Uses 5909K of libraries. Click here for Pure Java version (10323L/56K).
1 | !7 |
2 | |
3 | cmodule GreeterBot > DynTalkBot { |
4 | S msg = "Welcome <user>! Rules and regulations apply. And stuff."; |
5 | S goodbyeMsg = "<user> just left us"; |
6 | long channelToGreetIn; |
7 | |
8 | start { |
9 | useAGIBlueForDropPunctuation = false; |
10 | preprocessAtSelfToMyName = false; |
11 | dropPunctuation = false; |
12 | |
13 | dm_vmBus_onMessage_q discordGuildLeave(voidfunc(Map map) { |
14 | ret unless map.get('module) == module(); |
15 | O user = rcall getUser(map.get('event)); |
16 | S name = cast rcall getName(user); |
17 | postInChannel(channelToGreetIn, replace(goodbyeMsg, "<user>", or2(name, "an unknown user")); |
18 | }); |
19 | } |
20 | |
21 | void onUserJoin(long userID, O... _) { |
22 | S msg = replace(this.msg, "<user>", discordAt(userID)); |
23 | if (channelToGreetIn == 0) setField(channelToGreetIn := preferredChannelID); |
24 | if (channelToGreetIn == 0) fail("Have no greeting channel"); |
25 | postInChannel(channelToGreetIn, msg); |
26 | } |
27 | |
28 | S processSimplifiedLine(S s, O... _) { |
29 | try answer super.processSimplifiedLine(s, _); // adding authorized users etc. |
30 | |
31 | new Matches m; |
32 | |
33 | S sOld = s; |
34 | s = dropPrefixOrNull(myPrefix(), s); |
35 | if (s == null) { |
36 | print("no got prefix: " + quote(myPrefix()) + " / " + quote(sOld)); |
37 | null; |
38 | } |
39 | |
40 | if (eqic(s, "prefer this channel")) { |
41 | try answer checkAuth(_); |
42 | long channelID = longPar channelID(_); |
43 | if (channelID == 0) ret "No channel"; |
44 | setField(channelToGreetIn := channelID); |
45 | ret "OK, will greet here from now on."; |
46 | } |
47 | |
48 | if (eqic(s, "simulate greeting")) { |
49 | onUserJoin(longPar userID(_), _); |
50 | ret "Greeting simulated"; |
51 | } |
52 | |
53 | if (eqic(s, "get message")) ret msg; |
54 | if (eqic(s, "get goodbye message")) ret goodbyeMsg; |
55 | |
56 | if (swic_trim(s, "set message:", m)) { |
57 | try answer checkAuth(_); |
58 | setField(msg := m.rest(); |
59 | ret "Message changed to: " + msg; |
60 | } |
61 | |
62 | if (swic_trim(s, "set goodbye message:", m)) { |
63 | try answer checkAuth(_); |
64 | setField(goodbyeMsg := m.rest(); |
65 | ret "Goodbye message changed to: " + msg; |
66 | } |
67 | |
68 | if (eqic(s, "enable")) { |
69 | try answer checkAuth(_); |
70 | setField(enabled := true); |
71 | ret "Enabled. Will greet every new arrival!"; |
72 | } |
73 | |
74 | if (eqic(s, "disable")) { |
75 | try answer checkAuth(_); |
76 | setField(enabled := true); |
77 | ret "Disabled. Will not greet anyone."; |
78 | } |
79 | |
80 | if (eqic(s, "dump")) |
81 | ret struct(objectToMap_nonTransient_singleClass GreeterBot(GreeterBot.this)); |
82 | |
83 | if (eqic(s, "help")) |
84 | ret trim([[ |
85 | I am a simple greeter (and farewell) bot. Status: ]] + enabledDisabled(enabled) + [[. Commands: |
86 | |
87 | @me **simulate greeting** -- I greet you so you can test me |
88 | @me **get message** -- show current greeting message |
89 | @me **set message: Hello <user>! Bla bla...** -- change greeting. <user> is replaced with user name |
90 | @me **simulate goodbye** -- I pretend you walked away (although I know you didn't) |
91 | @me **get goodbye message** -- show current goodbye message (what I post when people leave) |
92 | @me **set goodbye message: <user> just left us |
93 | @me **prefer this channel** -- posts greetings in the channel you write this in |
94 | @me **enable/disable** -- enable/disable the auto-greeting |
95 | @me **masters**/**add master**/**delete master** -- change bot ownership |
96 | @me **source**/**support channel** -- see sources or join the support discord |
97 | |
98 | [Bot made by https://BotCompany.de] |
99 | ]]).replace("@me", atSelf()); |
100 | |
101 | null; |
102 | } |
103 | } |
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1025122 |
Snippet name: | Samantha [Discord Greeter Bot, old] |
Eternal ID of this version: | #1025122/31 |
Text MD5: | 1afebf92c6d018dff10f3eeccce4118f |
Transpilation MD5: | 67257a8873f9bb17a8e4d71d9676173b |
Author: | stefan |
Category: | javax / bots |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-09-10 00:01:56 |
Source code size: | 3534 bytes / 103 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 346 / 878 |
Version history: | 30 change(s) |
Referenced in: | [show references] |