Download Jar. Uses 8300K of libraries. Click here for Pure Java version (6164L/44K).
!7 lib 1400185 import net.dv8tion.jda.core.*; import net.dv8tion.jda.core.entities.*; import net.dv8tion.jda.core.hooks.*; import net.dv8tion.jda.core.events.message.*; p-exp { logModuleOutput(); JDABuilder builder = new(AccountType.BOT); File tokenFile = javaxSecretDir("discord-bot-token"); builder.setToken(assertNempty("Need: " + tokenFile, trim(loadTextFile(tokenFile)))); builder.addEventListener(new ListenerAdapter { @Override public void onMessageReceived(MessageReceivedEvent e) { print("Channel type: " + e.getChannelType()); bool isPrivate = e.getChannelType() == ChannelType.PRIVATE; print("Msg from " + e.getAuthor().getName() + ": " + e.getMessage().getContentDisplay()); if (e.getAuthor().isBot()) ret with print(" Msg from bot, skipping"); S content = e.getMessage().getContentRaw(); if (nempty(content)) { print("Next-to-last char: " + intToHex(nextToLastChar(content)); print("Last char: " + intToHex(lastChar(content)); } new Matches m; S s = ""; if (isPrivate) s = content; else if (swic(content, "gazelle", m)) s = m.rest(); if (empty(s)) ret; /*if (!regexpContains("^:[a-z]", s)) s = dropLeadingPunctuation(s);*/ s = "Bah! " + trim(s); print("Sending: " + s); e.getChannel().sendMessage(s).queue(); } }); builder.buildAsync(); }
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: | 508 / 1259 |
Version history: | 18 change(s) |
Referenced in: | [show references] |