20
20
import org .slf4j .Logger ;
21
21
22
22
public class MeteorBot extends ListenerAdapter {
23
- private static final String [] HELLOS = { "hi" , "hello" , "howdy" , "bonjour" , "ciao" , "hej" , "hola" , "yo" };
23
+ private static final String [] HELLOS = {"hi" , "hello" , "howdy" , "bonjour" , "ciao" , "hej" , "hola" , "yo" };
24
24
25
25
public static final Logger LOG = JDALogger .getLog ("Meteor Bot" );
26
- public static final String BACKEND_TOKEN = System .getenv ("BACKEND_TOKEN" );
27
26
28
- public static JDA BOT ;
29
- public static Guild SERVER ;
30
- public static RichCustomEmoji COPE_NN ;
27
+ private Guild server ;
28
+ private RichCustomEmoji copeEmoji ;
31
29
32
30
public static void main (String [] args ) {
33
- String token = System .getenv ("DISCORD_TOKEN" );
34
-
31
+ String token = Env .DISCORD_TOKEN .value ;
35
32
if (token == null ) {
36
33
MeteorBot .LOG .error ("Must specify discord bot token." );
37
34
return ;
@@ -46,51 +43,47 @@ public static void main(String[] args) {
46
43
47
44
@ Override
48
45
public void onReady (ReadyEvent event ) {
49
- BOT = event .getJDA ();
50
- BOT .getPresence ().setActivity (Activity .playing ("Meteor Client" ));
46
+ JDA bot = event .getJDA ();
47
+ bot .getPresence ().setActivity (Activity .playing ("Meteor Client" ));
51
48
52
- SERVER = BOT .getGuildById (System . getenv ( " GUILD_ID" ) );
53
- if (SERVER == null ) {
49
+ server = bot .getGuildById (Env . GUILD_ID . value );
50
+ if (server == null ) {
54
51
MeteorBot .LOG .error ("Couldn't find the specified server." );
55
- System .exit (0 );
52
+ System .exit (1 );
56
53
}
57
54
58
- COPE_NN = SERVER .getEmojiById (System . getenv ( " COPE_NN_ID" ) );
55
+ copeEmoji = server .getEmojiById (Env . COPE_NN_ID . value );
59
56
60
57
LOG .info ("Meteor Bot started" );
61
58
}
62
59
63
60
@ Override
64
61
public void onMessageReceived (MessageReceivedEvent event ) {
65
- if (!event .isFromType (ChannelType .TEXT ) || !event .isFromGuild () || !event .getGuild ().equals (SERVER )) return ;
62
+ if (!event .isFromType (ChannelType .TEXT ) || !event .isFromGuild () || !event .getGuild ().equals (server )) return ;
66
63
67
64
String content = event .getMessage ().getContentRaw ();
68
- if (!content .contains (BOT .getSelfUser ().getAsMention ())) return ;
69
-
70
- boolean found = false ;
65
+ if (!content .contains (event .getJDA ().getSelfUser ().getAsMention ())) return ;
71
66
72
67
for (String hello : HELLOS ) {
73
68
if (content .toLowerCase ().contains (hello )) {
74
- found = true ;
75
69
event .getMessage ().reply (hello + " :)" ).queue ();
70
+ return ;
76
71
}
77
72
}
78
73
79
- if (!found ) {
80
- event .getMessage ().addReaction (content .toLowerCase ().contains ("cope" ) ? COPE_NN : Emoji .fromUnicode ("\uD83D \uDC4B " )).queue ();
81
- }
74
+ event .getMessage ().addReaction (content .toLowerCase ().contains ("cope" ) ? copeEmoji : Emoji .fromUnicode ("\uD83D \uDC4B " )).queue ();
82
75
}
83
76
84
77
@ Override
85
78
public void onGuildMemberJoin (@ NotNull GuildMemberJoinEvent event ) {
86
- if (BACKEND_TOKEN == null ) return ;
79
+ if (Env . BACKEND_TOKEN . value == null ) return ;
87
80
88
81
Utils .apiPost ("discord/userJoined" ).queryString ("id" , event .getMember ().getId ()).asEmpty ();
89
82
}
90
83
91
84
@ Override
92
85
public void onGuildMemberRemove (@ NotNull GuildMemberRemoveEvent event ) {
93
- if (BACKEND_TOKEN == null ) return ;
86
+ if (Env . BACKEND_TOKEN . value == null ) return ;
94
87
95
88
Utils .apiPost ("discord/userLeft" ).asEmpty ();
96
89
}
0 commit comments