Skip to content

Commit 4b20fa9

Browse files
committed
Restrict to #java_javacord on Discord API server (#34)
1 parent 956a245 commit 4b20fa9

File tree

11 files changed

+90
-10
lines changed

11 files changed

+90
-10
lines changed

src/main/java/org/javacord/bot/Constants.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ public final class Constants {
1212
*/
1313
public static final Color JAVACORD_ORANGE = new Color(243, 189, 30);
1414

15+
/**
16+
* The ID of the "Discord API" server.
17+
*/
18+
public static final long DAPI_SERVER_ID = 81384788765712384L;
19+
20+
/**
21+
* The ID of the "#java_javacord" channel on the "Discord API" server.
22+
*/
23+
public static final long DAPI_JAVACORD_CHANNEL_ID = 381889796785831936L;
24+
1525
private Constants() { /* nope */ }
1626

1727
}

src/main/java/org/javacord/bot/commands/DocsCommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.javacord.api.entity.channel.TextChannel;
77
import org.javacord.api.entity.message.Message;
88
import org.javacord.api.entity.message.embed.EmbedBuilder;
9+
import org.javacord.api.entity.server.Server;
910
import org.javacord.api.util.logging.ExceptionLogger;
1011
import org.javacord.bot.Constants;
1112
import org.javacord.bot.listeners.CommandCleanupListener;
@@ -49,13 +50,19 @@ public class DocsCommand implements CommandExecutor {
4950
/**
5051
* Executes the {@code !docs} command.
5152
*
53+
* @param server The server where the command was issued.
5254
* @param channel The channel where the command was issued.
5355
* @param message The message the command was issued in.
5456
* @param args The arguments given to the command.
5557
* @throws IOException If the Javacord icon stream cannot be closed properly.
5658
*/
5759
@Command(aliases = {"!docs"}, async = true)
58-
public void onCommand(TextChannel channel, Message message, String[] args) throws IOException {
60+
public void onCommand(Server server, TextChannel channel, Message message, String[] args) throws IOException {
61+
// Only react in #java_javacord channel on Discord API server
62+
if ((server.getId() == Constants.DAPI_SERVER_ID) && (channel.getId() != Constants.DAPI_JAVACORD_CHANNEL_ID)) {
63+
return;
64+
}
65+
5966
try (InputStream javacord3Icon = getClass().getClassLoader().getResourceAsStream("javacord3_icon.png")) {
6067
EmbedBuilder embed = new EmbedBuilder()
6168
.setThumbnail(javacord3Icon, "png")

src/main/java/org/javacord/bot/commands/ExampleCommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.javacord.api.entity.channel.TextChannel;
66
import org.javacord.api.entity.message.Message;
77
import org.javacord.api.entity.message.embed.EmbedBuilder;
8+
import org.javacord.api.entity.server.Server;
89
import org.javacord.bot.Constants;
910
import org.javacord.bot.listeners.CommandCleanupListener;
1011

@@ -19,12 +20,18 @@ public class ExampleCommand implements CommandExecutor {
1920
/**
2021
* Executes the {@code !example} command.
2122
*
23+
* @param server The server where the command was issued.
2224
* @param channel The channel where the command was issued.
2325
* @param message The message the command was issued in.
2426
* @throws IOException If the Javacord icon stream cannot be closed properly.
2527
*/
2628
@Command(aliases = {"!example"}, async = true)
27-
public void onCommand(TextChannel channel, Message message) throws IOException {
29+
public void onCommand(Server server, TextChannel channel, Message message) throws IOException {
30+
// Only react in #java_javacord channel on Discord API server
31+
if ((server.getId() == Constants.DAPI_SERVER_ID) && (channel.getId() != Constants.DAPI_JAVACORD_CHANNEL_ID)) {
32+
return;
33+
}
34+
2835
try (InputStream javacord3Icon = getClass().getClassLoader().getResourceAsStream("javacord3_icon.png")) {
2936
EmbedBuilder embed = new EmbedBuilder()
3037
.setThumbnail(javacord3Icon, "png")

src/main/java/org/javacord/bot/commands/GitHubCommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.javacord.api.entity.channel.TextChannel;
66
import org.javacord.api.entity.message.Message;
77
import org.javacord.api.entity.message.embed.EmbedBuilder;
8+
import org.javacord.api.entity.server.Server;
89
import org.javacord.bot.Constants;
910
import org.javacord.bot.listeners.CommandCleanupListener;
1011

@@ -19,12 +20,18 @@ public class GitHubCommand implements CommandExecutor {
1920
/**
2021
* Executes the {@code !github} command.
2122
*
23+
* @param server The server where the command was issued.
2224
* @param channel The channel where the command was issued.
2325
* @param message The message the command was issued in.
2426
* @throws IOException If the Javacord icon stream cannot be closed properly.
2527
*/
2628
@Command(aliases = {"!github"}, async = true)
27-
public void onCommand(TextChannel channel, Message message) throws IOException {
29+
public void onCommand(Server server, TextChannel channel, Message message) throws IOException {
30+
// Only react in #java_javacord channel on Discord API server
31+
if ((server.getId() == Constants.DAPI_SERVER_ID) && (channel.getId() != Constants.DAPI_JAVACORD_CHANNEL_ID)) {
32+
return;
33+
}
34+
2835
try (InputStream javacord3Icon = getClass().getClassLoader().getResourceAsStream("javacord3_icon.png")) {
2936
EmbedBuilder embed = new EmbedBuilder()
3037
.addField("Javacord", "https://github.com/Javacord/Javacord")

src/main/java/org/javacord/bot/commands/GradleCommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.javacord.api.entity.channel.TextChannel;
77
import org.javacord.api.entity.message.Message;
88
import org.javacord.api.entity.message.embed.EmbedBuilder;
9+
import org.javacord.api.entity.server.Server;
910
import org.javacord.bot.Constants;
1011
import org.javacord.bot.listeners.CommandCleanupListener;
1112

@@ -17,11 +18,17 @@ public class GradleCommand implements CommandExecutor {
1718
/**
1819
* Executes the {@code !gradle} command.
1920
*
21+
* @param server The server where the command was issued.
2022
* @param channel The channel where the command was issued.
2123
* @param message The message the command was issued in.
2224
*/
2325
@Command(aliases = {"!gradle"}, async = true)
24-
public void onCommand(TextChannel channel, Message message) {
26+
public void onCommand(Server server, TextChannel channel, Message message) {
27+
// Only react in #java_javacord channel on Discord API server
28+
if ((server.getId() == Constants.DAPI_SERVER_ID) && (channel.getId() != Constants.DAPI_JAVACORD_CHANNEL_ID)) {
29+
return;
30+
}
31+
2532
EmbedBuilder embed = new EmbedBuilder()
2633
.setColor(Constants.JAVACORD_ORANGE)
2734
.addField("Dependency",

src/main/java/org/javacord/bot/commands/InfoCommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.javacord.api.entity.channel.TextChannel;
88
import org.javacord.api.entity.message.Message;
99
import org.javacord.api.entity.message.embed.EmbedBuilder;
10+
import org.javacord.api.entity.server.Server;
1011
import org.javacord.bot.Constants;
1112
import org.javacord.bot.listeners.CommandCleanupListener;
1213

@@ -15,11 +16,17 @@ public class InfoCommand implements CommandExecutor {
1516
/**
1617
* Executes the {@code !info} command.
1718
*
19+
* @param server The server where the command was issued.
1820
* @param channel The channel where the command was issued.
1921
* @param message The message the command was issued in.
2022
*/
2123
@Command(aliases = "!info", async = true)
22-
public void handleCommand(TextChannel channel, Message message) {
24+
public void handleCommand(Server server, TextChannel channel, Message message) {
25+
// Only react in #java_javacord channel on Discord API server
26+
if ((server.getId() == Constants.DAPI_SERVER_ID) && (channel.getId() != Constants.DAPI_JAVACORD_CHANNEL_ID)) {
27+
return;
28+
}
29+
2330
final DiscordApi api = channel.getApi();
2431
EmbedBuilder embed = new EmbedBuilder()
2532
.setColor(Constants.JAVACORD_ORANGE)

src/main/java/org/javacord/bot/commands/InviteCommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.javacord.api.entity.channel.TextChannel;
66
import org.javacord.api.entity.message.Message;
77
import org.javacord.api.entity.message.embed.EmbedBuilder;
8+
import org.javacord.api.entity.server.Server;
89
import org.javacord.bot.Constants;
910
import org.javacord.bot.listeners.CommandCleanupListener;
1011

@@ -19,12 +20,18 @@ public class InviteCommand implements CommandExecutor {
1920
/**
2021
* Executes the {@code !invite} command.
2122
*
23+
* @param server The server where the command was issued.
2224
* @param channel The channel where the command was issued.
2325
* @param message The message the command was issued in.
2426
* @throws IOException If the Javacord icon stream cannot be closed properly.
2527
*/
2628
@Command(aliases = {"!invite"}, async = true)
27-
public void onCommand(TextChannel channel, Message message) throws IOException {
29+
public void onCommand(Server server, TextChannel channel, Message message) throws IOException {
30+
// Only react in #java_javacord channel on Discord API server
31+
if ((server.getId() == Constants.DAPI_SERVER_ID) && (channel.getId() != Constants.DAPI_JAVACORD_CHANNEL_ID)) {
32+
return;
33+
}
34+
2835
try (InputStream javacord3Icon = getClass().getClassLoader().getResourceAsStream("javacord3_icon.png")) {
2936
EmbedBuilder embed = new EmbedBuilder()
3037
.setThumbnail(javacord3Icon, "png")

src/main/java/org/javacord/bot/commands/MavenCommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.javacord.api.entity.channel.TextChannel;
77
import org.javacord.api.entity.message.Message;
88
import org.javacord.api.entity.message.embed.EmbedBuilder;
9+
import org.javacord.api.entity.server.Server;
910
import org.javacord.bot.Constants;
1011
import org.javacord.bot.listeners.CommandCleanupListener;
1112

@@ -17,11 +18,17 @@ public class MavenCommand implements CommandExecutor {
1718
/**
1819
* Executes the {@code !maven} command.
1920
*
21+
* @param server The server where the command was issued.
2022
* @param channel The channel where the command was issued.
2123
* @param message The message the command was issued in.
2224
*/
2325
@Command(aliases = {"!maven"}, async = true)
24-
public void onCommand(TextChannel channel, Message message) {
26+
public void onCommand(Server server, TextChannel channel, Message message) {
27+
// Only react in #java_javacord channel on Discord API server
28+
if ((server.getId() == Constants.DAPI_SERVER_ID) && (channel.getId() != Constants.DAPI_JAVACORD_CHANNEL_ID)) {
29+
return;
30+
}
31+
2532
EmbedBuilder embed = new EmbedBuilder()
2633
.setColor(Constants.JAVACORD_ORANGE)
2734
.addField("Dependency",

src/main/java/org/javacord/bot/commands/Sdcf4jCommand.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.javacord.api.entity.channel.TextChannel;
66
import org.javacord.api.entity.message.Message;
77
import org.javacord.api.entity.message.embed.EmbedBuilder;
8+
import org.javacord.api.entity.server.Server;
89
import org.javacord.bot.Constants;
910
import org.javacord.bot.listeners.CommandCleanupListener;
1011

@@ -13,11 +14,16 @@ public class Sdcf4jCommand implements CommandExecutor {
1314
/**
1415
* Executes the {@code !sdcf4j} command.
1516
*
17+
* @param server The server where the command was issued.
1618
* @param channel The channel where the command was issued.
1719
* @param message The message the command was issued in.
1820
*/
1921
@Command(aliases = {"!sdcf4j", "!commands"}, async = true)
20-
public void onCommand(TextChannel channel, Message message) {
22+
public void onCommand(Server server, TextChannel channel, Message message) {
23+
// Only react in #java_javacord channel on Discord API server
24+
if ((server.getId() == Constants.DAPI_SERVER_ID) && (channel.getId() != Constants.DAPI_JAVACORD_CHANNEL_ID)) {
25+
return;
26+
}
2127

2228
EmbedBuilder embed = new EmbedBuilder()
2329
.setTitle("SDCF4J")

src/main/java/org/javacord/bot/commands/SetupCommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.javacord.api.entity.channel.TextChannel;
66
import org.javacord.api.entity.message.Message;
77
import org.javacord.api.entity.message.embed.EmbedBuilder;
8+
import org.javacord.api.entity.server.Server;
89
import org.javacord.bot.Constants;
910
import org.javacord.bot.listeners.CommandCleanupListener;
1011

@@ -16,11 +17,17 @@ public class SetupCommand implements CommandExecutor {
1617
/**
1718
* Executes the {@code !setup} command.
1819
*
20+
* @param server The server where the command was issued.
1921
* @param channel The channel where the command was issued.
2022
* @param message The message the command was issued in.
2123
*/
2224
@Command(aliases = {"!setup"}, async = true)
23-
public void onCommand(TextChannel channel, Message message) {
25+
public void onCommand(Server server, TextChannel channel, Message message) {
26+
// Only react in #java_javacord channel on Discord API server
27+
if ((server.getId() == Constants.DAPI_SERVER_ID) && (channel.getId() != Constants.DAPI_JAVACORD_CHANNEL_ID)) {
28+
return;
29+
}
30+
2431
EmbedBuilder embed = new EmbedBuilder()
2532
.setColor(Constants.JAVACORD_ORANGE)
2633
.addField("Gradle Dependency",

0 commit comments

Comments
 (0)