fix: Messages are now send on time into the proper time Management channels

feat: started checking for double users & bots in searchscrim command, made it impossible for DestinyCast to add the Bot to the Server
chore: added TODO.md
This commit is contained in:
limited_dev 2022-10-10 12:42:31 +02:00
parent 4a8b2640f4
commit cf5833f57b
10 changed files with 88 additions and 38 deletions

3
TODO.md Normal file
View file

@ -0,0 +1,3 @@
# TODO
- add Map Translator
- make Scrim searcher toggleable

View file

@ -16,6 +16,7 @@ import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.requests.GatewayIntent;
import java.io.IOException;
@ -36,6 +37,7 @@ public class Main {
jda = JDABuilder.createDefault(tokenManager.getToken())
.setActivity(Activity.watching("You"))
.setStatus(OnlineStatus.DO_NOT_DISTURB)
.enableIntents(GatewayIntent.GUILD_MEMBERS)
.build();
CommandManager.registerCommands();

View file

@ -1,5 +1,6 @@
package de.limited_dev.lil_judd.commands;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.features.ScrimMaker;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
@ -8,6 +9,9 @@ import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class SearchScrimCommand extends Command {
public SearchScrimCommand() {
super("searchscrim", "Search for a scrim", null);
@ -19,11 +23,27 @@ public class SearchScrimCommand extends Command {
User u2 = event.getOption("player2").getAsUser();
User u3 = event.getOption("player3").getAsUser();
User u4 = event.getOption("player4").getAsUser();
List<User> users = new CopyOnWriteArrayList<>(){{
add(u1);
add(u2);
add(u3);
add(u4);
}};
Guild g = event.getGuild();
int div = event.getOption("div").getAsInt();
ScrimMaker.EnterQueue(g, event.getChannel().asTextChannel(), div, u1, u2, u3, u4);
//MessageEmbed eb = EmbeddedMessageHelper.getEmbeddedMessageAutomated(false, "Adding...", "We are adding you to the queue", null, false ).build();
//event.replyEmbeds(eb).queue();
if(ScrimMaker.IsInGameOrQueue(g)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "The Guild is already in a match", "You cannot join another.", null);
return;
}
if(ContainsAUserTwice(users)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "You added a user twice.", "Please only add every user once.", null);
return;
}
if(ContainsABot(users)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "You added a bot", "You cannot add a bot as user.", null);
return;
}
ScrimMaker.EnterQueue(g, event.getChannel().asTextChannel(), div, users);
EmbeddedMessageHelper.sendSimpleOneLiner(event, "<a:loading:1028062794018476093> Queuing... ",
g.getName() + " has been added to the Scrim Queue for Division " + div + "\n\n" +
"Player 1 >> " + u1.getAsMention() + "\n" +
@ -32,4 +52,20 @@ public class SearchScrimCommand extends Command {
"Player 4 >> " + u4.getAsMention(),
null);
}
private boolean ContainsAUserTwice(List<User> users){
int counter = 0;
for (User u : users)
for (User us : users)
if(u.getIdLong() == us.getIdLong())
++counter;
return counter != 4;
}
private boolean ContainsABot(List<User> users){
for (User u : users)
if(u.isBot() || u.isSystem())
return true;
return false;
}
}

View file

@ -14,7 +14,7 @@ public class SetupFeatureCommand extends Command {
@Override
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
if(!event.getGuild().getMemberById(event.getUser().getId()).hasPermission(Permission.ADMINISTRATOR)){
if(!event.getGuild().getMemberById(event.getUser().getIdLong()).hasPermission(Permission.ADMINISTRATOR)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "You do not have the Permission", "Sorry, but you don't have the Permission to run this command", null);
return;
}

View file

@ -13,7 +13,7 @@ public class ScrimMaker {
private static List<GuildInQueue> queueList = new CopyOnWriteArrayList<>();
private static List<GuildInQueue> gameList = new CopyOnWriteArrayList<>();
public static void EnterQueue(Guild g, TextChannel channel, int div, User u1, User u2, User u3, User u4){
public static void EnterQueue(Guild g, TextChannel channel, int div, List<User> users){
if(IsInGameOrQueue(g)){
EmbeddedMessageHelper.sendSimpleOneLiner(g, channel.getIdLong(), "Error", "You are already in a scrim or are already searching. Please stop searching first.", null);
return;
@ -23,12 +23,12 @@ public class ScrimMaker {
if(gq.getDiv() == div || b){
b = true;
EnterGame(gq, new GuildInQueue(g, channel, div, u1, u2, u3, u4));
EnterGame(gq, new GuildInQueue(g, channel, div, users));
}
}
if(b)
return;
queueList.add(new GuildInQueue(g, channel, div, u1, u2, u3, u4));
queueList.add(new GuildInQueue(g, channel, div, users));
}
public static void LeaveQueue(Guild g){

View file

@ -26,6 +26,9 @@ import java.util.concurrent.TimeUnit;
public class TimePlanner {
private static final GuildTimePlannerStorage gtps = GuildTimePlannerStorage.getInstance();
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 GuildTimePlannerStorage getGtps() {
return gtps;
@ -36,7 +39,7 @@ public class TimePlanner {
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Europe/Berlin"));
ZonedDateTime nextNotifyDay = now.plusDays(DayUtil.getDelay(now.getDayOfWeek().name())).withHour(8).withMinute(0).withSecond(0);
ZonedDateTime nextNotifyDay = now.plusDays(DayUtil.getDelay(now.getDayOfWeek().name())).withHour(hour).withMinute(minute).withSecond(second);
//ZonedDateTime nextNotifyDay = now.plusSeconds(10);
lgr.info(nextNotifyDay.getDayOfWeek() + ", " + nextNotifyDay.getDayOfMonth() + "." + nextNotifyDay.getMonth() + "." + nextNotifyDay.getYear() + " / " + nextNotifyDay.getHour() + ":" + nextNotifyDay.getMinute() + ":" + nextNotifyDay.getSecond());
@ -44,8 +47,8 @@ public class TimePlanner {
// if it's already past the time (in this case 8:05) the first lesson will be scheduled for the next day
if (now.compareTo(nextNotifyDay) > 0) {
nextNotifyDay = nextNotifyDay.plusDays(7).withHour(8).withMinute(0);
lgr.info("See you next week");
nextNotifyDay = nextNotifyDay.plusDays(7).withHour(hour).withMinute(minute).withSecond(second);
lgr.info("Its already after 8am. Setting time to next Week");
}
// duration between now and the beginning of the next first lesson
@ -65,20 +68,22 @@ public class TimePlanner {
Thread thr = new Thread(){
@Override
public void run() {
ZonedDateTime then = ZonedDateTime.now(ZoneId.of("Europe/Berlin"));
for(Long l : gs) {
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 {
Thread.sleep(2000);
Thread.sleep(4000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
for(int i = 0; i < 7; ++i){
then = then.plusDays(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));
lgr.info(gs + ": " + then.getDayOfWeek() + ", " + then.getDayOfMonth() + "." + then.getMonthValue() + "." + then.getYear());
try {
Thread.sleep(2000);
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
@ -93,25 +98,25 @@ public class TimePlanner {
private void addReactions(Message msg){
try {
Thread.sleep(500);
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
msg.addReaction(Emoji.fromUnicode("")).queue();
try {
Thread.sleep(500);
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
msg.addReaction(Emoji.fromFormatted("")).queue();
try {
Thread.sleep(500);
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
msg.addReaction(Emoji.fromFormatted("")).queue();
try {
Thread.sleep(500);
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

View file

@ -18,28 +18,32 @@ public class GuildInQueue {
private final long startedSearching;
private long startedScrim;
public GuildInQueue(Guild g, TextChannel responseChannel, int div, User u1, User u2, User u3, User u4){
public GuildInQueue(Guild g, TextChannel responseChannel, int div, List<User> users){
this.g = g;
this.responseChannel = responseChannel;
this.div = div;
this.users = new CopyOnWriteArrayList<>(){{
add(u1);
add(u2);
add(u3);
add(u4);
}};
this.users = users;
this.startedSearching = System.currentTimeMillis();
}
public void startScrimWith(GuildInQueue g2){
this.enemyGuildInQueue = g2;
this.startedScrim = System.currentTimeMillis();
EmbeddedMessageHelper.sendSimpleOneLiner(this.g, this.responseChannel.getIdLong(), "Team found.", "A Scrim has been found!\nTime spent queuing: " + TimeUtil.getTimeFormatedRaw(this.startedScrim - this.startedSearching) + "\nYou will play against: " + this.enemyGuildInQueue.getGuild().getName() + "\n" +
"Please communicate with the other team with /msgscrim <Msg>; end the scrim with /endscrim", this.enemyGuildInQueue.getGuild().getIconUrl(), 2);
EmbeddedMessageHelper.sendSimpleOneLiner(this.g, this.responseChannel.getIdLong(),
"Match found.", "***A Scrim has been found!***\n" +
"Time spent queuing: " + TimeUtil.getTimeFormatedRaw(this.startedScrim - this.startedSearching) + "\n\n" +
"**Vs: " + this.enemyGuildInQueue.getGuild().getName() + "**\n" +
"Player 1 >> " + this.enemyGuildInQueue.getUsers().get(0).getAsMention() + "\n" +
"Player 2 >> " + this.enemyGuildInQueue.getUsers().get(1).getAsMention() + "\n" +
"Player 3 >> " + this.enemyGuildInQueue.getUsers().get(2).getAsMention() + "\n" +
"Player 4 >> " + this.enemyGuildInQueue.getUsers().get(3).getAsMention() +
"\n\n" +
"/msgscrim <msg> to message the other Team\n" +
"/endscrim to end the current scrim", this.enemyGuildInQueue.getGuild().getIconUrl(), 2);
}
public void endScrim(){
EmbeddedMessageHelper.sendSimpleOneLiner(this.g, this.responseChannel.getIdLong(), "The Scrim has ended.", "The Scrim with " + this.enemyGuildInQueue.getGuild().getName() + " was ended.", this.enemyGuildInQueue.getGuild().getIconUrl());
EmbeddedMessageHelper.sendSimpleOneLiner(this.g, this.responseChannel.getIdLong(), "The Scrim has ended.", "The Scrim with " + this.enemyGuildInQueue.getGuild().getName() + " ended.", this.enemyGuildInQueue.getGuild().getIconUrl());
}

View file

@ -15,8 +15,9 @@ public class GuildStateListener extends ListenerAdapter {
@Override
public void onGuildJoin(@NotNull GuildJoinEvent event) {
lgr.info("I have been added to a guild.");
//Guild g = event.getGuild();
//SlashCommandHelper.addSlashCommandsToGuild(g);
if(event.getGuild().getName().contains("Cast") || event.getGuild().getName().contains("cst")){
event.getGuild().leave().queue();
}
}
@Override

View file

@ -12,10 +12,9 @@ public class SlashCommandInteractionListener extends ListenerAdapter {
@Override
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
for(Command c : CommandManager.getCommands()){
Main.getLgr().info("New Command: /" + event.getName());
Main.getLgr().info("New Command: /" + event.getName() + " in " + event.getGuild().getName());
for(Command c : CommandManager.getCommands())
if(event.getName().equals(c.getName()))
c.onSlashCommandInteraction(event);
}
}
}

View file

@ -1,10 +1,6 @@
package de.limited_dev.lil_judd.util;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.commands.components.CommandManager;
import de.limited_dev.lil_judd.commands.components.Option;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
@ -41,7 +37,11 @@ public class SlashCommandHelper {
.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 German to English")
.addOptions(
new OptionData(OptionType.STRING, "map", "Message content", true)
)
).queue();