Changed channelId to long

This commit is contained in:
Teriuihi 2021-09-17 16:31:21 +02:00
parent 49e53fb01c
commit 44a335bf12
4 changed files with 22 additions and 7 deletions

View File

@ -53,7 +53,7 @@ public class Bot {
} }
} }
public void sendMessageToDiscord(String channelid, String message) { public void sendMessageToDiscord(long channelid, String message) {
//sendMessageToDiscord(client.getTextChannelById(channel), message, blocking); //sendMessageToDiscord(client.getTextChannelById(channel), message, blocking);
TextChannel channel = jda.getTextChannelById(channelid); TextChannel channel = jda.getTextChannelById(channelid);
if (jda == null) return; if (jda == null) return;
@ -74,7 +74,7 @@ public class Bot {
} }
} }
public void sendEmbedToDiscord(String channelid, EmbedBuilder embedBuilder, long secondsTillDelete) { public void sendEmbedToDiscord(long channelid, EmbedBuilder embedBuilder, long secondsTillDelete) {
//sendMessageToDiscord(client.getTextChannelById(channel), message, blocking); //sendMessageToDiscord(client.getTextChannelById(channel), message, blocking);
TextChannel channel = jda.getTextChannelById(channelid); TextChannel channel = jda.getTextChannelById(channelid);
if (jda == null) return; if (jda == null) return;

View File

@ -7,14 +7,14 @@ import net.dv8tion.jda.api.EmbedBuilder;
import java.awt.*; import java.awt.*;
public class DiscordSendMessage { public class DiscordSendMessage {
public static void sendMessage(String channelId, String message) public static void sendMessage(long channelId, String message)
{ {
Bot bot = DiscordLink.getPlugin().getBot(); Bot bot = DiscordLink.getPlugin().getBot();
bot.sendMessageToDiscord(channelId, message); bot.sendMessageToDiscord(channelId, message);
} }
public static void sendEmbed(String channelId, String title, String description) public static void sendEmbed(long channelId, String title, String description)
{ {
Bot bot = DiscordLink.getPlugin().getBot(); Bot bot = DiscordLink.getPlugin().getBot();
EmbedBuilder embedBuilder = new EmbedBuilder(); EmbedBuilder embedBuilder = new EmbedBuilder();

View File

@ -8,6 +8,7 @@ import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional;
public class DiscordMessageListener extends ListenerAdapter { public class DiscordMessageListener extends ListenerAdapter {
@ -27,7 +28,7 @@ public class DiscordMessageListener extends ListenerAdapter {
if (event.isWebhookMessage()) { if (event.isWebhookMessage()) {
return; return;
} }
if (event.getMessage().getChannel().getId().equals(BotConfig.COMMAND_CHANNEL)) { if (event.getMessage().getChannel().getIdLong() == BotConfig.LINK_CHANNEL) {
String content = event.getMessage().getContentRaw(); String content = event.getMessage().getContentRaw();
if (content.startsWith(BotConfig.prefixMap.get(event.getGuild().getIdLong())) && content.length() > 1) { if (content.startsWith(BotConfig.prefixMap.get(event.getGuild().getIdLong())) && content.length() > 1) {
String[] split = content.split(" "); String[] split = content.split(" ");
@ -44,6 +45,18 @@ public class DiscordMessageListener extends ListenerAdapter {
} }
} }
} }
if (event.getMessage().getChannel().getIdLong() == BotConfig.LINK_CHANNEL) {
String content = event.getMessage().getContentRaw();
String[] split = content.split(" ");
String cmd = split[0].substring(1).toLowerCase();
String[] args = Arrays.copyOfRange(split, 1, split.length);
if (cmd.equalsIgnoreCase("link")) {
Optional<DiscordCommand> link = DiscordCommand.getCommands().stream().filter(discordCommand -> discordCommand.getCommand().equals("link")).findFirst();
if (!link.isEmpty()) {
link.get().handleCommand(event.getMessage(), event.getAuthor().getName(), cmd, args);
}
}
}
} }
} }

View File

@ -167,13 +167,15 @@ public class BotConfig {
**/ **/
public static String BOT_TOKEN = "unconfigured"; public static String BOT_TOKEN = "unconfigured";
public static String COMMAND_CHANNEL = "unconfigured"; public static long COMMAND_CHANNEL = -1;
public static long LINK_CHANNEL = -1;
public static long GUILD_ID = -1; public static long GUILD_ID = -1;
public static long LINKED_ROLE_ID = -1; public static long LINKED_ROLE_ID = -1;
private static void settings() { private static void settings() {
BOT_TOKEN = getString("settings.token", BOT_TOKEN); BOT_TOKEN = getString("settings.token", BOT_TOKEN);
COMMAND_CHANNEL = getString("settings.command_channel", COMMAND_CHANNEL); COMMAND_CHANNEL = getLong("settings.command-channel", COMMAND_CHANNEL);
LINK_CHANNEL = getLong("settings.link-channel", LINK_CHANNEL);
GUILD_ID = getLong("settings.guild-id", GUILD_ID); GUILD_ID = getLong("settings.guild-id", GUILD_ID);
LINKED_ROLE_ID = getLong("settings.linked-role-id", LINKED_ROLE_ID); LINKED_ROLE_ID = getLong("settings.linked-role-id", LINKED_ROLE_ID);
} }