mirror of
https://github.com/Noratrieb/killua-bot.git
synced 2026-01-14 23:25:01 +01:00
lots of optimizations
This commit is contained in:
parent
d79e80d422
commit
9684b72cc2
14 changed files with 206 additions and 83 deletions
|
|
@ -3,7 +3,6 @@ package com.github.nilstrieb.cofig;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.events.Event;
|
import net.dv8tion.jda.api.events.Event;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -15,13 +14,12 @@ public class Config {
|
||||||
public static final long THIS_ID = 801015254023798825L;
|
public static final long THIS_ID = 801015254023798825L;
|
||||||
|
|
||||||
public static EmbedBuilder getDefaultEmbed() {
|
public static EmbedBuilder getDefaultEmbed() {
|
||||||
|
|
||||||
EmbedBuilder builder = new EmbedBuilder();
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
builder.setColor(Config.DEFAULT_COLOR);
|
builder.setColor(Config.DEFAULT_COLOR);
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EmbedBuilder getDefaultEmbed(MessageReceivedEvent event) {
|
public static EmbedBuilder getDefaultEmbed(Event event) {
|
||||||
User killua = event.getJDA().getUserById(Config.THIS_ID);
|
User killua = event.getJDA().getUserById(Config.THIS_ID);
|
||||||
Objects.requireNonNull(killua, "user killua not found");
|
Objects.requireNonNull(killua, "user killua not found");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,13 @@ package com.github.nilstrieb.commands.fun;
|
||||||
|
|
||||||
import com.github.nilstrieb.cofig.Config;
|
import com.github.nilstrieb.cofig.Config;
|
||||||
import com.github.nilstrieb.commands.handler.Command;
|
import com.github.nilstrieb.commands.handler.Command;
|
||||||
import com.github.nilstrieb.reactions.ReactionEventManager;
|
|
||||||
import com.github.nilstrieb.reactions.ReactionListener;
|
|
||||||
import com.github.nilstrieb.util.DepartureSong;
|
import com.github.nilstrieb.util.DepartureSong;
|
||||||
import com.github.nilstrieb.util.MultiPageEmbed;
|
|
||||||
import com.iwebpp.crypto.TweetNaclFast;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
|
||||||
import net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class DepartureCommand extends Command {
|
public class DepartureCommand extends Command {
|
||||||
public DepartureCommand() {
|
public DepartureCommand() {
|
||||||
super("departure");
|
super("departure", "Returns the lyrics of the Hunter x Hunter Opening Song, Departure");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -44,8 +35,6 @@ public class DepartureCommand extends Command {
|
||||||
japaneseBuilder.addField("", DepartureSong.LYRICS_JAPANESE[i], false);
|
japaneseBuilder.addField("", DepartureSong.LYRICS_JAPANESE[i], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
event.getTextChannel().sendMessage(latinBuilder.build()).queue((message -> {
|
reply(event, latinBuilder.build(), japaneseBuilder.build());
|
||||||
new MultiPageEmbed(message, latinBuilder, japaneseBuilder);
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,22 @@
|
||||||
package com.github.nilstrieb.commands.fun;
|
package com.github.nilstrieb.commands.fun;
|
||||||
|
|
||||||
|
import com.github.nilstrieb.cofig.Config;
|
||||||
import com.github.nilstrieb.commands.handler.Command;
|
import com.github.nilstrieb.commands.handler.Command;
|
||||||
import com.github.nilstrieb.util.KilluaQuotes;
|
import com.github.nilstrieb.util.KilluaQuotes;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
public class QuoteCommand extends Command {
|
public class QuoteCommand extends Command {
|
||||||
public QuoteCommand() {
|
public QuoteCommand() {
|
||||||
super("quote");
|
super("quote", "Get a quote from Killua");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(MessageReceivedEvent event, String args) {
|
||||||
replyEmbed(event, "Killuas Quotes", KilluaQuotes.getRandomQuote());
|
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
||||||
|
.addField("Killuas Quotes", KilluaQuotes.getRandomQuote(), false);
|
||||||
|
|
||||||
|
reply(event, builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
public class SayCommand extends Command {
|
public class SayCommand extends Command {
|
||||||
public SayCommand(){
|
public SayCommand(){
|
||||||
super("say");
|
super("say", "Let Killua say something", "say hello gon", "<message>");
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(MessageReceivedEvent event, String args) {
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,55 @@
|
||||||
package com.github.nilstrieb.commands.handler;
|
package com.github.nilstrieb.commands.handler;
|
||||||
|
|
||||||
import com.github.nilstrieb.cofig.Config;
|
import com.github.nilstrieb.cofig.Config;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import com.github.nilstrieb.util.MultiPageEmbed;
|
||||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
|
||||||
import net.dv8tion.jda.api.events.Event;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
public abstract class Command {
|
public abstract class Command {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private final String description;
|
||||||
|
private final String exampleUsage;
|
||||||
|
private final String arguments;
|
||||||
private final CommandParser parser = CommandParser.getInstance();
|
private final CommandParser parser = CommandParser.getInstance();
|
||||||
|
|
||||||
public Command(String name) {
|
public Command(String name, String description, String exampleUsage, String arguments, boolean hidden) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
CommandHandler.addCommand(name, this);
|
this.description = description;
|
||||||
|
this.exampleUsage = exampleUsage;
|
||||||
|
this.arguments = arguments;
|
||||||
|
CommandHandler.addCommand(name, this, hidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command(String name, String description, String exampleUsage, String arguments){
|
||||||
|
this(name, description, exampleUsage, arguments, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command(String name, String description){
|
||||||
|
this(name, description, name, "", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void called(MessageReceivedEvent event, String args);
|
public abstract void called(MessageReceivedEvent event, String args);
|
||||||
|
|
||||||
protected void reply(MessageReceivedEvent event, String message) {
|
protected void reply(MessageReceivedEvent event, String message) {
|
||||||
event.getTextChannel().sendMessage(message).queue();
|
if(!message.equals("")){
|
||||||
|
event.getTextChannel().sendMessage(message).queue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void reply(MessageReceivedEvent event, MessageEmbed embed) {
|
protected void reply(MessageReceivedEvent event, MessageEmbed embed) {
|
||||||
event.getTextChannel().sendMessage(embed).queue();
|
if(!embed.isEmpty()){
|
||||||
|
event.getTextChannel().sendMessage(embed).queue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void replyEmbed(MessageReceivedEvent event, String fieldTitle, String fieldContent) {
|
protected void reply(MessageReceivedEvent event, MessageEmbed ... embeds){
|
||||||
|
if(!embeds[0].isEmpty()){
|
||||||
EmbedBuilder builder = Config.getDefaultEmbed(event);
|
event.getTextChannel().sendMessage(embeds[0]).queue(message -> new MultiPageEmbed(message, embeds));
|
||||||
builder.addField(fieldTitle, fieldContent, false);
|
}
|
||||||
|
|
||||||
event.getTextChannel().sendMessage(builder.build()).queue();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void deleteMsg(MessageReceivedEvent event, long delay) {
|
protected void deleteMsg(MessageReceivedEvent event, long delay) {
|
||||||
|
|
@ -54,4 +66,21 @@ public abstract class Command {
|
||||||
protected void deleteMsg(MessageReceivedEvent event) {
|
protected void deleteMsg(MessageReceivedEvent event) {
|
||||||
event.getMessage().delete().queue();
|
event.getMessage().delete().queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExampleUsage() {
|
||||||
|
return Config.PREFIX + exampleUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArguments() {
|
||||||
|
return arguments;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,104 @@
|
||||||
package com.github.nilstrieb.commands.handler;
|
package com.github.nilstrieb.commands.handler;
|
||||||
|
|
||||||
import com.github.nilstrieb.cofig.Config;
|
import com.github.nilstrieb.cofig.Config;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
|
import net.dv8tion.jda.api.events.Event;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class CommandHandler {
|
public class CommandHandler {
|
||||||
private static Map<String, Command> commands = new HashMap<>();
|
|
||||||
|
|
||||||
private static CommandParser parser = CommandParser.getInstance();
|
public static final int MAX_PAGE_LENGTH = 10;
|
||||||
|
private static final Map<String, Command> commands = new HashMap<>();
|
||||||
|
private static final Map<String, Command> hiddenCommands = new HashMap<>();
|
||||||
|
private static final CommandParser parser = CommandParser.getInstance();
|
||||||
|
|
||||||
|
public static void addCommand(String key, Command cmd, boolean hidden) {
|
||||||
|
if (hidden) {
|
||||||
|
hiddenCommands.put(key, cmd);
|
||||||
|
} else {
|
||||||
|
commands.put(key, cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void addCommand(String key, Command cmd) {
|
public static void addCommand(String key, Command cmd) {
|
||||||
commands.put(key, cmd);
|
commands.put(key, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void call(MessageReceivedEvent event) {
|
public static void call(MessageReceivedEvent event) {
|
||||||
if(event.getMessage().getContentRaw().startsWith(Config.PREFIX)) {
|
if (event.getMessage().getContentRaw().toLowerCase().startsWith(Config.PREFIX)) {
|
||||||
System.out.println("[CHandler] contains prefix");
|
|
||||||
String[] split = parser.splitOffCommandName(event.getMessage().getContentRaw());
|
String[] split = parser.splitOffCommandName(event.getMessage().getContentRaw());
|
||||||
System.out.println("[CHandler] cmd: '" + split[0] + "'" + " args: '" + split[1] + "'");
|
String command = split[0];
|
||||||
if(commands.containsKey(split[0])) {
|
System.out.println("[CHandler] cmd: '" + command + "'" + " args: '" + split[1] + "'");
|
||||||
System.out.println("[CHandler] command exists: " + split[0]);
|
if (commands.containsKey(command)) {
|
||||||
commands.get(split[0]).called(event, split[1]);
|
System.out.println("[CHandler] command exists: " + command);
|
||||||
|
commands.get(command).called(event, split[1]);
|
||||||
|
} else if (hiddenCommands.containsKey(command)) {
|
||||||
|
System.out.println("[CHandler] hidden command exists: " + command);
|
||||||
|
hiddenCommands.get(command).called(event, split[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int commandAmount() {
|
||||||
|
return commands.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EmbedBuilder getHelpList(Event event) {
|
||||||
|
EmbedBuilder builder = Config.getDefaultEmbed(event);
|
||||||
|
builder.setTitle("Killua help");
|
||||||
|
for (Command s : commands.values()) {
|
||||||
|
builder.addField(s.getName(), s.getDescription(), false);
|
||||||
|
}
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageEmbed[] getHelpLists(Event event) {
|
||||||
|
|
||||||
|
int length = commands.size();
|
||||||
|
int pages = length / MAX_PAGE_LENGTH + 1;
|
||||||
|
EmbedBuilder[] builders = new EmbedBuilder[pages];
|
||||||
|
|
||||||
|
|
||||||
|
int i = 0, j = 0;
|
||||||
|
EmbedBuilder builder = null;
|
||||||
|
for (Command value : commands.values()) {
|
||||||
|
if (i % MAX_PAGE_LENGTH == 0) {
|
||||||
|
builder = Config.getDefaultEmbed(event);
|
||||||
|
builder.setTitle("Killua help");
|
||||||
|
builders[j] = builder;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
builder.addField(value.getName(), value.getDescription(), false);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(Arrays.toString(builders));
|
||||||
|
MessageEmbed[] messageEmbeds = new MessageEmbed[pages];
|
||||||
|
for (i = 0; i < builders.length; i++) {
|
||||||
|
messageEmbeds[i] = builders[i].build();
|
||||||
|
}
|
||||||
|
return messageEmbeds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageEmbed getCommandHelp(Event event, String command) {
|
||||||
|
Command cmd = commands.get(command);
|
||||||
|
if (cmd != null) {
|
||||||
|
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
||||||
|
.setTitle("Killua help: " + cmd.getName())
|
||||||
|
.addField("Name", cmd.getName(), true)
|
||||||
|
.addField("Description", cmd.getDescription(), true)
|
||||||
|
.addField("Example usage", "`" + cmd.getExampleUsage() + "`", true);
|
||||||
|
|
||||||
|
if (!cmd.getArguments().equals("")) {
|
||||||
|
builder.addField("Arguments", "`" + cmd.getArguments() + "`", true);
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,15 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
public class EvalCommand extends Command {
|
public class EvalCommand extends Command {
|
||||||
public EvalCommand() {
|
public EvalCommand() {
|
||||||
super("eval");
|
super("eval", "no", "", "<command>", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(MessageReceivedEvent event, String args) {
|
||||||
if(args.startsWith("event.getJDA().getToken()")){
|
if(args.startsWith("event.getJDA().getToken()")){
|
||||||
reply(event, "ODAxDKE1MjU0UDOzNzk4ODI1.YAaYOg.u.MEQ_2bzQkVVZ5y1J5Q23Se5CU");
|
reply(event, "ODAxDKE1MjU0UDOzNzk4ODI1.YAaYOg.u.MEQ_2bzQkVVZ5y1J5Q23Se5CU");
|
||||||
|
} else {
|
||||||
|
reply(event, "No arguments provided.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,33 @@
|
||||||
package com.github.nilstrieb.commands.info;
|
package com.github.nilstrieb.commands.info;
|
||||||
|
|
||||||
import com.github.nilstrieb.commands.handler.Command;
|
import com.github.nilstrieb.commands.handler.Command;
|
||||||
|
import com.github.nilstrieb.commands.handler.CommandHandler;
|
||||||
|
import com.github.nilstrieb.util.MultiPageEmbed;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class HelpCommand extends Command {
|
public class HelpCommand extends Command {
|
||||||
public HelpCommand() {
|
public HelpCommand() {
|
||||||
super("help");
|
super("help", "Shows this message", "help invite", "(command name)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(MessageReceivedEvent event, String args) {
|
||||||
reply(event, "hallo");
|
if(args.length() == 0) {
|
||||||
|
if (CommandHandler.commandAmount() > CommandHandler.MAX_PAGE_LENGTH) {
|
||||||
|
reply(event, CommandHandler.getHelpLists(event));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
reply(event, CommandHandler.getHelpList(event).build());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MessageEmbed help = CommandHandler.getCommandHelp(event, args.split(" ")[0]);
|
||||||
|
if (help != null) {
|
||||||
|
reply(event, help);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,32 +3,28 @@ package com.github.nilstrieb.commands.info;
|
||||||
import com.github.nilstrieb.cofig.Config;
|
import com.github.nilstrieb.cofig.Config;
|
||||||
import com.github.nilstrieb.commands.handler.Command;
|
import com.github.nilstrieb.commands.handler.Command;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
|
||||||
import net.dv8tion.jda.api.entities.User;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class InviteCommand extends Command {
|
public class InviteCommand extends Command {
|
||||||
private static final String INVITE_LINK =
|
private static final String INVITE_LINK =
|
||||||
"(https://discord.com/api/oauth2/authorize?client_id=801015254023798825&permissions=8&scope=bot)";
|
"(https://discord.com/api/oauth2/authorize?client_id=801015254023798825&permissions=8&scope=bot)";
|
||||||
|
|
||||||
public InviteCommand() {
|
public InviteCommand() {
|
||||||
super("invite");
|
super("invite", "Get the invite link for this bot");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(MessageReceivedEvent event, String args) {
|
||||||
|
|
||||||
User nils = event.getJDA().getUserById(Config.NILS_ID);
|
event.getJDA().retrieveUserById(Config.NILS_ID).queue(nils -> {
|
||||||
Objects.requireNonNull(nils, "user nils not found");
|
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
||||||
|
.setTitle("Invite Killua to your server!")
|
||||||
|
.addField("Invite link", "[Invite]" + INVITE_LINK, true)
|
||||||
|
.setFooter("This bot was made by " + nils.getAsTag(), nils.getAvatarUrl());
|
||||||
|
reply(event, builder.build());
|
||||||
|
});
|
||||||
|
|
||||||
EmbedBuilder builder = Config.getDefaultEmbed(event);
|
|
||||||
builder.setTitle("Invite Killua to your server!")
|
|
||||||
.addField("Invite Link", "[Invite]" + INVITE_LINK, true)
|
|
||||||
.setFooter("This bot was made by " + nils.getAsTag());
|
|
||||||
|
|
||||||
reply(event, builder.build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,33 @@
|
||||||
package com.github.nilstrieb.commands.info;
|
package com.github.nilstrieb.commands.info;
|
||||||
|
|
||||||
|
import com.github.nilstrieb.cofig.Config;
|
||||||
import com.github.nilstrieb.commands.handler.Command;
|
import com.github.nilstrieb.commands.handler.Command;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
|
|
||||||
public class ToukaCommand extends Command {
|
public class ToukaCommand extends Command {
|
||||||
|
|
||||||
private static final String TOUKA_INVITE =
|
private static final String TOUKA_INVITE =
|
||||||
"(https://discord.com/channels/799696420386504795/799721568259145750/801075666862211092)";
|
"(https://discord.com/oauth2/authorize?client_id=783720725848129566&permissions=8192&scope=bot)";
|
||||||
|
|
||||||
public ToukaCommand() {
|
public ToukaCommand() {
|
||||||
super("touka");
|
super("touka", "Get the invite link for the Touka bot");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(MessageReceivedEvent event, String args) {
|
||||||
EmbedBuilder builder = new EmbedBuilder();
|
event.getJDA().retrieveUserById(265849018662387712L).queue(yuki -> {
|
||||||
builder.setAuthor("Invite the Touka bot")
|
event.getJDA().retrieveUserById(783720725848129566L).queue(touka -> {
|
||||||
.setAuthor("The Touka bot was made by angelsflyinhell")
|
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
||||||
.addField("", "[Invite]" + TOUKA_INVITE, false);
|
.setTitle("Invite the Touka bot")
|
||||||
event.getTextChannel().sendMessage(builder.build()).queue();
|
.setFooter("The Touka bot was made by " + yuki.getAsTag(), yuki.getAvatarUrl())
|
||||||
|
.setThumbnail(touka.getAvatarUrl())
|
||||||
|
.addField("Invite link", "[Invite]" + TOUKA_INVITE, false);
|
||||||
|
event.getTextChannel().sendMessage(builder.build()).queue();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,19 @@ import net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ReactionEventListener extends ListenerAdapter {
|
public class ReactionEventListener extends ListenerAdapter {
|
||||||
@Override
|
@Override
|
||||||
public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) {
|
public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) {
|
||||||
if (!event.getUser().isBot()) {
|
if (!Objects.requireNonNull(event.getUser(), "message author is null").isBot()) {
|
||||||
ReactionEventManager.onReactionAdd(event);
|
ReactionEventManager.onReactionAdd(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessageReactionRemove(@NotNull MessageReactionRemoveEvent event) {
|
public void onMessageReactionRemove(@NotNull MessageReactionRemoveEvent event) {
|
||||||
if (!event.getUser().isBot()) {
|
if (!Objects.requireNonNull(event.getUser(), "message author is null").isBot()) {
|
||||||
ReactionEventManager.onReactionRemove(event);
|
ReactionEventManager.onReactionRemove(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,6 @@ public class StartUpListener extends ListenerAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReady(@NotNull ReadyEvent event) {
|
public void onReady(@NotNull ReadyEvent event) {
|
||||||
System.out.println("started");
|
System.out.println("[Startup] Killua started");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import java.util.Random;
|
||||||
|
|
||||||
public class KilluaQuotes {
|
public class KilluaQuotes {
|
||||||
|
|
||||||
private static Random random = new Random();
|
private static final Random random = new Random();
|
||||||
private static final String[] quotes = {
|
private static final String[] quotes = {
|
||||||
"When I say it doesn't hurt me, that means I can bear it.",
|
"When I say it doesn't hurt me, that means I can bear it.",
|
||||||
"Gon, you are light itself. Sometimes you're too bright and I can't look at you... But can I still stay by your side?",
|
"Gon, you are light itself. Sometimes you're too bright and I can't look at you... But can I still stay by your side?",
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package com.github.nilstrieb.util;
|
||||||
|
|
||||||
import com.github.nilstrieb.reactions.ReactionEventManager;
|
import com.github.nilstrieb.reactions.ReactionEventManager;
|
||||||
import com.github.nilstrieb.reactions.ReactionListener;
|
import com.github.nilstrieb.reactions.ReactionListener;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
||||||
|
|
@ -20,19 +19,16 @@ public class MultiPageEmbed implements ReactionListener {
|
||||||
private final String prevReaction;
|
private final String prevReaction;
|
||||||
private final String nextReaction;
|
private final String nextReaction;
|
||||||
|
|
||||||
public MultiPageEmbed(Message message, EmbedBuilder... pages) {
|
public MultiPageEmbed(Message message, MessageEmbed... pages) {
|
||||||
this(message, PREVIOUS_PAGE_DEFAULT_REACTION, NEXT_PAGE_DEFAULT_REACTION, pages);
|
this(message, PREVIOUS_PAGE_DEFAULT_REACTION, NEXT_PAGE_DEFAULT_REACTION, pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiPageEmbed(Message message, String prevReaction, String nextReaction, EmbedBuilder... builders) {
|
public MultiPageEmbed(Message message, String prevReaction, String nextReaction, MessageEmbed... pages) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.prevReaction = prevReaction;
|
this.prevReaction = prevReaction;
|
||||||
this.nextReaction = nextReaction;
|
this.nextReaction = nextReaction;
|
||||||
|
|
||||||
pages = new MessageEmbed[builders.length];
|
this.pages = pages;
|
||||||
for (int i = 0; i < pages.length; i++) {
|
|
||||||
pages[i] = builders[i].build();
|
|
||||||
}
|
|
||||||
currentState = 0;
|
currentState = 0;
|
||||||
|
|
||||||
message.addReaction(prevReaction).queue();
|
message.addReaction(prevReaction).queue();
|
||||||
|
|
@ -45,14 +41,18 @@ public class MultiPageEmbed implements ReactionListener {
|
||||||
public void onReactionAdded(MessageReactionAddEvent event) {
|
public void onReactionAdded(MessageReactionAddEvent event) {
|
||||||
String name = event.getReaction().getReactionEmote().getName();
|
String name = event.getReaction().getReactionEmote().getName();
|
||||||
if (name.equals(nextReaction)) {
|
if (name.equals(nextReaction)) {
|
||||||
if(currentState + 1 < pages.length){
|
if (currentState + 1 < pages.length) {
|
||||||
currentState++;
|
currentState++;
|
||||||
message.editMessage(pages[currentState]).queue();
|
if (!pages[currentState].isEmpty()) {
|
||||||
|
message.editMessage(pages[currentState]).queue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (name.equals(prevReaction)) {
|
} else if (name.equals(prevReaction)) {
|
||||||
if(currentState > 0){
|
if (currentState > 0) {
|
||||||
currentState--;
|
currentState--;
|
||||||
message.editMessage(pages[currentState]).queue();
|
if (!pages[currentState].isEmpty()) {
|
||||||
|
message.editMessage(pages[currentState]).queue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Objects.requireNonNull(event.getUser(), "[MultiPageEmbed] reaction user was null");
|
Objects.requireNonNull(event.getUser(), "[MultiPageEmbed] reaction user was null");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue