feat: updated JDACommand package

This commit is contained in:
limited_dev 2022-11-24 13:20:42 +01:00
parent 61e71e4dc4
commit dfcf2fac3c
17 changed files with 80 additions and 41 deletions

View file

@ -5,8 +5,11 @@ plugins {
} }
group = "de.limited_dev" group = "de.limited_dev"
version = "v1.5.3"
version = "v1.5.4-build1"
var splatoonPatchBased = "1.2.1" var splatoonPatchBased = "1.2.1"
var jdaVersion = "5.0.0-alpha.20"
repositories { repositories {
mavenCentral() mavenCentral()
@ -14,7 +17,7 @@ repositories {
} }
dependencies { dependencies {
implementation("net.dv8tion:JDA:5.0.0-alpha.20") implementation("net.dv8tion:JDA:$jdaVersion")
implementation("org.slf4j:slf4j-api:2.0.3") implementation("org.slf4j:slf4j-api:2.0.3")
implementation("org.slf4j:slf4j-simple:2.0.3") implementation("org.slf4j:slf4j-simple:2.0.3")
} }
@ -43,7 +46,7 @@ tasks {
withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> { withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
dependencies { dependencies {
include(dependency("net.dv8tion:JDA:5.0.0-alpha.20")) include(dependency("net.dv8tion:JDA:$jdaVersion"))
include(dependency("org.slf4j:slf4j-api:2.0.3")) include(dependency("org.slf4j:slf4j-api:2.0.3"))
include(dependency("org.slf4j:slf4j-simple:2.0.3")) include(dependency("org.slf4j:slf4j-simple:2.0.3"))
} }
@ -59,7 +62,8 @@ tasks {
filteringCharset = "UTF-8" filteringCharset = "UTF-8"
val props = mapOf( val props = mapOf(
"version" to version, "version" to version,
"splatoonPatchBased" to splatoonPatchBased "splatoonPatchBased" to splatoonPatchBased,
"jdaVersion" to jdaVersion
) )
inputs.properties(props) inputs.properties(props)
from(templateSource) from(templateSource)

View file

@ -7,18 +7,25 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class JDACommand { public class JDACommand {
private final String name; private final String name;
private final String description;
protected final Logger lgr = Main.getLgr(); protected final Logger lgr = Main.getLgr();
public JDACommand(String name) {
public JDACommand(String name, String description) {
this.name = name; this.name = name;
this.description = description;
lgr.info("Created jda command " + name); lgr.info("Created jda command " + name);
} }
public void onSlashCommand(SlashCommandInteractionEvent event){ public void onSlashCommand(SlashCommandInteractionEvent event) {
} }
public String getName() { public String getName() {
return name.toLowerCase(); return name.toLowerCase();
} }
public String getDescription() {
return description;
}
} }

View file

@ -2,8 +2,8 @@ package de.limited_dev.lil_judd.commands.jdacommands.components;
import de.limited_dev.lil_judd.commands.jdacommands.management.RemoveFeatureCommand; import de.limited_dev.lil_judd.commands.jdacommands.management.RemoveFeatureCommand;
import de.limited_dev.lil_judd.commands.jdacommands.management.SetupFeatureCommand; import de.limited_dev.lil_judd.commands.jdacommands.management.SetupFeatureCommand;
import de.limited_dev.lil_judd.commands.jdacommands.util.HelpCommand;
import de.limited_dev.lil_judd.commands.jdacommands.util.InfoCommand; import de.limited_dev.lil_judd.commands.jdacommands.util.InfoCommand;
import de.limited_dev.lil_judd.commands.jdacommands.util.PingCommand;
import de.limited_dev.lil_judd.commands.jdacommands.util.TranslateMapCommand; import de.limited_dev.lil_judd.commands.jdacommands.util.TranslateMapCommand;
import de.limited_dev.lil_judd.commands.jdacommands.weapons.RandomWeaponCommand; import de.limited_dev.lil_judd.commands.jdacommands.weapons.RandomWeaponCommand;
import de.limited_dev.lil_judd.commands.jdacommands.weapons.WeaponInfoCommand; import de.limited_dev.lil_judd.commands.jdacommands.weapons.WeaponInfoCommand;
@ -20,13 +20,13 @@ public class JDACommandManager {
//commands.add(new EndScrimCommand()); //commands.add(new EndScrimCommand());
//commands.add(new MessageScrimCommand()); //commands.add(new MessageScrimCommand());
//commands.add(new ScrimInfoCommand()); //commands.add(new ScrimInfoCommand());
commands.add(new PingCommand());
commands.add(new InfoCommand()); commands.add(new InfoCommand());
commands.add(new SetupFeatureCommand()); commands.add(new SetupFeatureCommand());
commands.add(new RemoveFeatureCommand()); commands.add(new RemoveFeatureCommand());
commands.add(new TranslateMapCommand()); commands.add(new TranslateMapCommand());
commands.add(new WeaponInfoCommand()); commands.add(new WeaponInfoCommand());
commands.add(new RandomWeaponCommand()); commands.add(new RandomWeaponCommand());
commands.add(new HelpCommand());
} }
public static List<JDACommand> getCommands() { public static List<JDACommand> getCommands() {

View file

@ -8,7 +8,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class RemoveFeatureCommand extends JDACommand { public class RemoveFeatureCommand extends JDACommand {
public RemoveFeatureCommand() { public RemoveFeatureCommand() {
super("remove"); super("remove", "Remove a feature");
} }
@Override @Override

View file

@ -8,7 +8,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class SetupFeatureCommand extends JDACommand { public class SetupFeatureCommand extends JDACommand {
public SetupFeatureCommand() { public SetupFeatureCommand() {
super("setup"); super("setup", "Setup a feature");
} }
@Override @Override

View file

@ -9,7 +9,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class EndScrimCommand extends JDACommand { public class EndScrimCommand extends JDACommand {
public EndScrimCommand() { public EndScrimCommand() {
super("endscrim"); super("endscrim", "");
} }
@Override @Override

View file

@ -9,7 +9,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class MessageScrimCommand extends JDACommand { public class MessageScrimCommand extends JDACommand {
public MessageScrimCommand() { public MessageScrimCommand() {
super("msgscrim"); super("msgscrim", "");
} }
@Override @Override

View file

@ -7,7 +7,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class ScrimInfoCommand extends JDACommand { public class ScrimInfoCommand extends JDACommand {
public ScrimInfoCommand() { public ScrimInfoCommand() {
super("scriminfo"); super("scriminfo", "");
} }
@Override @Override

View file

@ -12,7 +12,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class SearchScrimCommand extends JDACommand { public class SearchScrimCommand extends JDACommand {
public SearchScrimCommand() { public SearchScrimCommand() {
super("searchscrim"); super("searchscrim", "");
} }
@Override @Override

View file

@ -0,0 +1,43 @@
package de.limited_dev.lil_judd.commands.jdacommands.util;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommandManager;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import java.awt.*;
import java.util.HashMap;
import java.util.concurrent.CopyOnWriteArrayList;
public class HelpCommand extends JDACommand {
public HelpCommand() {
super("help", "Shows all commands & their descriptions");
}
@Override
public void onSlashCommand(SlashCommandInteractionEvent event) {
HashMap<String, String[]> values = new HashMap<>();
CopyOnWriteArrayList<String> arguments = new CopyOnWriteArrayList<>();
CopyOnWriteArrayList<String> disc = new CopyOnWriteArrayList<>();
for (JDACommand c : JDACommandManager.getCommands()) {
String commandArgs = c.getName();
arguments.add(commandArgs);
disc.add(c.getDescription().isEmpty() ? "No description" : c.getDescription());
}
String[] argumentsArray = new String[arguments.size()];
for (int i = 0; i < arguments.size(); i++) {
argumentsArray[i] = arguments.get(i);
}
values.put("Command", argumentsArray);
String[] Descriptions = new String[disc.size()];
for (int i = 0; i < disc.size(); i++) {
Descriptions[i] = disc.get(i);
}
values.put("Description", Descriptions);
EmbeddedMessageHelper.sendWithTable(event, "Uses / commands", "Commands", Color.MAGENTA,
null, "List of avalible commands", new String[]{"Command", "Description"}, values, true);
}
}

View file

@ -13,14 +13,14 @@ import java.util.HashMap;
public class InfoCommand extends JDACommand { public class InfoCommand extends JDACommand {
public InfoCommand() { public InfoCommand() {
super("info"); super("info", "Shows Info about the bot");
} }
@Override @Override
public void onSlashCommand(SlashCommandInteractionEvent event) { public void onSlashCommand(SlashCommandInteractionEvent event) {
HashMap<String, String[]> hm = new HashMap<>(); HashMap<String, String[]> hm = new HashMap<>();
hm.put("Information", new String[]{"Version", "Ping", "Uptime", "RAM", "# Commands"}); hm.put("Information", new String[]{"Version", "JDA version", "Ping", "Uptime", "RAM", "# Commands"});
hm.put("Value", new String[]{BuildConstants.botVersion, Main.getJda().getGatewayPing() + "ms", TimeUtil.getTimeFormatedShortend(Main.getUptime()), hm.put("Value", new String[]{BuildConstants.botVersion, BuildConstants.jdaVersion, Main.getJda().getGatewayPing() + "ms", TimeUtil.getTimeFormatedShortend(Main.getUptime()),
(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "MB / " + (Runtime.getRuntime().maxMemory() - (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())) / 1024 / 1024 + "MB; " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) * 100L / Runtime.getRuntime().maxMemory() + "%" (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "MB / " + (Runtime.getRuntime().maxMemory() - (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())) / 1024 / 1024 + "MB; " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) * 100L / Runtime.getRuntime().maxMemory() + "%"
, JDACommandManager.getCommands().size() + ""}); , JDACommandManager.getCommands().size() + ""});
EmbeddedMessageHelper.sendWithTable(event, Main.getJda().getSelfUser().getName() + " " + BuildConstants.botVersion, "Bot information", Color.YELLOW, Main.getJda().getSelfUser().getAvatarUrl(), "General information about the bot", EmbeddedMessageHelper.sendWithTable(event, Main.getJda().getSelfUser().getName() + " " + BuildConstants.botVersion, "Bot information", Color.YELLOW, Main.getJda().getSelfUser().getAvatarUrl(), "General information about the bot",

View file

@ -1,18 +0,0 @@
package de.limited_dev.lil_judd.commands.jdacommands.util;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
public class PingCommand extends JDACommand {
public PingCommand() {
super("ping");
}
@Override
public void onSlashCommand(SlashCommandInteractionEvent event) {
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Connection speed", "My connection to base takes **" + Main.getJda().getGatewayPing() + "ms**", null);
}
}

View file

@ -8,7 +8,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class TranslateMapCommand extends JDACommand { public class TranslateMapCommand extends JDACommand {
public TranslateMapCommand() { public TranslateMapCommand() {
super("translatemap"); super("mapinfo", "Show map information");
} }
@Override @Override

View file

@ -8,7 +8,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class RandomWeaponCommand extends JDACommand { public class RandomWeaponCommand extends JDACommand {
public RandomWeaponCommand() { public RandomWeaponCommand() {
super("randomweapon"); super("randomweapon", "Get a random weapon");
} }
@Override @Override

View file

@ -12,7 +12,7 @@ import java.util.HashMap;
public class WeaponInfoCommand extends JDACommand { public class WeaponInfoCommand extends JDACommand {
public WeaponInfoCommand() { public WeaponInfoCommand() {
super("weaponinfo"); super("weaponinfo", "Get infos about a weapon");
} }
@Override @Override

View file

@ -10,7 +10,7 @@ public class SlashCommandRegister {
public static void registerCommands(){ public static void registerCommands(){
Main.getJda().updateCommands().addCommands( Main.getJda().updateCommands().addCommands(
Commands.slash("info", "Shows Info about me") Commands.slash("info", "Shows Info about the bot")
.addOptions(new OptionData(OptionType.BOOLEAN, "mobileformatting", "Format the reply for mobile devices")), .addOptions(new OptionData(OptionType.BOOLEAN, "mobileformatting", "Format the reply for mobile devices")),
Commands.slash("setup", "Setup a feature") Commands.slash("setup", "Setup a feature")
.addOptions( .addOptions(
@ -33,13 +33,15 @@ public class SlashCommandRegister {
.addOptions(new OptionData(OptionType.STRING, "message", "Message content", true)), .addOptions(new OptionData(OptionType.STRING, "message", "Message content", true)),
Commands.slash("scriminfo", "Show info about the scrim system."), Commands.slash("scriminfo", "Show info about the scrim system."),
*/ */
Commands.slash("translatemap", "Translate a Map from English to German or vice versa") Commands.slash("mapinfo", "Show map information")
.addOptions(new OptionData(OptionType.STRING, "map", "Map Name", true)), .addOptions(new OptionData(OptionType.STRING, "map", "Map Name", true)),
Commands.slash("weaponinfo", "Get infos about a weapon") Commands.slash("weaponinfo", "Get infos about a weapon")
.addOptions(new OptionData(OptionType.STRING, "name", "Weapon name in English or German", true)) .addOptions(new OptionData(OptionType.STRING, "name", "Weapon name in English or German", true))
.addOptions(new OptionData(OptionType.BOOLEAN, "mobileformatting", "Format the reply for mobile devices")), .addOptions(new OptionData(OptionType.BOOLEAN, "mobileformatting", "Format the reply for mobile devices")),
Commands.slash("randomweapon", "Get a random weapon") Commands.slash("randomweapon", "Get a random weapon")
.addOptions(new OptionData(OptionType.BOOLEAN, "mobileformatting", "Format the reply for mobile devices"))//, .addOptions(new OptionData(OptionType.BOOLEAN, "mobileformatting", "Format the reply for mobile devices")),
Commands.slash("help", "Shows all commands & their descriptions")
.addOptions(new OptionData(OptionType.BOOLEAN, "mobileformatting", "Format the reply for mobile devices"))
//Commands.context(Command.Type.USER, "Get user avatar"), //Commands.context(Command.Type.USER, "Get user avatar"),
//Commands.message("Get message ID") //Commands.message("Get message ID")
).queue(); ).queue();

View file

@ -3,4 +3,5 @@ package de.limited_dev.lil_judd.build;
public class BuildConstants{ public class BuildConstants{
public static String botVersion = "${version}"; public static String botVersion = "${version}";
public static String splatoonPatchVersion = "${splatoonPatchBased}"; public static String splatoonPatchVersion = "${splatoonPatchBased}";
public static String jdaVersion = "${jdaVersion}";
} }