Message Reaction Debug messages
This commit is contained in:
parent
e0d66b816d
commit
5f70ed36a2
@ -35,6 +35,8 @@ import io.rixa.bot.events.ReadyListener;
|
||||
import io.rixa.bot.events.UserListener;
|
||||
import io.rixa.bot.guild.RixaGuild;
|
||||
import io.rixa.bot.guild.manager.GuildManager;
|
||||
import io.rixa.bot.reactions.ReactManager;
|
||||
import io.rixa.bot.reactions.react.HelpReaction;
|
||||
import io.rixa.bot.user.RixaUser;
|
||||
import io.rixa.bot.user.manager.UserManager;
|
||||
import io.rixa.bot.utils.FileUtils;
|
||||
@ -63,6 +65,8 @@ public class Rixa {
|
||||
@Getter
|
||||
private CommandHandler commandHandler;
|
||||
@Getter
|
||||
private ReactManager reactManager;
|
||||
@Getter
|
||||
private Configuration configuration;
|
||||
@Getter
|
||||
private ObjectMapper objectMapper;
|
||||
@ -75,15 +79,17 @@ public class Rixa {
|
||||
|
||||
private Rixa() {
|
||||
instance = this;
|
||||
logger = Logger.getLogger(Rixa.class.getCanonicalName());
|
||||
objectMapper = new ObjectMapper(new YAMLFactory());
|
||||
defaultPath = new File("Rixa/");
|
||||
commandHandler = new CommandHandler();
|
||||
shardList = new ArrayList<>();
|
||||
defaultPath.mkdirs();
|
||||
loadConfiguration();
|
||||
registerCommands();
|
||||
loadJDA();
|
||||
this.logger = Logger.getLogger(Rixa.class.getCanonicalName());
|
||||
this.objectMapper = new ObjectMapper(new YAMLFactory());
|
||||
this.defaultPath = new File("Rixa/");
|
||||
this.commandHandler = new CommandHandler();
|
||||
this.reactManager = new ReactManager();
|
||||
this.shardList = new ArrayList<>();
|
||||
this.defaultPath.mkdirs();
|
||||
this.loadConfiguration();
|
||||
this.registerCommands();
|
||||
this.registerReactions();
|
||||
this.loadJDA();
|
||||
}
|
||||
|
||||
public static Rixa getInstance() {
|
||||
@ -128,6 +134,10 @@ public class Rixa {
|
||||
timeUp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private void registerReactions() {
|
||||
this.reactManager.registerReact(new HelpReaction("Help"));
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
this.commandHandler.registerCommands(
|
||||
new AdviceCommand("advice", RixaPermission.NONE, "Receive advice from the great beyond...",
|
||||
|
@ -37,7 +37,7 @@ public class YoutubeSearch {
|
||||
return items.getJSONObject(index).getJSONObject("id").getString("kind");
|
||||
}
|
||||
|
||||
public String getVideoId(int index) {
|
||||
public String getVideoId(int index) throws JSONException {
|
||||
if (!hasVideoId(index)) {
|
||||
index++;
|
||||
}
|
||||
@ -45,7 +45,7 @@ public class YoutubeSearch {
|
||||
}
|
||||
|
||||
public boolean hasVideoId(int index) {
|
||||
return items.getJSONObject(index).getJSONObject("id").has("videoID");
|
||||
return items.getJSONObject(index).getJSONObject("id").has("videoId");
|
||||
}
|
||||
|
||||
public String getPublishedTime(int index) {
|
||||
|
@ -14,18 +14,10 @@ import net.dv8tion.jda.core.entities.TextChannel;
|
||||
|
||||
public abstract class Command {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String command, description;
|
||||
@Getter
|
||||
@Setter
|
||||
private RixaPermission permission;
|
||||
@Getter
|
||||
@Setter
|
||||
private List<String> aliases;
|
||||
@Getter
|
||||
@Setter
|
||||
private CommandType commandType;
|
||||
@Getter @Setter private String command, description;
|
||||
@Getter @Setter private RixaPermission permission;
|
||||
@Getter @Setter private List<String> aliases;
|
||||
@Getter @Setter private CommandType commandType;
|
||||
|
||||
public Command(String command) {
|
||||
this(command, RixaPermission.NONE, "Undefined", CommandType.USER, Collections.emptyList());
|
||||
@ -45,11 +37,11 @@ public abstract class Command {
|
||||
|
||||
public Command(String command, RixaPermission rixaPermission, String description,
|
||||
CommandType commandType, List<String> aliases) {
|
||||
setCommand(command);
|
||||
setPermission(rixaPermission);
|
||||
setDescription(description);
|
||||
setAliases(aliases);
|
||||
this.commandType = commandType;
|
||||
this.setCommand(command);
|
||||
this.setPermission(rixaPermission);
|
||||
this.setDescription(description);
|
||||
this.setAliases(aliases);
|
||||
this.setCommandType(commandType);
|
||||
}
|
||||
|
||||
// public abstract void execute(GuildMessageReceivedEvent event);
|
||||
|
@ -6,32 +6,31 @@ import io.rixa.bot.commands.perms.RixaPermission;
|
||||
import io.rixa.bot.guild.RixaGuild;
|
||||
import io.rixa.bot.guild.manager.GuildManager;
|
||||
import io.rixa.bot.guild.modules.module.LevelsModule;
|
||||
import io.rixa.bot.user.RixaUser;
|
||||
import io.rixa.bot.user.manager.UserManager;
|
||||
import io.rixa.bot.utils.DiscordUtils;
|
||||
import io.rixa.bot.utils.MessageFactory;
|
||||
import net.dv8tion.jda.core.MessageBuilder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.entities.TextChannel;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LeaderboardsCommand extends Command {
|
||||
|
||||
public LeaderboardsCommand(String command, RixaPermission rixaPermission, String description, CommandType commandType {
|
||||
public LeaderboardsCommand(String command, RixaPermission rixaPermission, String description,
|
||||
CommandType commandType) {
|
||||
super(command, rixaPermission, description, commandType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String commandLabel, Guild guild, Member member, TextChannel channel, String[] args) {
|
||||
public void execute(String commandLabel, Guild guild, Member member, TextChannel channel,
|
||||
String[] args) {
|
||||
RixaGuild rixaGuild = GuildManager.getInstance().getGuild(guild);
|
||||
LevelsModule levelsModule = (LevelsModule) rixaGuild.getModule("Levels");
|
||||
int page = 1;
|
||||
List<String> leaderboard = getLeaderboard(rixaGuild, page);
|
||||
MessageFactory.create(leaderboard.isEmpty() ? "No users found!" : (String.join("\n", leaderboard)))
|
||||
MessageFactory
|
||||
.create(leaderboard.isEmpty() ? "No users found!" : (String.join("\n", leaderboard)))
|
||||
.setAuthor("Leaderboard: " + guild.getName(), guild.getIconUrl())
|
||||
.setColor(member.getColor())
|
||||
.queue(channel, message -> {
|
||||
|
@ -1,28 +1,64 @@
|
||||
package io.rixa.bot.events;
|
||||
|
||||
import com.mysql.jdbc.StringUtils;
|
||||
import io.rixa.bot.Rixa;
|
||||
import io.rixa.bot.commands.Command;
|
||||
import io.rixa.bot.commands.exceptions.CommandNotFoundException;
|
||||
import io.rixa.bot.commands.exceptions.ReactNotFoundException;
|
||||
import io.rixa.bot.commands.perms.RixaPermission;
|
||||
import io.rixa.bot.guild.RixaGuild;
|
||||
import io.rixa.bot.guild.manager.GuildManager;
|
||||
import io.rixa.bot.guild.modules.module.ConversationModule;
|
||||
import io.rixa.bot.reactions.React;
|
||||
import io.rixa.bot.user.RixaUser;
|
||||
import io.rixa.bot.user.manager.UserManager;
|
||||
import io.rixa.bot.utils.DiscordUtils;
|
||||
import io.rixa.bot.utils.MessageFactory;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.core.entities.TextChannel;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.events.message.guild.react.GuildMessageReactionAddEvent;
|
||||
import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent;
|
||||
import net.dv8tion.jda.core.hooks.SubscribeEvent;
|
||||
|
||||
public class MessageListener {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onReactionAdded(GuildMessageReactionAddEvent event) {
|
||||
if (event.getUser().isBot()) return;
|
||||
public void onReactionAdded(MessageReactionAddEvent event) {
|
||||
System.out.println("Reaction Event Triggered - 1");
|
||||
if (event.getUser().isBot()) {
|
||||
return;
|
||||
}
|
||||
event.getChannel().getMessageById(event.getMessageId()).queue(message -> {
|
||||
React react = this.check(message);
|
||||
if (react != null) {
|
||||
react.onReact(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private React check(Message message) {
|
||||
if (message == null || message.getEmbeds().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
MessageEmbed messageEmbed = message.getEmbeds().get(0);
|
||||
if (StringUtils.isNullOrEmpty(messageEmbed.getTitle())) {
|
||||
return null;
|
||||
}
|
||||
String[] titleSplit = messageEmbed.getTitle().split(": ");
|
||||
if (titleSplit[0].equalsIgnoreCase("Leaderboard")) {
|
||||
return null; // Not sure if this is required anymore.
|
||||
}
|
||||
try {
|
||||
React react = Rixa.getInstance().getReactManager().getReaction(titleSplit[0]);
|
||||
if (react != null) {
|
||||
return react;
|
||||
}
|
||||
} catch (ReactNotFoundException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -1,10 +1,17 @@
|
||||
package io.rixa.bot.reactions;
|
||||
|
||||
import net.dv8tion.jda.core.events.message.guild.react.GuildMessageReactionAddEvent;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent;
|
||||
import net.dv8tion.jda.core.hooks.SubscribeEvent;
|
||||
|
||||
public interface React {
|
||||
public abstract class React {
|
||||
|
||||
void onReact(GuildMessageReactionAddEvent event);
|
||||
@Getter private final String name;
|
||||
|
||||
String getName();
|
||||
public React(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public abstract void onReact(MessageReactionAddEvent event);
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package io.rixa.bot.reactions;
|
||||
|
||||
import io.rixa.bot.commands.Command;
|
||||
import io.rixa.bot.commands.exceptions.CommandNotFoundException;
|
||||
import io.rixa.bot.commands.exceptions.ReactNotFoundException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -2,40 +2,56 @@ package io.rixa.bot.reactions.react;
|
||||
|
||||
import io.rixa.bot.Rixa;
|
||||
import io.rixa.bot.commands.handler.CommandHandler;
|
||||
import io.rixa.bot.commands.handler.CommandType;
|
||||
import io.rixa.bot.guild.RixaGuild;
|
||||
import io.rixa.bot.guild.manager.GuildManager;
|
||||
import io.rixa.bot.reactions.React;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.core.events.message.guild.react.GuildMessageReactionAddEvent;
|
||||
import net.dv8tion.jda.core.events.message.priv.react.PrivateMessageReactionAddEvent;
|
||||
import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent;
|
||||
import net.dv8tion.jda.core.exceptions.ErrorResponseException;
|
||||
import net.dv8tion.jda.core.hooks.SubscribeEvent;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
|
||||
public class HelpReaction implements React {
|
||||
public class HelpReaction extends React {
|
||||
|
||||
public HelpReaction(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SubscribeEvent
|
||||
public void onReact(GuildMessageReactionAddEvent event) {
|
||||
public void onReact(MessageReactionAddEvent event) {
|
||||
System.out.println("Help Triggered");
|
||||
if (event.getUser().getId().equalsIgnoreCase(event.getJDA().getSelfUser().getId())) {
|
||||
return;
|
||||
}
|
||||
System.out.println("Not bot");
|
||||
Message message = event.getChannel().getMessageById(event.getMessageId()).complete();
|
||||
this.execute(message, event.getReaction().getReactionEmote().getName(), event.getJDA());
|
||||
}
|
||||
|
||||
private void execute(Message message, String emoteName, JDA jda) {
|
||||
System.out.println("Executed");
|
||||
MessageEmbed messageEmbed = message.getEmbeds().get(0);
|
||||
if (!messageEmbed.getTitle().contains(": ")) {
|
||||
return;
|
||||
}
|
||||
String title = messageEmbed.getTitle().split(": ")[1];
|
||||
RixaGuild rixaGuild = GuildManager.getInstance().getGuild(event.getJDA().getGuildById(title));
|
||||
RixaGuild rixaGuild = GuildManager.getInstance().getGuild(jda.getGuildById(title));
|
||||
if (rixaGuild == null) {
|
||||
return;
|
||||
}
|
||||
String prefix = rixaGuild.getSettings().getPrefix();
|
||||
EmbedBuilder embedBuilder;
|
||||
try {
|
||||
switch (event.getReaction().getReactionEmote().getName()) {
|
||||
switch (emoteName) {
|
||||
case "\uD83D\uDDD1":// waste bin
|
||||
if (message.getAuthor().getId().equalsIgnoreCase(event.getJDA().getSelfUser().getId())) {
|
||||
if (message.getAuthor().getId().equalsIgnoreCase(jda.getSelfUser().getId())) {
|
||||
message.delete().complete();
|
||||
}
|
||||
break;
|
||||
@ -48,11 +64,12 @@ public class HelpReaction implements React {
|
||||
embedBuilder.setTitle(String.format("Help: %s", title));
|
||||
embedBuilder.setDescription(stringBuilder);
|
||||
Rixa.getInstance().getCommandHandler().getAllCommands().values()
|
||||
.stream().filter(cmd -> cmd.getCommandType() == CommandType.USER)
|
||||
.forEach(cmd -> embedBuilder.addField(prefix + cmd.getCommand(),
|
||||
cmd.getDescription(), false));
|
||||
message.editMessage(embedBuilder.build()).queue();
|
||||
break;
|
||||
/*case "\u0032\u20E3": // two emoji
|
||||
case "\u0032\u20E3": // two emoji
|
||||
embedBuilder = new EmbedBuilder();
|
||||
stringBuilder = "\u2753" +
|
||||
" **Staff Commands Help**" +
|
||||
@ -61,12 +78,11 @@ public class HelpReaction implements React {
|
||||
embedBuilder.setTitle(String.format("Help: %s", title));
|
||||
embedBuilder.setDescription(stringBuilder);
|
||||
Rixa.getInstance().getCommandHandler().getAllCommands().values().stream()
|
||||
.filter(cmd -> cmd.getAnnotation().type() == CommandType.ADMIN
|
||||
|| cmd.getAnnotation().type() == CommandType.MOD)
|
||||
.forEach(cmd -> embedBuilder.addField(prefix + cmd.getAnnotation().mainCommand(),
|
||||
cmd.getAnnotation().description(), false));
|
||||
.filter(cmd -> cmd.getCommandType() == CommandType.STAFF)
|
||||
.forEach(cmd -> embedBuilder.addField(prefix + cmd.getCommand(),
|
||||
cmd.getDescription(), false));
|
||||
message.editMessage(embedBuilder.build()).queue();
|
||||
break;*/
|
||||
break;
|
||||
case "\u0033\u20E3": // three emoji
|
||||
embedBuilder = new EmbedBuilder();
|
||||
stringBuilder = "\u2753" +
|
||||
|
Loading…
Reference in New Issue
Block a user