-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e16b4c
commit a32891a
Showing
6 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
terra/src/main/java/dev/jacksonbailey/wheel/terra/PingPong.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package dev.jacksonbailey.wheel.terra; | ||
|
||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.entities.Message; | ||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; | ||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class PingPong extends ListenerAdapter { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(PingPong.class); | ||
|
||
private final JDA jda; | ||
|
||
public PingPong(JDA jda) { | ||
this.jda = jda; | ||
// TODO This is wrong wrong wrong! | ||
jda.addEventListener(this); | ||
} | ||
|
||
@Override | ||
public void onMessageReceived(MessageReceivedEvent event) { | ||
if (event.getAuthor().isBot()) { | ||
return; | ||
} | ||
// We don't want to respond to other bot accounts, including ourself | ||
Message message = event.getMessage(); | ||
String content = message.getContentRaw(); | ||
// getContentRaw() is an atomic getter | ||
// getContentDisplay() is a lazy getter which modifies the content for e.g. console view (strip | ||
// discord formatting) | ||
if (content.equals("!ping")) { | ||
MessageChannel channel = event.getChannel(); | ||
channel.sendMessage("Pong!") | ||
.queue(); // Important to call .queue() on the RestAction returned by sendMessage(...) | ||
} | ||
} | ||
|
||
} |
10 changes: 8 additions & 2 deletions
10
terra/src/main/java/dev/jacksonbailey/wheel/terra/TerraConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
package dev.jacksonbailey.wheel.terra; | ||
|
||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.JDABuilder; | ||
import net.dv8tion.jda.api.requests.GatewayIntent; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
@Configuration | ||
public class TerraConfig { | ||
|
||
@Bean | ||
public JDABuilder jdaBuilder(TerraConfigProps terraConfigProps) { | ||
return JDABuilder.createDefault(terraConfigProps.token()); | ||
@Profile("live") | ||
public JDA jda(TerraConfigProps terraConfigProps) { | ||
return JDABuilder.createDefault(terraConfigProps.token()) | ||
.enableIntents(GatewayIntent.MESSAGE_CONTENT) | ||
.build(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
terra/src/test/java/dev/jacksonbailey/wheel/terra/TerraTestConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.jacksonbailey.wheel.terra; | ||
|
||
import static org.mockito.Mockito.mock; | ||
|
||
import net.dv8tion.jda.api.JDA; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
@Configuration | ||
public class TerraTestConfig { | ||
|
||
@Bean | ||
@Profile("!live") | ||
public JDA jda() { | ||
return mock(JDA.class); | ||
} | ||
|
||
} |