Download Jar. Uses 8300K of libraries. Click here for Pure Java version (6164L/44K).
1 | !7 |
2 | |
3 | lib 1400185 |
4 | |
5 | import net.dv8tion.jda.core.*; |
6 | import net.dv8tion.jda.core.entities.*; |
7 | import net.dv8tion.jda.core.hooks.*; |
8 | import net.dv8tion.jda.core.events.message.*; |
9 | |
10 | p-exp { |
11 | logModuleOutput(); |
12 | JDABuilder builder = new(AccountType.BOT); |
13 | File tokenFile = javaxSecretDir("discord-bot-token"); |
14 | builder.setToken(assertNempty("Need: " + tokenFile, trim(loadTextFile(tokenFile)))); |
15 | builder.addEventListener(new ListenerAdapter { |
16 | @Override |
17 | public void onMessageReceived(MessageReceivedEvent e) { |
18 | print("Channel type: " + e.getChannelType()); |
19 | bool isPrivate = e.getChannelType() == ChannelType.PRIVATE; |
20 | print("Msg from " + e.getAuthor().getName() + ": " + e.getMessage().getContentDisplay()); |
21 | if (e.getAuthor().isBot()) ret with print(" Msg from bot, skipping"); |
22 | S content = e.getMessage().getContentRaw(); |
23 | if (nempty(content)) { |
24 | print("Next-to-last char: " + intToHex(nextToLastChar(content)); |
25 | print("Last char: " + intToHex(lastChar(content)); |
26 | } |
27 | new Matches m; |
28 | S s = ""; |
29 | if (isPrivate) s = content; |
30 | else if (swic(content, "gazelle", m)) s = m.rest(); |
31 | if (empty(s)) ret; |
32 | /*if (!regexpContains("^:[a-z]", s)) |
33 | s = dropLeadingPunctuation(s);*/ |
34 | s = "Bah! " + trim(s); |
35 | print("Sending: " + s); |
36 | e.getChannel().sendMessage(s).queue(); |
37 | } |
38 | }); |
39 | builder.buildAsync(); |
40 | } |
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, whxojlpjdney
No comments. add comment
Snippet ID: | #1021602 |
Snippet name: | Discord Bot Spike [OK] |
Eternal ID of this version: | #1021602/19 |
Text MD5: | 79f3b5f628c141cc304ab58ba3eb327f |
Transpilation MD5: | 467abab0511bc22890bf55f80c586015 |
Author: | stefan |
Category: | javax / discord |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-02-21 23:19:09 |
Source code size: | 1440 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 509 / 1260 |
Version history: | 18 change(s) |
Referenced in: | [show references] |