Skip to content

Commit

Permalink
Version 1.1
Browse files Browse the repository at this point in the history
You are now able to select a specific channel where the bot should listen for commands
  • Loading branch information
Pequla committed Feb 12, 2021
1 parent cccea38 commit 003f22b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ id:
admin-role: role-id
death-channel: channel-id
join-leave-channel: channel-id
bot-commands-channel: channel-id

```
Now replace `bot-token-goes-here` with the bot token you copied from the Discord developer page of your application. Chose your own command prefix, but you can also stick with defaults.
Expand All @@ -43,6 +44,8 @@ With this plugin you get a player death notification on discord as well as the f

Player join leave notifications also exist and they are self explanatory, when the player joins or leaves the game it will display the message in the channel specified as well as the total number of players at that time. This feature will make your server much more active since other players will join instantly if they see somone else is online

Custom bot commands channel, this way you dont need to fiddle arround with permissions, all you need to do is to change the `channel-id` place holder under the `bot-commands-channel` property with your bot only commands channel id. Bot will listen only in that channel for commands.

## More information
This plugin is extreamly light weight and will consume less then 40MB of ram while running, it might seam a lot but the way you communicate with Discord is really complicated and in order to keep the connection running we need a little bit more RAM. In terms of bandwith no worries there, the bot will consume an average of 10MB per month.

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.pequla.bot.minecraft</groupId>
<artifactId>minecraft-bot</artifactId>
<version>1.0</version>
<version>1.1</version>
<packaging>jar</packaging>

<name>MinecraftBot</name>
Expand Down Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.2.0_227</version>
<version>4.2.0_228</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/pequla/bot/minecraft/MinecraftBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public final class MinecraftBot extends JavaPlugin {
private final String adminRole;
private final String deathChannel;
private final String joinLeaveChannel;
private final String botCommandsChannel;
private JDA jda;

public MinecraftBot() {
Expand All @@ -38,6 +39,7 @@ public MinecraftBot() {
this.adminRole = config.getString("id.admin-role");
this.deathChannel = config.getString("id.death-channel");
this.joinLeaveChannel = config.getString("id.join-leave-channel");
this.botCommandsChannel = config.getString("bot-commands-channel");
}

@Override
Expand Down Expand Up @@ -105,6 +107,10 @@ public String getJoinLeaveChannel() {
return joinLeaveChannel;
}

public String getBotCommandsChannel() {
return botCommandsChannel;
}

public JDA getJda() {
return jda;
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/pequla/bot/minecraft/module/CommandModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.pequla.bot.minecraft.MinecraftBot;
import com.pequla.bot.minecraft.command.*;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
Expand All @@ -27,10 +28,13 @@ public CommandModule(MinecraftBot plugin) {
@Override
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
if (!event.getAuthor().isBot()) {
String[] message = event.getMessage().getContentRaw().trim().split("\\s+");
GuildCommand command = map.get(message[0]);
if (command != null) {
command.execute(plugin, event.getMember(), event.getChannel(), Arrays.copyOfRange(message, 1, message.length));
TextChannel channel = event.getChannel();
if (channel.getId().equals(plugin.getBotCommandsChannel())) {
String[] message = event.getMessage().getContentRaw().trim().split("\\s+");
GuildCommand command = map.get(message[0]);
if (command != null) {
command.execute(plugin, event.getMember(), channel, Arrays.copyOfRange(message, 1, message.length));
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ id:
admin-role: role-id
death-channel: channel-id
join-leave-channel: channel-id
bot-commands-channel: channel-id

0 comments on commit 003f22b

Please sign in to comment.