0

Added restriction of rank sync channel.

This commit is contained in:
Logan Fick
2019-03-10 19:04:50 -04:00
parent 3c88f2e9f2
commit ceafc5039f
2 changed files with 44 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package com.redstoner.discordbot;
import com.redstoner.discordbot.commands.LinkAccount;
import com.redstoner.discordbot.commands.LinkStatus;
import com.redstoner.discordbot.commands.Nickname;
import com.redstoner.discordbot.events.GuildMessageReceived;
import com.redstoner.discordbot.tasks.ForumNotificationTask;
import com.redstoner.discordbot.tasks.GuildRankSyncTask;
import com.redstoner.discordbot.utils.RankUtil;
@@ -50,6 +51,9 @@ public final class Main {
CommandManager.registerCommand("linkstatus", new LinkStatus(), false);
CommandManager.registerCommandAlias("ls", "linkstatus");
logger.info("Registering events...");
LogalBot.getJDA().addEventListener(new GuildMessageReceived());
logger.info("Starting tasks...");
Scheduler.scheduleAtFixedRate(new ForumNotificationTask(), 1, 1, TimeUnit.MINUTES);
Scheduler.scheduleAtFixedRate(new GuildRankSyncTask(), 1, 5, TimeUnit.MINUTES);

View File

@@ -0,0 +1,40 @@
package com.redstoner.discordbot.events;
import dev.logal.logalbot.commands.CommandManager;
import dev.logal.logalbot.commands.CommandResponse;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import java.util.concurrent.TimeUnit;
public final class GuildMessageReceived extends ListenerAdapter {
private final String rankSyncChannel = "470263993458491392";
@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
Guild guild = event.getGuild();
TextChannel channel = event.getChannel();
Message message = event.getMessage();
String rawMessage = message.getContentRaw();
Member member = event.getMember();
if (channel.getId().equals(rankSyncChannel)) {
if (guild.getSelfMember().hasPermission(channel, Permission.MESSAGE_MANAGE)) {
message.delete().reason("Redstoner Channel Restriction").queue();
}
if (rawMessage.length() == 8 && rawMessage.matches("[A-Za-z0-9]+")) {
CommandManager.executeCommand(new String[] { "linkaccount", rawMessage }, member, channel);
} else {
new CommandResponse(
"no_entry_sign",
"Sorry " + member.getAsMention() + ", but this channel can only be used for rank synchronization tokens. If you need help, contact staff in the `staff-help` channel."
).setDeletionDelay(30, TimeUnit.SECONDS).sendResponse(channel);
}
}
}
}