Added restriction of rank sync channel.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user