Added info message rechecking
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package com.redstoner.redstonerBot.commands;
|
||||||
|
|
||||||
|
import com.redstoner.redstonerBot.managers.DiscordManager;
|
||||||
|
import com.redstoner.redstonerBot.managers.InfoManager;
|
||||||
|
import net.dv8tion.jda.core.entities.*;
|
||||||
|
|
||||||
|
public class CheckMessagesCommand implements Command {
|
||||||
|
@Override
|
||||||
|
public boolean execute(Guild guild, TextChannel channel, Message message, User author, Member self, String command, String[] params) {
|
||||||
|
if (!guild.getOwnerId().equals(author.getId())) {
|
||||||
|
message.getChannel().sendMessage("You are not allowed to run this command " + author.getAsMention()).queue(DiscordManager::expireMessage);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
message.getChannel().sendMessage("Rechecking messages " + author.getAsMention()).queue(DiscordManager::expireMessage);
|
||||||
|
|
||||||
|
InfoManager.checkMessages();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,9 +7,13 @@ import net.dv8tion.jda.core.entities.*;
|
|||||||
public class StopCommand implements Command {
|
public class StopCommand implements Command {
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(Guild guild, TextChannel channel, Message message, User author, Member self, String command, String[] params) {
|
public boolean execute(Guild guild, TextChannel channel, Message message, User author, Member self, String command, String[] params) {
|
||||||
if (!guild.getOwnerId().equals(author.getId())) return false;
|
if (!guild.getOwnerId().equals(author.getId())) {
|
||||||
|
message.getChannel().sendMessage("You are not allowed to run this command " + author.getAsMention()).queue(DiscordManager::expireMessage);
|
||||||
|
|
||||||
message.getChannel().sendMessage("This bot will stop in 5 seconds, as requested by " + author.getAsTag()).queue(DiscordManager::expireMessage);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
message.getChannel().sendMessage("This bot will stop in 5 seconds, as requested by " + author.getAsMention()).queue(DiscordManager::expireMessage);
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.redstoner.redstonerBot.managers;
|
package com.redstoner.redstonerBot.managers;
|
||||||
|
|
||||||
import com.redstoner.redstonerBot.Manager;
|
import com.redstoner.redstonerBot.Manager;
|
||||||
|
import com.redstoner.redstonerBot.commands.CheckMessagesCommand;
|
||||||
import com.redstoner.redstonerBot.commands.Command;
|
import com.redstoner.redstonerBot.commands.Command;
|
||||||
import com.redstoner.redstonerBot.commands.InfoCommand;
|
import com.redstoner.redstonerBot.commands.InfoCommand;
|
||||||
import com.redstoner.redstonerBot.commands.StopCommand;
|
import com.redstoner.redstonerBot.commands.StopCommand;
|
||||||
@@ -23,7 +24,7 @@ public class CommandManager implements Manager {
|
|||||||
|
|
||||||
commands.put("info", new InfoCommand());
|
commands.put("info", new InfoCommand());
|
||||||
commands.put("stop", new StopCommand());
|
commands.put("stop", new StopCommand());
|
||||||
|
commands.put("checkmessages", new CheckMessagesCommand());
|
||||||
|
|
||||||
logger.info("Command Manager started!");
|
logger.info("Command Manager started!");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import java.util.List;
|
|||||||
public class InfoManager implements Manager {
|
public class InfoManager implements Manager {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(InfoManager.class);
|
private static final Logger logger = LoggerFactory.getLogger(InfoManager.class);
|
||||||
|
|
||||||
private List<ReactableMessageHandler> messageHandlers = new ArrayList<>();
|
private static List<ReactableMessageHandler> messageHandlers = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
@@ -29,11 +29,7 @@ public class InfoManager implements Manager {
|
|||||||
messageHandlers.add(new InfoReactableMessageHandler(jda, guild, channel));
|
messageHandlers.add(new InfoReactableMessageHandler(jda, guild, channel));
|
||||||
messageHandlers.add(new OptInReactableMessageHandler(jda, guild, channel));
|
messageHandlers.add(new OptInReactableMessageHandler(jda, guild, channel));
|
||||||
|
|
||||||
new Thread(() -> {
|
checkMessages();
|
||||||
for (ReactableMessageHandler handler : messageHandlers) {
|
|
||||||
handler.checkMessage();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
logger.info("Info Manager started!");
|
logger.info("Info Manager started!");
|
||||||
return true;
|
return true;
|
||||||
@@ -52,4 +48,14 @@ public class InfoManager implements Manager {
|
|||||||
logger.info("Info Manager stopped!");
|
logger.info("Info Manager stopped!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkMessages() {
|
||||||
|
new Thread(() -> {
|
||||||
|
for (ReactableMessageHandler handler : messageHandlers) {
|
||||||
|
handler.checkMessage();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import net.dv8tion.jda.core.entities.*;
|
|||||||
import net.dv8tion.jda.core.managers.GuildController;
|
import net.dv8tion.jda.core.managers.GuildController;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class InfoReactableMessageHandler extends ReactableMessageHandler {
|
public class InfoReactableMessageHandler extends ReactableMessageHandler {
|
||||||
static Map<String, String> configNames = new HashMap<>();
|
static Map<String, String> configNames = new HashMap<>();
|
||||||
@@ -32,7 +31,7 @@ public class InfoReactableMessageHandler extends ReactableMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(Consumer<? super Message> onSent) {
|
public Message getMessage() {
|
||||||
String prefix = DataManager.getConfigValue(configNames.get("prefix"));
|
String prefix = DataManager.getConfigValue(configNames.get("prefix"));
|
||||||
String suffix = DataManager.getConfigValue(configNames.get("suffix"));
|
String suffix = DataManager.getConfigValue(configNames.get("suffix"));
|
||||||
|
|
||||||
@@ -72,9 +71,10 @@ public class InfoReactableMessageHandler extends ReactableMessageHandler {
|
|||||||
|
|
||||||
msg.append(suffix);
|
msg.append(suffix);
|
||||||
|
|
||||||
channel.sendMessage(msg.build()).queue(onSent);
|
return msg.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReactionHandler getReactionHandler() {
|
public ReactionHandler getReactionHandler() {
|
||||||
return (messageId, reaction, author, added) -> {
|
return (messageId, reaction, author, added) -> {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import net.dv8tion.jda.core.entities.*;
|
|||||||
import net.dv8tion.jda.core.managers.GuildController;
|
import net.dv8tion.jda.core.managers.GuildController;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class OptInReactableMessageHandler extends ReactableMessageHandler {
|
public class OptInReactableMessageHandler extends ReactableMessageHandler {
|
||||||
static Map<String, String> configNames = new HashMap<>();
|
static Map<String, String> configNames = new HashMap<>();
|
||||||
@@ -34,7 +33,7 @@ public class OptInReactableMessageHandler extends ReactableMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(Consumer<? super Message> onSent) {
|
public Message getMessage() {
|
||||||
String prefix = DataManager.getConfigValue(configNames.get("prefix"));
|
String prefix = DataManager.getConfigValue(configNames.get("prefix"));
|
||||||
String suffix = DataManager.getConfigValue(configNames.get("suffix"));
|
String suffix = DataManager.getConfigValue(configNames.get("suffix"));
|
||||||
|
|
||||||
@@ -106,7 +105,7 @@ public class OptInReactableMessageHandler extends ReactableMessageHandler {
|
|||||||
|
|
||||||
msg.append(suffix);
|
msg.append(suffix);
|
||||||
|
|
||||||
channel.sendMessage(msg.build()).queue(onSent);
|
return msg.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -35,17 +35,22 @@ public abstract class ReactableMessageHandler {
|
|||||||
|
|
||||||
abstract Map<String, String> getConfigNames();
|
abstract Map<String, String> getConfigNames();
|
||||||
|
|
||||||
public abstract void send(Consumer<? super Message> onSent);
|
public abstract Message getMessage();
|
||||||
|
|
||||||
public abstract ReactionHandler getReactionHandler();
|
public abstract ReactionHandler getReactionHandler();
|
||||||
|
|
||||||
public abstract Set<String> getReactions();
|
public abstract Set<String> getReactions();
|
||||||
|
|
||||||
|
private void send(Consumer<? super Message> onSent) {
|
||||||
|
channel.sendMessage(getMessage()).queue(onSent);
|
||||||
|
}
|
||||||
|
|
||||||
public void checkMessage() {
|
public void checkMessage() {
|
||||||
logger.info("[Check] Checking message ID: " + msgId);
|
logger.info("[Check] Checking message ID: " + msgId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
checkAfterMessageFound(channel.getMessageById(msgId).complete());
|
checkAfterMessageFound(channel.getMessageById(msgId).complete());
|
||||||
|
channel.editMessageById(msgId, getMessage()).queue();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.info("[Check] Message with ID " + msgId + " does not exist, sending new one!");
|
logger.info("[Check] Message with ID " + msgId + " does not exist, sending new one!");
|
||||||
send(this::checkAfterMessageFound);
|
send(this::checkAfterMessageFound);
|
||||||
|
|||||||
Reference in New Issue
Block a user