Uses 10819K of libraries. Click here for Pure Java version (19007L/101K).
1 | !7 |
2 | |
3 | !include once #1026298 // use JDA 4.0 |
4 | |
5 | standardBot1 TomiiBoiDiscordBot { |
6 | allServers { |
7 | switchable S backendName = "tomiiBoiQA"; |
8 | //switchable bool newVersion = true; |
9 | |
10 | void grabChannels { |
11 | print("Grabbing channels"); |
12 | for (Guild guild : discord.getGuilds()) { |
13 | virtual Server server = guildToServer(guild); |
14 | for (GuildChannel c : guild.getChannels()) |
15 | dm_call(backendName, "addChannel", server, str(c.getIdLong()), c.getName()); |
16 | } |
17 | } |
18 | |
19 | virtual Server guildToServer(Guild guild) { |
20 | ret guild == null ? null |
21 | : dm_callOpt(backendName, "addServer", str(guild.getIdLong()), guild.getName()); |
22 | } |
23 | } |
24 | |
25 | init { |
26 | if (myName == null) setField(myName := "Tomii"); |
27 | preprocessAtSelfToMyName = true; |
28 | dropPunctuation = false; |
29 | escapeAtEveryone = true; |
30 | reactToBots = false; |
31 | dm_registerAs("tomiiBoiDiscordBot"); |
32 | } |
33 | |
34 | sync S processSimplifiedLine(S s, O... _) { |
35 | try answer super.processSimplifiedLine(s, _); |
36 | |
37 | new Matches m; |
38 | if (swic_trim(s, "gbot:", m)) |
39 | ret gbot(m.rest(), paramsToMap(_)); |
40 | |
41 | O dbBot = dm_mainClass(backendName); |
42 | |
43 | temp tempSetTL((ThreadLocal) getOpt(dbBot, 'opt_noDefault), true); |
44 | |
45 | optPar Message msg; |
46 | |
47 | // channel logic |
48 | |
49 | MessageChannel channel = msg.getChannel(); |
50 | if (channel != null) { |
51 | virtual Channel backendChannel = dm_call(backendName, "channelForID", str(channel.getIdLong())); |
52 | if (isFalse(getOpt botEnabled(backendChannel))) null; |
53 | } |
54 | |
55 | // guild logic |
56 | |
57 | Guild guild = msg == null ? null : msg.getGuild(); |
58 | |
59 | // add guild to server list |
60 | virtual Server server = guildToServer(guild); |
61 | |
62 | //if (newVersion) |
63 | ret (S) call(dbBot, "answer", s, +server); |
64 | |
65 | /*Cl<S> categories = dm_callOpt(backendName, "categoriesForServer", server); |
66 | |
67 | temp tempSetTL((ThreadLocal) getOpt(dbBot, "categoriesForRequest"), categories); |
68 | ret (S) call(dbBot, 'answer, s, "en");*/ |
69 | } |
70 | |
71 | S gbot(S query, Map map, O... _) { |
72 | LS l = regexpICFullMatch_groups("(\\d+) results? for[ :](.+)", query); |
73 | int results = 1; |
74 | if (l != null) { |
75 | results = parseInt(first(l)); |
76 | query = unquote(trim(last(l))); |
77 | } |
78 | bool safeSearch = !discord_isNSFWChannel_gen(map.get('channel)); |
79 | ret discord_google(query, paramsPlus(_, +results, +safeSearch)); |
80 | } |
81 | } |
Began life as a copy of #1026479
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: | #1026494 |
Snippet name: | Tomii Boi Discord Bot [in-OS db version, use with #1028036] |
Eternal ID of this version: | #1026494/22 |
Text MD5: | 72f2b8c027f967e236a75bc86bb5860e |
Transpilation MD5: | 425b6c624a51e7fe53e93d8c7b2344e8 |
Author: | stefan |
Category: | |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-08-11 13:54:16 |
Source code size: | 2440 bytes / 81 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 277 / 3253 |
Version history: | 21 change(s) |
Referenced in: | [show references] |