more commands

This commit is contained in:
nora 2021-01-19 14:54:35 +01:00
parent 14e1e69cbb
commit 44ffe1be8e
8 changed files with 77 additions and 5 deletions

View file

@ -1,5 +1,9 @@
package com.github.nilstrieb.cofig;
import java.awt.*;
public class Config {
public static final String PREFIX = "kil ";
public static final String NILS_ID = "414755070161453076";
public static final Color DEFAULT_COLOR = new Color(229, 201, 255);
}

View file

@ -0,0 +1,15 @@
package com.github.nilstrieb.commands.fun;
import com.github.nilstrieb.commands.handler.Command;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class SayCommand extends Command {
public SayCommand(){
super("say");
}
@Override
public void called(MessageReceivedEvent event, String args) {
reply(event, args);
deleteMsg(event);
}
}

View file

@ -2,8 +2,10 @@ package com.github.nilstrieb.commands.handler;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public abstract class Command {
import java.util.Timer;
import java.util.TimerTask;
public abstract class Command {
private final String name;
private final CommandParser parser = CommandParser.getInstance();
@ -17,4 +19,19 @@ public abstract class Command {
protected void reply(MessageReceivedEvent event, String message){
event.getTextChannel().sendMessage(message).queue();
}
protected void deleteMsg(MessageReceivedEvent event, long delay){
new Timer().schedule(
new TimerTask() {
@Override
public void run() {
event.getMessage().delete().queue();
}
}, delay
);
}
protected void deleteMsg(MessageReceivedEvent event){
event.getMessage().delete().queue();
}
}

View file

@ -9,7 +9,7 @@ import java.util.Map;
public class CommandHandler {
private static Map<String, Command> commands = new HashMap<>();
private static CommandParser parser = new CommandParser();
private static CommandParser parser = CommandParser.getInstance();
public static void addCommand(String key, Command cmd) {
commands.put(key, cmd);

View file

@ -6,17 +6,23 @@ public class CommandParser {
private static final CommandParser parser = new CommandParser();
private CommandParser() {}
public static CommandParser getInstance() {
return parser;
}
public static String[] splitArgs(String args){
return args.split(" ");
}
public String[] splitOffCommandName(String contentRaw) {
String[] returns = new String[2];
String beheaded = contentRaw.substring(Config.PREFIX.length());
String[] split = beheaded.split(" ");
returns[0] = split[0];
String prefixRemoved = beheaded.substring(split[0].length() + 1);
returns[1] = prefixRemoved;
String commandRemoved = beheaded.replaceAll(split[0] + " ?(.*)", "$1");
returns[1] = commandRemoved;
return returns;
}
}

View file

@ -10,7 +10,7 @@ public class EvalCommand extends Command {
@Override
public void called(MessageReceivedEvent event, String args) {
if(args.matches(".*event.getJDA\\(\\).getToken\\(\\).*")){
if(args.startsWith("event.getJDA().getToken()")){
reply(event, "ODAxDKE1MjU0UDOzNzk4ODI1.YAaYOg.u.MEQ_2bzQkVVZ5y1J5Q23Se5CU");
}
}

View file

@ -0,0 +1,24 @@
package com.github.nilstrieb.commands.info;
import com.github.nilstrieb.commands.handler.Command;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class ToukaCommand extends Command {
private static final String TOUKA_INVITE =
"(https://discord.com/channels/799696420386504795/799721568259145750/801075666862211092)";
public ToukaCommand() {
super("touka");
}
@Override
public void called(MessageReceivedEvent event, String args) {
EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor("Invite the Touka bot")
.setAuthor("The Touka bot was made by angelsflyinhell")
.addField("", "[Invite]" + TOUKA_INVITE, false);
event.getTextChannel().sendMessage(builder.build()).queue();
}
}

View file

@ -1,8 +1,11 @@
package com.github.nilstrieb.core;
import com.github.nilstrieb.cofig.Secrets;
import com.github.nilstrieb.commands.fun.SayCommand;
import com.github.nilstrieb.commands.info.InviteCommand;
import com.github.nilstrieb.commands.info.EvalCommand;
import com.github.nilstrieb.commands.info.HelpCommand;
import com.github.nilstrieb.commands.info.ToukaCommand;
import com.github.nilstrieb.listener.CommandListener;
import com.github.nilstrieb.listener.StartUpListener;
import net.dv8tion.jda.api.JDA;
@ -28,5 +31,8 @@ public class Main {
private static void setupCommands() {
new HelpCommand();
new EvalCommand();
new ToukaCommand();
new SayCommand();
new InviteCommand();
}
}