Uses 5909K of libraries. Click here for Pure Java version (20633L/113K).
1 | !7 |
2 | |
3 | concept Msg { |
4 | long msgID, channelID, userID; |
5 | long date, edited; // epochSeconds |
6 | S text; |
7 | } |
8 | |
9 | standardBot1 EAMBot { |
10 | init { |
11 | dbIndexing(Msg, 'msgID); |
12 | |
13 | dm_vmBus_onMessage_q discord_onMessageReceived(voidfunc(O module, O event) { |
14 | if (!enabled || !indexAllIncoming || !dm_isMe(module)) ret; |
15 | Message message = cast rcall getMessage(event); |
16 | storeMsg(message); |
17 | }); |
18 | } |
19 | |
20 | allServers { |
21 | bool indexAllIncoming = true; |
22 | |
23 | !include #1025906 // DiscordScanner |
24 | |
25 | enhanceFrame { |
26 | internalFrameMenuItem(f, "Show word list", rThread { |
27 | S list = makeWordsList(); |
28 | showText_fast_noWrap("Word list (" + countLines(list) + ")", list); |
29 | }); |
30 | } |
31 | |
32 | S makeWordsList() { |
33 | new Map<S, Long> map; // word -> date |
34 | new MultiSet<S> ms; // word count |
35 | for ping (Msg msg : sortedByField date(list(Msg))) { |
36 | Long date = msg.date; |
37 | for ping (S word : words2_notNextToNumbers_plusApostrophe(msg.text)) { |
38 | map.put(word, date); |
39 | ms.add(word); |
40 | } |
41 | } |
42 | ret mapToLines(keysSortedByValuesDesc(map), w -> { |
43 | int count = ms.get(w); |
44 | ret count == 1 ? w : count + " " + w; |
45 | }); |
46 | } |
47 | } |
48 | |
49 | sync S processSimplifiedLine(S s, O... _) { |
50 | try answer super.processSimplifiedLine(s, _); |
51 | |
52 | if ((s = dropMyPrefixOrNull(s)) == null) null; |
53 | |
54 | optPar MessageChannel channel; |
55 | |
56 | if "upload word list" { |
57 | S list = makeWordsList(); |
58 | editMechList("NGB Word List", list); |
59 | ret "OK. " + nWords(countLines(list)); |
60 | } |
61 | |
62 | if "retrieve history" { |
63 | setAll(new DiscordScanner, +channel, incremental := true).run(); |
64 | ret "Retrieving..."; |
65 | } |
66 | |
67 | if "retrieve full channel" { |
68 | setAll(new DiscordScanner, +channel, incremental := false).run(); |
69 | ret "Retrieving..."; |
70 | } |
71 | |
72 | if "retrieve all channels" { |
73 | L<TextChannel> l = getGuild().getTextChannels(); |
74 | |
75 | new AtomicInt counter; |
76 | Runnable whenDone = r { |
77 | if (incAtomicInt(counter) == l(l)) |
78 | postInChannel(channel, "Incremental scan of " + nChannels(l) + " done"); |
79 | }; |
80 | |
81 | for ping (TextChannel c : l) |
82 | setAll(new DiscordScanner, channel := c, incremental := true, |
83 | postResult := false, +whenDone).run(); |
84 | } |
85 | |
86 | if "mega retrieve" { |
87 | try answer checkAuth(_); |
88 | L<TextChannel> l = getGuild().getTextChannels(); |
89 | |
90 | new AtomicInt counter; |
91 | Runnable whenDone = r { |
92 | if (incAtomicInt(counter) == l(l)) |
93 | postInChannel(channel, "Full scan of " + nChannels(l) + " done"); |
94 | }; |
95 | |
96 | for ping (TextChannel c : l) |
97 | setAll(new DiscordScanner, channel := c, incremental := false, |
98 | postResult := false, +whenDone).run(); |
99 | } |
100 | |
101 | if "db size" ret nMessages(countConcepts(Msg)); |
102 | |
103 | if "random message" { |
104 | Msg msg = random(list(Msg)); |
105 | ret msg == null ? "No messages" : "[" + msg.msgID + "] " + msg.text; |
106 | } |
107 | |
108 | null; |
109 | } |
110 | } |
Began life as a copy of #1025795
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: | #1025807 |
Snippet name: | Channel History DB Bot [OK] |
Eternal ID of this version: | #1025807/58 |
Text MD5: | 0cafab3a7bbe35b728263cd736828921 |
Transpilation MD5: | cb45085c75d24aaed69cfc8f6e4cd2c3 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-10-29 21:44:34 |
Source code size: | 3119 bytes / 110 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 314 / 5999 |
Version history: | 57 change(s) |
Referenced in: | [show references] |