Uses 11163K of libraries. Click here for Pure Java version (22339L/122K).
1 | !7 |
2 | |
3 | concept Game{ |
4 | S shortName, name; |
5 | } |
6 | concept Wanted{ |
7 | long Id, timeout, guildid; |
8 | S name, game; |
9 | } |
10 | !include once #1026298 // use JDA 4.0 |
11 | |
12 | standardBot1 TomiiBoiDiscordBot { |
13 | allServers { |
14 | |
15 | start{ |
16 | db(); |
17 | gamesCRUD = new CRUD(Game); |
18 | wantedCRUD = new CRUD(Wanted); |
19 | } |
20 | transient CRUD<Game> gamesCRUD; |
21 | transient CRUD<Wanted> wantedCRUD; |
22 | visual jtabs( |
23 | "Main", super, |
24 | "Games", gamesCRUD.visualize(), |
25 | "Wanted", wantedCRUD.visualize()); |
26 | switchable S backendName = "tomiiBoiQA"; |
27 | //switchable bool newVersion = true; |
28 | |
29 | void grabChannels { |
30 | print("Grabbing channels"); |
31 | for (Guild guild : discord.getGuilds()) { |
32 | virtual Server server = guildToServer(guild); |
33 | for (GuildChannel c : guild.getChannels()) |
34 | dm_call(backendName, "addChannel", server, str(c.getIdLong()), c.getName()); |
35 | } |
36 | } |
37 | |
38 | virtual Server guildToServer(Guild guild) { |
39 | ret guild == null ? null |
40 | : dm_callOpt(backendName, "addServer", str(guild.getIdLong()), guild.getName()); |
41 | } |
42 | } |
43 | |
44 | init { |
45 | |
46 | if (myName == null) setField(myName := "Tomii"); |
47 | preprocessAtSelfToMyName = true; |
48 | dropPunctuation = false; |
49 | escapeAtEveryone = true; |
50 | reactToBots = false; |
51 | dm_registerAs("tomiiBoiDiscordBot"); |
52 | } |
53 | |
54 | sync S processSimplifiedLine(S s, O... _) { |
55 | try answer super.processSimplifiedLine(s, _); |
56 | |
57 | new Matches m; |
58 | if (swic_trim(s, "gbot:", m)) |
59 | ret gbot(m.rest(), paramsToMap(_)); |
60 | |
61 | O dbBot = dm_mainClass(backendName); |
62 | |
63 | temp tempSetTL((ThreadLocal) getOpt(dbBot, 'opt_noDefault), true); |
64 | |
65 | optPar Message msg; |
66 | |
67 | // channel logic |
68 | |
69 | MessageChannel channel = msg.getChannel(); |
70 | if (channel != null) { |
71 | virtual Channel backendChannel = dm_call(backendName, "channelForID", str(channel.getIdLong())); |
72 | if (isFalse(getOpt botEnabled(backendChannel))) null; |
73 | } |
74 | |
75 | // guild logic |
76 | |
77 | |
78 | Guild guild = msg == null ? null : msg.getGuild(); |
79 | long guildid = guild.getIdLong(); |
80 | // add guild to server list |
81 | virtual Server server = guildToServer(guild); |
82 | |
83 | //if (newVersion) |
84 | |
85 | if (eqic(s, "!help")) |
86 | |
87 | ret trimAllLines([[Type !play followed by a game of your choice to signal that you want to play this game. |
88 | |
89 | The bot will remember you wanting to play this game for 30 minutes. |
90 | |
91 | During these 30 minutes if anyone types !who followed by your game the bot will show who wanted to play this game in the last 30 minutes respectively]]); |
92 | |
93 | if (swic(s, "!play ", m)) { |
94 | |
95 | S game = m.rest(); |
96 | Game gameObject = conceptWhereIC Game(shortName :=game); |
97 | if (gameObject !=null) game =gameObject.name; |
98 | else { |
99 | ret "I dont know this game"; |
100 | } |
101 | |
102 | long Id = msg.getMember().getIdLong(); |
103 | S name = msg.getMember().getUser().getName(); |
104 | |
105 | cset(uniqIC Wanted(+Id,+name,+game,+guildid),timeout :=now()+1000*1800); |
106 | deleteConcepts(filter(list(Wanted),w -> w.timeout <= now())); |
107 | ret "@here " + discordAt(Id) + " wants to play " + game; |
108 | } |
109 | |
110 | |
111 | |
112 | if (swic(s, "!who ",m)){ |
113 | S game = m.rest(); |
114 | Game gameObject = conceptWhereIC Game(shortName :=game); |
115 | if (gameObject !=null) game =gameObject.name; |
116 | else { |
117 | ret "I dont know this game"; |
118 | } |
119 | deleteConcepts(filter(list(Wanted),w -> w.timeout <= now())); |
120 | L<Wanted> list = conceptsWhereIC Wanted(+game,+guildid); |
121 | if (l(list) > 1) |
122 | ret joinWithComma(map(list, w -> discordAt(w.Id))) + " want to play " + game; |
123 | else if (l(list) == 1) |
124 | ret joinWithComma(map(list, w -> discordAt(w.Id))) + " wants to play " + game; |
125 | else |
126 | ret "Nobody wants to play this game right now"; |
127 | |
128 | } |
129 | |
130 | ret (S) call(dbBot, "answer", s, +server); |
131 | |
132 | /*Cl<S> categories = dm_callOpt(backendName, "categoriesForServer", server); |
133 | |
134 | temp tempSetTL((ThreadLocal) getOpt(dbBot, "categoriesForRequest"), categories); |
135 | ret (S) call(dbBot, 'answer, s, "en");*/ |
136 | } |
137 | |
138 | S gbot(S query, Map map, O... _) { |
139 | LS l = regexpICFullMatch_groups("(\\d+) results? for[ :](.+)", query); |
140 | int results = 1; |
141 | if (l != null) { |
142 | results = parseInt(first(l)); |
143 | query = unquote(trim(last(l))); |
144 | } |
145 | bool safeSearch = !discord_isNSFWChannel_gen(map.get('channel)); |
146 | ret discord_google(query, paramsPlus(_, +results, +safeSearch)); |
147 | } |
148 | } |
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, qsqiayxyrbia, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1029471 |
Snippet name: | Tomii Boi Discord Bot Extension [in-OS db version, use with #1028036] |
Eternal ID of this version: | #1029471/41 |
Text MD5: | ac1ca46266a16a6e04ccb6b44e023347 |
Transpilation MD5: | d419c0358e6fb65d5deef6839dc9896e |
Author: | jarvis |
Category: | |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-08-11 17:47:18 |
Source code size: | 4474 bytes / 148 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 250 / 64552 |
Version history: | 40 change(s) |
Referenced in: | [show references] |