Merge pull request #272 from Focusvity/pr/discord-msg

Prevent Discord from sending messages to the server
This commit is contained in:
CoolJWB 2020-08-18 09:27:05 +02:00 committed by GitHub
commit fc08761e70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 14 deletions

View File

@ -20,7 +20,6 @@ import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.staff.StaffMember; import me.totalfreedom.totalfreedommod.staff.StaffMember;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
@ -78,20 +77,20 @@ public class Discord extends FreedomService
} }
try try
{ {
bot = new JDABuilder(AccountType.BOT) bot = JDABuilder.createDefault(ConfigEntry.DISCORD_TOKEN.getString())
.setToken(ConfigEntry.DISCORD_TOKEN.getString()) .addEventListeners(new PrivateMessageListener(),
.addEventListeners(new PrivateMessageListener()) new DiscordToMinecraftListener(),
.addEventListeners(new DiscordToMinecraftListener()) new ListenerAdapter()
{
@Override
public void onReady(ReadyEvent event)
{
new StartEvent(event.getJDA()).start();
}
})
.setAutoReconnect(true) .setAutoReconnect(true)
.setRateLimitPool(RATELIMIT_EXECUTOR) .setRateLimitPool(RATELIMIT_EXECUTOR)
.addEventListeners(new ListenerAdapter() .build();
{
@Override
public void onReady(ReadyEvent event)
{
new StartEvent(event.getJDA()).start();
}
}).build();
FLog.info("Discord verification bot has successfully enabled!"); FLog.info("Discord verification bot has successfully enabled!");
} }
catch (LoginException e) catch (LoginException e)

View File

@ -20,7 +20,7 @@ public class DiscordToMinecraftListener extends ListenerAdapter
String chat_channel_id = ConfigEntry.DISCORD_CHAT_CHANNEL_ID.getString(); String chat_channel_id = ConfigEntry.DISCORD_CHAT_CHANNEL_ID.getString();
if (event.getMember() != null && !chat_channel_id.isEmpty() && event.getChannel().getId().equals(chat_channel_id)) if (event.getMember() != null && !chat_channel_id.isEmpty() && event.getChannel().getId().equals(chat_channel_id))
{ {
if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId())) if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId()) && !event.getMessage().getContentDisplay().isEmpty())
{ {
Member member = event.getMember(); Member member = event.getMember();
String tag = getDisplay(member); String tag = getDisplay(member);