Uses 4998K of libraries. Click here for Pure Java version (12711L/91K).
1 | abstract sclass DynTalkBot > DynDiscordHopper { |
2 | switchable S myName = "Anonymous bot"; |
3 | transient bool useAGIBlueForDropPunctuation = true; |
4 | transient bool preprocessAtSelfToMyName = true; |
5 | transient bool dropPunctuation = true; |
6 | L<Long> authorizedUsers = ll(547706854680297473); // stefan |
7 | |
8 | start { |
9 | dm_vmBus_onMessage_q('discordGuildJoin, voidfunc(Map map) { |
10 | ret unless map.get('module) == module(); |
11 | print("Got join"); |
12 | onUserJoin(getLong userID(map), map); |
13 | }); |
14 | } |
15 | |
16 | // overridable |
17 | void onUserJoin(long userID, O... _) {} |
18 | |
19 | @Override S answer(S input, Map map) { |
20 | try answer super.answer(input, map); // discord hopping |
21 | |
22 | ret mapEachLine_tlft_nempties(input, s -> { |
23 | ret processLine(s, map); |
24 | }); |
25 | } |
26 | |
27 | S processLine(S s, O... _) { |
28 | s = preprocess(s, _); |
29 | ret processSimplifiedLine(s, _); |
30 | } |
31 | |
32 | S preprocess(S s, O... _) { |
33 | if (preprocessAtSelfToMyName && discordBotID != 0) |
34 | s = replace(s, atSelf(), " " + myName + " "); |
35 | if (dropPunctuation) |
36 | s = dropPunctuation3_withAGIBlue(useAGIBlueForDropPunctuation, s); |
37 | s = trim(simpleSpaces_noTok(s)); |
38 | print("simplified >> " + quote(s)); |
39 | ret s; |
40 | } |
41 | |
42 | S myPrefix() { |
43 | ret preprocessAtSelfToMyName ? myName + " " : |
44 | (dropPunctuation ? replace(atSelf(), "@", "") /* @ is killed by preprocessing */ : atSelf()) + " "; |
45 | } |
46 | |
47 | // extend me |
48 | S processSimplifiedLine(S input, O... _) { |
49 | new Matches m; |
50 | |
51 | input = dropPrefixOrNull(myPrefix(), input); |
52 | if (input == null) null; |
53 | |
54 | if (eqicOneOf(input, "support channel", "support server", "support")) |
55 | ret "Get support for me here: " + nextGenBotsDiscordInvite(); |
56 | |
57 | if (eqicOneOf(input, "source", "sources", "source code")) |
58 | ret snippetLink(programID()); |
59 | |
60 | if (swic_trim(input, "add master ", m)) { |
61 | try answer checkAuth(_); |
62 | |
63 | add(authorizedUsers, parseFirstLong(m.rest())); |
64 | change(); |
65 | |
66 | ret "Okidoki. Have " + n2(l(authorizedUsers), "master"); |
67 | } |
68 | |
69 | if (eqic(input, "masters")) |
70 | ret empty(authorizedUsers) ? "I have no masters." : "My masters are: " + joinWithComma(map discordAtPlusID(authorizedUsers)); |
71 | |
72 | if (swic_trim(input, "delete master ", m)) { |
73 | try answer checkAuth(_); |
74 | |
75 | remove(authorizedUsers, parseFirstLong(m.rest())); |
76 | change(); |
77 | |
78 | ret "Okidoki. Have " + n2(l(authorizedUsers), "master"); |
79 | } |
80 | null; |
81 | } |
82 | |
83 | bool authed(O... _) { |
84 | ret contains(authorizedUsers, optPar userID(_)); |
85 | } |
86 | |
87 | S checkAuth(O... _) { |
88 | long userID = longPar userID(_); |
89 | bool result = authed(_); |
90 | print("Auth-checking user ID: " + userID + " => " + result); |
91 | if (!result) ret "You are not authorized"; |
92 | null; |
93 | } |
94 | } |
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: | #1024519 |
Snippet name: | DynTalkBot - DynDiscordHopper + input simplification, onUserJoin, name, authorizedUsers |
Eternal ID of this version: | #1024519/36 |
Text MD5: | 1ec2536c44313dd2576cd6ee835261fd |
Transpilation MD5: | 7bb458347e7b4b574bc510b40067edb5 |
Author: | stefan |
Category: | javax / agi.blue |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-09-08 15:11:48 |
Source code size: | 2831 bytes / 94 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 359 / 869 |
Version history: | 35 change(s) |
Referenced in: | [show references] |