feat: added ResendTimePlannerMessageCommand to ConsoleCommand, added PollCommand

fix: fixed an issue with loading guilds with TimePlanner Channels
chore: did some formatting, bumped version number
This commit is contained in:
limited_dev 2022-11-07 14:52:53 +01:00
parent 116df6e630
commit ecea872b25
36 changed files with 498 additions and 99 deletions

View file

@ -5,7 +5,7 @@ plugins {
}
group = "de.limited_dev"
version = "v1.4.0"
version = "v1.5.2"
var splatoonPatchBased = "1.2.1"
repositories {

View file

@ -1,12 +1,15 @@
package de.limited_dev.lil_judd;
import de.limited_dev.lil_judd.build.BuildConstants;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommandManager;
import de.limited_dev.lil_judd.features.weapons.WeaponManager;
import de.limited_dev.lil_judd.jdacommands.components.JDACommandManager;
import de.limited_dev.lil_judd.commands.consolecommand.component.ConsoleCommandManager;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommandManager;
import de.limited_dev.lil_judd.features.maps.MapManager;
import de.limited_dev.lil_judd.features.planner.TimePlanner;
import de.limited_dev.lil_judd.features.storage.GuildTimePlannerStorage;
import de.limited_dev.lil_judd.features.weapons.WeaponManager;
import de.limited_dev.lil_judd.interactions.messagecontext.components.MessageContextInteractionManager;
import de.limited_dev.lil_judd.interactions.usercontext.components.UserContextInteractionManager;
import de.limited_dev.lil_judd.listeners.ContextInteractionListener;
import de.limited_dev.lil_judd.listeners.GuildStateListener;
import de.limited_dev.lil_judd.listeners.ReadyListener;
import de.limited_dev.lil_judd.listeners.SlashCommandInteractionListener;
@ -24,6 +27,7 @@ public class Main {
private static Logger lgr = new Logger();
private static final TokenManager tokenManager = TokenManager.getInstance();
private static final WeaponDataManager weaponDataManager = WeaponDataManager.getInstance();
private static final GuildTimePlannerStorage gtps = GuildTimePlannerStorage.getInstance();
private static long launchTime;
public static void main(String[] args){
@ -31,6 +35,7 @@ public class Main {
lgr.info(BuildConstants.botVersion);
launchTime = System.currentTimeMillis();
tokenManager.load();
gtps.load();
weaponDataManager.loadPatchInfo();
jda = JDABuilder.createDefault(tokenManager.getToken())
@ -41,6 +46,7 @@ public class Main {
jda.addEventListener(new ReadyListener());
jda.addEventListener(new SlashCommandInteractionListener());
jda.addEventListener(new ContextInteractionListener());
jda.addEventListener(new GuildStateListener());
try {
@ -53,6 +59,8 @@ public class Main {
WeaponManager.registerWeapons();
TimePlanner.registerMessageThread();
JDACommandManager.registerCommands();
UserContextInteractionManager.registerInteractions();
MessageContextInteractionManager.registerInteractions();
ConsoleCommandManager.registerCommands();
ConsoleCommandManager.registerListener();
}
@ -73,7 +81,11 @@ public class Main {
return launchTime;
}
public static WeaponDataManager getWeaponDataManager(){
public static WeaponDataManager getWeaponDataManager() {
return weaponDataManager;
}
public static GuildTimePlannerStorage getGtps() {
return gtps;
}
}

View file

@ -1,4 +1,4 @@
package de.limited_dev.lil_judd.consolecommand.component;
package de.limited_dev.lil_judd.commands.consolecommand.component;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.util.Logger;
@ -15,6 +15,7 @@ public class ConsoleCommand {
this.name = name;
this.description = description;
this.args = args;
lgr.info("Created console command " + name);
}
public void onCommand(String[] args){

View file

@ -1,12 +1,13 @@
package de.limited_dev.lil_judd.consolecommand.component;
package de.limited_dev.lil_judd.commands.consolecommand.component;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.consolecommand.system.BotVersionCommand;
import de.limited_dev.lil_judd.consolecommand.system.ShutdownCommand;
import de.limited_dev.lil_judd.consolecommand.util.AnnounceCommand;
import de.limited_dev.lil_judd.consolecommand.util.HelpConsoleCommand;
import de.limited_dev.lil_judd.consolecommand.util.ManualCommand;
import de.limited_dev.lil_judd.consolecommand.weapons.ReloadWeaponsCommand;
import de.limited_dev.lil_judd.commands.consolecommand.system.BotVersionCommand;
import de.limited_dev.lil_judd.commands.consolecommand.system.ShutdownCommand;
import de.limited_dev.lil_judd.commands.consolecommand.util.AnnounceCommand;
import de.limited_dev.lil_judd.commands.consolecommand.util.HelpConsoleCommand;
import de.limited_dev.lil_judd.commands.consolecommand.util.ManualCommand;
import de.limited_dev.lil_judd.commands.consolecommand.util.ResendTimePlannerMessageCommand;
import de.limited_dev.lil_judd.commands.consolecommand.weapons.ReloadWeaponsCommand;
import de.limited_dev.lil_judd.util.Logger;
import java.util.ArrayList;
@ -25,6 +26,7 @@ public class ConsoleCommandManager {
commands.add(new BotVersionCommand());
commands.add(new AnnounceCommand());
commands.add(new ReloadWeaponsCommand());
commands.add(new ResendTimePlannerMessageCommand());
}
public static void registerListener(){

View file

@ -1,7 +1,7 @@
package de.limited_dev.lil_judd.consolecommand.system;
package de.limited_dev.lil_judd.commands.consolecommand.system;
import de.limited_dev.lil_judd.build.BuildConstants;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.commands.consolecommand.component.ConsoleCommand;
public class BotVersionCommand extends ConsoleCommand {
public BotVersionCommand() {

View file

@ -1,6 +1,6 @@
package de.limited_dev.lil_judd.consolecommand.system;
package de.limited_dev.lil_judd.commands.consolecommand.system;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.commands.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.features.planner.TimePlanner;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.GuildVoiceState;
@ -24,7 +24,7 @@ public class ShutdownCommand extends ConsoleCommand {
audioManager.closeAudioConnection();
}
}
TimePlanner.schedulerFirstLesson.shutdown();
TimePlanner.schedulerService.shutdown();
jda.shutdown();
}
}

View file

@ -1,7 +1,7 @@
package de.limited_dev.lil_judd.consolecommand.util;
package de.limited_dev.lil_judd.commands.consolecommand.util;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.commands.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.entities.Guild;

View file

@ -1,7 +1,7 @@
package de.limited_dev.lil_judd.consolecommand.util;
package de.limited_dev.lil_judd.commands.consolecommand.util;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommandManager;
import de.limited_dev.lil_judd.commands.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.commands.consolecommand.component.ConsoleCommandManager;
import java.util.List;

View file

@ -1,7 +1,6 @@
package de.limited_dev.lil_judd.consolecommand.util;
package de.limited_dev.lil_judd.commands.consolecommand.util;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommandManager;
import de.limited_dev.lil_judd.commands.consolecommand.component.ConsoleCommand;
public class ManualCommand extends ConsoleCommand {
public ManualCommand() {

View file

@ -0,0 +1,105 @@
package de.limited_dev.lil_judd.commands.consolecommand.util;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.commands.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.features.planner.TimePlanner;
import de.limited_dev.lil_judd.features.storage.GuildTimePlannerStorage;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class ResendTimePlannerMessageCommand extends ConsoleCommand {
private static final GuildTimePlannerStorage gtps = Main.getGtps();
public ResendTimePlannerMessageCommand() {
super("resendplannermsg", "Resend Time Planner Message", new String[]{"guildID / all"});
}
@Override
public void onCommand(String[] args) {
if (args.length != 1) {
this.sendUsage(this.getName());
return;
}
lgr.consoleOut("Resending the msg to " + args[0]);
if (args[0].toLowerCase().equals("all")) {
for (Guild g : jda.getSelfUser().getMutualGuilds()) {
sendMessageToGuild(g);
lgr.consoleOut("Sent message to " + g.getName());
}
lgr.consoleOut("Done.");
return;
}
Guild g = jda.getGuildById(Long.parseLong(args[0]));
if (g == null) {
lgr.consoleOut("This guild does not exist.");
return;
}
sendMessageToGuild(g);
lgr.consoleOut("The message has been send to " + g.getName());
lgr.consoleOut("Done.");
}
private void sendMessageToGuild(Guild g) {
if (g == null) {
lgr.info("Guild does not exist");
return;
}
long l = g.getIdLong();
if (g.getTextChannelById(gtps.guildsWithPlanner.get(l)) == null) {
lgr.info("The channel with the id " + gtps.guildsWithPlanner.get(l) + " does not exist.");
return;
}
ZonedDateTime then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withHour(TimePlanner.hour).withMinute(TimePlanner.minute).withSecond(TimePlanner.second);
EmbeddedMessageHelper.sendSimpleOneLiner(g, gtps.guildsWithPlanner.get(l), "Timeplanning System", "Do you have time on the following Days?", null);
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
for (int i = 0; i < 7; ++i) {
if (i != 0)
then = then.plusDays(1).withHour(TimePlanner.hour).withMinute(TimePlanner.minute).withSecond(TimePlanner.second);
MessageEmbed eb = EmbeddedMessageHelper.getEmbeddedMessageAutomated(false, null, then.getDayOfWeek() + ", " + then.getDayOfMonth() + "." + then.getMonthValue() + "." + then.getYear(), null, false).build();
g.getTextChannelById(gtps.guildsWithPlanner.get(l)).sendMessageEmbeds(eb).queue(this::addReactions);
lgr.info("[" + l + ", " + gtps.guildsWithPlanner.get(l) + "]" + ": " + then.getDayOfWeek() + ", " + then.getDayOfMonth() + "." + then.getMonthValue() + "." + then.getYear());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
lgr.info("Sent to Server " + g.getName());
}
private void addReactions(Message msg) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
msg.addReaction(Emoji.fromUnicode("")).queue();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
msg.addReaction(Emoji.fromFormatted("")).queue();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
msg.addReaction(Emoji.fromFormatted("")).queue();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}

View file

@ -1,6 +1,6 @@
package de.limited_dev.lil_judd.consolecommand.weapons;
package de.limited_dev.lil_judd.commands.consolecommand.weapons;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.commands.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.features.weapons.WeaponManager;
public class ReloadWeaponsCommand extends ConsoleCommand {

View file

@ -1,4 +1,4 @@
package de.limited_dev.lil_judd.jdacommands.components;
package de.limited_dev.lil_judd.commands.jdacommands.components;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.util.Logger;
@ -11,16 +11,13 @@ public class JDACommand {
public JDACommand(String name) {
this.name = name;
lgr.info("Created jda command " + name);
}
public void onSlashCommand(SlashCommandInteractionEvent event){
}
protected void sendReply(SlashCommandInteractionEvent event, String msg){
event.reply(msg).queue();
}
public String getName() {
return name.toLowerCase();
}

View file

@ -1,10 +1,13 @@
package de.limited_dev.lil_judd.jdacommands.components;
package de.limited_dev.lil_judd.commands.jdacommands.components;
import de.limited_dev.lil_judd.jdacommands.management.RemoveFeatureCommand;
import de.limited_dev.lil_judd.jdacommands.management.SetupFeatureCommand;
import de.limited_dev.lil_judd.jdacommands.util.*;
import de.limited_dev.lil_judd.jdacommands.weapons.RandomWeaponCommand;
import de.limited_dev.lil_judd.jdacommands.weapons.WeaponInfoCommand;
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.util.InfoCommand;
import de.limited_dev.lil_judd.commands.jdacommands.util.PingCommand;
import de.limited_dev.lil_judd.commands.jdacommands.util.PollCommand;
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.WeaponInfoCommand;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@ -25,6 +28,7 @@ public class JDACommandManager {
commands.add(new TranslateMapCommand());
commands.add(new WeaponInfoCommand());
commands.add(new RandomWeaponCommand());
commands.add(new PollCommand());
}
public static List<JDACommand> getCommands() {

View file

@ -1,6 +1,6 @@
package de.limited_dev.lil_judd.jdacommands.management;
package de.limited_dev.lil_judd.commands.jdacommands.management;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.features.planner.TimePlanner;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.Permission;

View file

@ -1,6 +1,6 @@
package de.limited_dev.lil_judd.jdacommands.management;
package de.limited_dev.lil_judd.commands.jdacommands.management;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.features.planner.TimePlanner;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.Permission;
@ -13,15 +13,15 @@ public class SetupFeatureCommand extends JDACommand {
@Override
public void onSlashCommand(SlashCommandInteractionEvent event) {
if(!event.getGuild().getMemberById(event.getUser().getIdLong()).hasPermission(Permission.ADMINISTRATOR)){
if (!event.getMember().hasPermission(Permission.ADMINISTRATOR)) {
EmbeddedMessageHelper.sendSimpleOneLiner(event, "403: Forbidden", "You are not allowed to run this command.", null);
return;
}
if(event.getOption("feature").getAsString().equals("timefinder")){
if (event.getOption("feature").getAsString().equals("timefinder")) {
TimePlanner.getGtps().guildsWithPlanner.put(event.getGuild().getIdLong(), event.getOption("channel").getAsChannel().getIdLong());
TimePlanner.getGtps().save();
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Channel has been selected for the ritual",
"The Channel has been added. You may now recieve notifications", null);
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Feature added to channel.",
"\"" + event.getOption("channel").getAsChannel().getName() + "\" has been added to send time notifications.", null);
}
}
}

View file

@ -1,6 +1,6 @@
package de.limited_dev.lil_judd.jdacommands.scrim;
package de.limited_dev.lil_judd.commands.jdacommands.scrim;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.features.scrims.ScrimMaker;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.entities.Guild;

View file

@ -1,6 +1,6 @@
package de.limited_dev.lil_judd.jdacommands.scrim;
package de.limited_dev.lil_judd.commands.jdacommands.scrim;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.features.scrims.ScrimMaker;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.entities.Guild;

View file

@ -1,6 +1,6 @@
package de.limited_dev.lil_judd.jdacommands.scrim;
package de.limited_dev.lil_judd.commands.jdacommands.scrim;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.features.scrims.ScrimMaker;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;

View file

@ -1,6 +1,6 @@
package de.limited_dev.lil_judd.jdacommands.scrim;
package de.limited_dev.lil_judd.commands.jdacommands.scrim;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.features.scrims.ScrimMaker;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.entities.Guild;

View file

@ -1,9 +1,9 @@
package de.limited_dev.lil_judd.jdacommands.util;
package de.limited_dev.lil_judd.commands.jdacommands.util;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.build.BuildConstants;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.jdacommands.components.JDACommandManager;
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 de.limited_dev.lil_judd.util.TimeUtil;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;

View file

@ -1,8 +1,8 @@
package de.limited_dev.lil_judd.jdacommands.util;
package de.limited_dev.lil_judd.commands.jdacommands.util;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
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;

View file

@ -0,0 +1,93 @@
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.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class PollCommand extends JDACommand {
public PollCommand() {
super("poll");
}
@Override
public void onSlashCommand(SlashCommandInteractionEvent event) {
Guild g = event.getGuild();
String caption = event.getOption("caption").getAsString();
List<String> voteOptions = new ArrayList<>();
String content = "";
int index = 0;
for (String s : optionNames) {
OptionMapping o = event.getOption(s);
if (o == null)
continue;
voteOptions.add(o.getAsString());
content += emojiToSelection2.get(index + 1) + " - " + o.getAsString() + "\n";
++index;
}
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Poll was created", "You can view it below.");
MessageEmbed eb = EmbeddedMessageHelper.getEmbeddedMessageAutomated(true, "Poll", caption + "\n\n" + content, null, true).build();
event.getChannel().sendMessageEmbeds(eb).queue(message -> addReactions(message, voteOptions));
}
private void addReactions(Message msg, List<String> voteOption) {
Thread thr = new Thread() {
@Override
public void run() {
for (int i = 0; i < voteOption.size(); ++i) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
msg.addReaction(Emoji.fromUnicode(emojiToSelection1.get(i + 1))).queue();
}
Thread.currentThread().interrupt();
}
};
thr.start();
}
private static final List<String> optionNames = List.of("option1", "option2", "option3", "option4", "option5", "option6", "option7", "option8", "option9", "option10");
private static final HashMap<Integer, String> emojiToSelection1 = new HashMap<>() {{
put(1, "1");
put(2, "2");
put(3, "3");
put(4, "4");
put(5, "5");
put(6, "6");
put(7, "7");
put(8, "8");
put(9, "9");
put(10, "🔟");
}};
private static final HashMap<Integer, String> emojiToSelection2 = new HashMap<>() {{
put(1, ":one:");
put(2, ":two:");
put(3, ":three:");
put(4, ":four:");
put(5, ":five:");
put(6, ":six:");
put(7, ":seven:");
put(8, ":eight:");
put(9, ":nine:");
put(10, ":keycap_ten:");
}};
}

View file

@ -1,6 +1,6 @@
package de.limited_dev.lil_judd.jdacommands.util;
package de.limited_dev.lil_judd.commands.jdacommands.util;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.features.maps.MapManager;
import de.limited_dev.lil_judd.features.maps.components.MapData;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;

View file

@ -1,15 +1,11 @@
package de.limited_dev.lil_judd.jdacommands.weapons;
package de.limited_dev.lil_judd.commands.jdacommands.weapons;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.features.weapons.WeaponManager;
import de.limited_dev.lil_judd.features.weapons.components.WeaponKit;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import java.awt.*;
import java.util.HashMap;
public class RandomWeaponCommand extends JDACommand {
public RandomWeaponCommand() {
super("randomweapon");

View file

@ -1,14 +1,10 @@
package de.limited_dev.lil_judd.jdacommands.weapons;
package de.limited_dev.lil_judd.commands.jdacommands.weapons;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.build.BuildConstants;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.features.weapons.WeaponManager;
import de.limited_dev.lil_judd.features.weapons.components.WeaponKit;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.jdacommands.components.JDACommandManager;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import de.limited_dev.lil_judd.util.TimeUtil;
import de.limited_dev.lil_judd.util.managers.WeaponDataManager;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import java.awt.*;

View file

@ -5,37 +5,32 @@ import de.limited_dev.lil_judd.features.storage.GuildTimePlannerStorage;
import de.limited_dev.lil_judd.util.DayUtil;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import de.limited_dev.lil_judd.util.Logger;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import java.time.Duration;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class TimePlanner {
private static final GuildTimePlannerStorage gtps = GuildTimePlannerStorage.getInstance();
private static final GuildTimePlannerStorage gtps = Main.getGtps();
private static final Logger lgr = Main.getLgr();
private static final int hour = 8;
private static final int minute = 0;
private static final int second = 0;
public static ScheduledExecutorService schedulerFirstLesson;
public static final int hour = 8; // 8
public static final int minute = 0; // 0
public static final int second = 0; // 0
public static ScheduledExecutorService schedulerService;
public static GuildTimePlannerStorage getGtps() {
return gtps;
}
public static void registerMessageThread(){
public static void registerMessageThread() {
// get the current ZonedDateTime of your TimeZone
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Europe/Berlin"));
@ -59,16 +54,30 @@ public class TimePlanner {
lgr.info("Duration: " + initialDelayUntilNextNotification);
// schedules the reminder at a fixed rate of one day
ScheduledExecutorService schedulerFirstLesson = Executors.newScheduledThreadPool(1);
schedulerFirstLesson.scheduleAtFixedRate(() -> {
schedulerService = Executors.newScheduledThreadPool(1);
schedulerService.scheduleAtFixedRate(() -> {
// send a message
JDA jda = Main.getJda();
Set<Long> gs = gtps.guildsWithPlanner.keySet();
lgr.info(gs.toString());
Thread thr = new Thread(){
lgr.info("All Guilds found with time planner:");
for (Long l : gs) {
if (jda.getGuildById(l) == null) {
lgr.info("Guild with id " + l + " does not exist.");
continue;
}
lgr.info("Guild: " + jda.getGuildById(l).getName());
}
Thread thr = new Thread() {
@Override
public void run() {
for(Long l : gs) {
for (Long l : gs) {
if (jda.getGuildById(l) == null) {
continue;
}
if (jda.getGuildById(l).getTextChannelById(gtps.guildsWithPlanner.get(l)) == null) {
lgr.info("The channel with the id " + gtps.guildsWithPlanner.get(l) + " does not exist.");
continue;
}
ZonedDateTime then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withHour(hour).withMinute(minute).withSecond(second);
EmbeddedMessageHelper.sendSimpleOneLiner(jda.getGuildById(l), gtps.guildsWithPlanner.get(l), "Timeplanning System", "Do you have time on the following Days?", null);
try {
@ -76,11 +85,11 @@ public class TimePlanner {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
for(int i = 0; i < 7; ++i){
if(i != 0)
for (int i = 0; i < 7; ++i) {
if (i != 0)
then = then.plusDays(1).withHour(hour).withMinute(minute).withSecond(second);
MessageEmbed eb = EmbeddedMessageHelper.getEmbeddedMessageAutomated(false, null, then.getDayOfWeek() + ", " + then.getDayOfMonth() + "." + then.getMonthValue() + "." + then.getYear(), null, false).build();
jda.getGuildById(l).getTextChannelById(gtps.guildsWithPlanner.get(l)).sendMessageEmbeds(eb).queue(message -> addReactions(message));
jda.getGuildById(l).getTextChannelById(gtps.guildsWithPlanner.get(l)).sendMessageEmbeds(eb).queue(this::addReactions);
lgr.info(gs + ": " + then.getDayOfWeek() + ", " + then.getDayOfMonth() + "." + then.getMonthValue() + "." + then.getYear());
try {
Thread.sleep(5000);
@ -89,7 +98,7 @@ public class TimePlanner {
}
}
lgr.info("Send to Server " + jda.getGuildById(l).getName());
lgr.info("Sent to Server " + jda.getGuildById(l).getName());
}
lgr.info("Terminating Thread...");
Thread.currentThread().interrupt();

View file

@ -0,0 +1,16 @@
package de.limited_dev.lil_judd.interactions.messagecontext;
import de.limited_dev.lil_judd.interactions.messagecontext.components.MessageContext;
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
import org.jetbrains.annotations.NotNull;
public class GetMessageIDInteraction extends MessageContext {
public GetMessageIDInteraction() {
super("Get message ID");
}
@Override
public void onMessageContextInteractionEvent(@NotNull MessageContextInteractionEvent event) {
event.reply("Message ID: " + event.getTarget().getIdLong()).queue();
}
}

View file

@ -0,0 +1,26 @@
package de.limited_dev.lil_judd.interactions.messagecontext.components;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.util.Logger;
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
import org.jetbrains.annotations.NotNull;
public class MessageContext {
private final String name;
protected final Logger lgr = Main.getLgr();
public MessageContext(String name) {
this.name = name;
lgr.info("Created UserContextInteraction " + name);
}
public void onMessageContextInteractionEvent(@NotNull MessageContextInteractionEvent event) {
}
public String getName() {
return name;
}
}

View file

@ -0,0 +1,19 @@
package de.limited_dev.lil_judd.interactions.messagecontext.components;
import de.limited_dev.lil_judd.interactions.messagecontext.GetMessageIDInteraction;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class MessageContextInteractionManager {
private static List<MessageContext> interactions = new CopyOnWriteArrayList<>();
public static void registerInteractions() {
interactions.add(new GetMessageIDInteraction());
}
public static List<MessageContext> getInteractions() {
return interactions;
}
}

View file

@ -0,0 +1,17 @@
package de.limited_dev.lil_judd.interactions.usercontext;
import de.limited_dev.lil_judd.interactions.usercontext.components.UserContext;
import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent;
import org.jetbrains.annotations.NotNull;
public class GetPFPInteraction extends UserContext {
public GetPFPInteraction() {
super("Get user avatar");
}
@Override
public void onUserContextInteraction(@NotNull UserContextInteractionEvent event) {
event.reply("Avatar: " + event.getTarget().getEffectiveAvatarUrl()).queue();
}
}

View file

@ -0,0 +1,25 @@
package de.limited_dev.lil_judd.interactions.usercontext.components;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.util.Logger;
import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent;
import org.jetbrains.annotations.NotNull;
public class UserContext {
private final String name;
protected final Logger lgr = Main.getLgr();
public UserContext(String name) {
this.name = name;
lgr.info("Created UserContextInteraction " + name);
}
public void onUserContextInteraction(@NotNull UserContextInteractionEvent event) {
}
public String getName() {
return name;
}
}

View file

@ -0,0 +1,18 @@
package de.limited_dev.lil_judd.interactions.usercontext.components;
import de.limited_dev.lil_judd.interactions.usercontext.GetPFPInteraction;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class UserContextInteractionManager {
private static List<UserContext> interactions = new CopyOnWriteArrayList<>();
public static void registerInteractions() {
interactions.add(new GetPFPInteraction());
}
public static List<UserContext> getInteractions() {
return interactions;
}
}

View file

@ -0,0 +1,43 @@
package de.limited_dev.lil_judd.listeners;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.interactions.messagecontext.components.MessageContext;
import de.limited_dev.lil_judd.interactions.messagecontext.components.MessageContextInteractionManager;
import de.limited_dev.lil_judd.interactions.usercontext.components.UserContext;
import de.limited_dev.lil_judd.interactions.usercontext.components.UserContextInteractionManager;
import de.limited_dev.lil_judd.util.Logger;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
public class ContextInteractionListener extends ListenerAdapter {
private static final Logger lgr = Main.getLgr();
@Override
public void onUserContextInteraction(@NotNull UserContextInteractionEvent event) {
Member target = event.getInteraction().getTargetMember();
Member source = event.getMember();
Guild g = event.getGuild();
lgr.info("New User Interaction from " + source.getUser().getName() + " on " + target.getUser().getName() + " in " + g.getName());
for (UserContext uc : UserContextInteractionManager.getInteractions())
if (event.getName().equals(uc.getName()))
uc.onUserContextInteraction(event);
}
@Override
public void onMessageContextInteraction(@NotNull MessageContextInteractionEvent event) {
Member source = event.getMember();
Guild g = event.getGuild();
lgr.info("New Message Interaction from" + source.getUser().getName() + " on " + event.getInteraction().getMember().getUser().getName() + " in " + g.getName());
for (MessageContext mc : MessageContextInteractionManager.getInteractions())
if (event.getName().equals(mc.getName()))
mc.onMessageContextInteractionEvent(event);
}
}

View file

@ -1,8 +1,8 @@
package de.limited_dev.lil_judd.listeners;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.jdacommands.components.JDACommandManager;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.commands.jdacommands.components.JDACommandManager;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;

View file

@ -115,7 +115,11 @@ public class EmbeddedMessageHelper {
event.replyEmbeds(eb.build()).queue();
}
public static void sendSimpleOneLiner(SlashCommandInteractionEvent event, String title, String description, String thumbnailURL){
public static void sendSimpleOneLiner(SlashCommandInteractionEvent event, String title, String description) {
sendSimpleOneLiner(event, title, description, null);
}
public static void sendSimpleOneLiner(SlashCommandInteractionEvent event, String title, String description, String thumbnailURL) {
LocalDateTime now = LocalDateTime.now();
EmbedBuilder eb = new EmbedBuilder();
@ -123,7 +127,7 @@ public class EmbeddedMessageHelper {
eb.setTitle(title);
eb.setColor(Color.ORANGE);
eb.setDescription(description);
if(thumbnailURL != null)
if (thumbnailURL != null)
eb.setThumbnail(thumbnailURL);
eb.setFooter(">" + dtf.format(now) + " - " + event.getUser().getName() + "#" + event.getUser().getDiscriminator());
event.replyEmbeds(eb.build()).queue();

View file

@ -33,13 +33,30 @@ public class SlashCommandRegister {
.addOptions(new OptionData(OptionType.STRING, "message", "Message content", true)),
Commands.slash("scriminfo", "Show info about the scrim system."),
*/
Commands.slash("poll", "Create a pol")
.addOptions(new OptionData(OptionType.STRING, "caption", "Caption the poll", true))
.addOptions(new OptionData(OptionType.STRING, "option1", "The 1st option", true))
.addOptions(new OptionData(OptionType.STRING, "option2", "The 2nd option", true))
.addOptions(new OptionData(OptionType.STRING, "option3", "The 3rd option"))
.addOptions(new OptionData(OptionType.STRING, "option4", "The 4th option"))
.addOptions(new OptionData(OptionType.STRING, "option5", "The 5th option"))
.addOptions(new OptionData(OptionType.STRING, "option6", "The 6th option"))
.addOptions(new OptionData(OptionType.STRING, "option7", "The 7th option"))
.addOptions(new OptionData(OptionType.STRING, "option8", "The 8th option"))
.addOptions(new OptionData(OptionType.STRING, "option9", "The 9th option"))
.addOptions(new OptionData(OptionType.STRING, "option10", "The 10th option"))
,
Commands.slash("translatemap", "Translate a Map from English to German or vice versa")
.addOptions(new OptionData(OptionType.STRING, "map", "Map Name", true)),
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.BOOLEAN, "mobileformatting", "Format the reply for mobile devices")),
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.context(Command.Type.USER, "Get user avatar"),
//Commands.message("Get message ID")
).queue();
}
//https://jda.wiki/using-jda/interactions/#context-menus
}