| 1 | ifndef DifferentJDA | 
| 2 | lib 1400215 // discord without opus/JNA | 
| 3 | |
| 4 | //static LS _stickyLibs_discordBot = ll(#1400215); // can cause loader constraint violations | 
| 5 | endifndef | 
| 6 | |
| 7 | import net.dv8tion.jda.core.*; | 
| 8 | import net.dv8tion.jda.core.entities.*; | 
| 9 | import net.dv8tion.jda.core.entities.Member; | 
| 10 | import net.dv8tion.jda.core.hooks.*; | 
| 11 | import net.dv8tion.jda.core.events.*; | 
| 12 | import net.dv8tion.jda.core.events.message.*; | 
| 13 | import net.dv8tion.jda.core.events.message.react.*; | 
| 14 | |
| 15 | static JDA discordBot(final VF1<MessageReceivedEvent> onMessage) {
 | 
| 16 |   ret discordBot(new ListenerAdapter {
 | 
| 17 | @Override | 
| 18 |     public void onMessageReceived(MessageReceivedEvent e) {
 | 
| 19 |       if (e.getAuthor().isBot()) ret with print("  Msg from bot, skipping");
 | 
| 20 | pcallF(onMessage, e); | 
| 21 | } | 
| 22 | }); | 
| 23 | } | 
| 24 | |
| 25 | static JDA discordBot(ListenerAdapter listener, O... _) ctex {
 | 
| 26 |   print("Making JDABuilder");
 | 
| 27 | JDABuilder builder = new(AccountType.BOT); | 
| 28 |   print("Have JDABuilder");
 | 
| 29 | S token = stringPar token(_); | 
| 30 |   if (empty(token)) {
 | 
| 31 |     File tokenFile = javaxSecretDir("discord-bot-token");
 | 
| 32 |     token = assertNempty("Need: " + tokenFile, trim(loadTextFile(tokenFile)));
 | 
| 33 | } | 
| 34 | builder.setToken(token); | 
| 35 | builder.addEventListener(listener); | 
| 36 |   print("Building JDA with token " + shorten(10, token));
 | 
| 37 | JDA jda = builder.build(); | 
| 38 |   print("Got JDA: " + jda);
 | 
| 39 |   jda.addEventListener(new ListenerAdapter {
 | 
| 40 |     public void onStatusChange(StatusChangeEvent event) {
 | 
| 41 |       print("JDA status: " + event.getNewStatus());
 | 
| 42 | } | 
| 43 | }); | 
| 44 | //jda.awaitSatus(JDA.Status.CONNECTED); | 
| 45 | jda.awaitReady(); | 
| 46 |   print("Started Discord bot (token: " + shorten(token, 7) + ")");
 | 
| 47 | ret jda; | 
| 48 | } | 
Began life as a copy of #1021617
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1030355 | 
| Snippet name: | discordBot [backup] | 
| Eternal ID of this version: | #1030355/1 | 
| Text MD5: | bafda1897fe00eceebfdec58256a80f1 | 
| Author: | stefan | 
| Category: | javax / discord | 
| Type: | JavaX fragment (include) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2020-12-07 00:42:09 | 
| Source code size: | 1651 bytes / 48 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 361 / 396 | 
| Referenced in: | [show references] |