From 7d2ebed84c9545f3c2ca7e4d20dbd589f60a44cb Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Jul 2021 00:02:16 +0200 Subject: [PATCH] Add Schem alert Signed-off-by: Chaoscaot --- .../bot/util/DiscordSchemAlert.java | 69 +++++++++++++++++++ .../bungeecore/commands/CheckCommand.java | 11 ++- 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java new file mode 100644 index 00000000..a36135db --- /dev/null +++ b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java @@ -0,0 +1,69 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.bungeecore.bot.util; + +import de.steamwar.bungeecore.bot.SteamwarDiscordBot; +import de.steamwar.bungeecore.sql.Schematic; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.entities.Emoji; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.interactions.components.ActionRow; +import net.dv8tion.jda.api.interactions.components.Button; + +import java.awt.*; +import java.time.Instant; + +public class DiscordSchemAlert { + + public static void sendDecline(Schematic schematic, SteamwarUser user, String reason) { + if(user.getDiscordId() != null) { + User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete(); + EmbedBuilder builder = new EmbedBuilder(); + builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png"); + builder.setColor(Color.RED); + builder.setTitle("SteamWar-Schematic Info"); + builder.setDescription("Deine Schematic **" + schematic.getSchemName() + "** wurde abgelehnt. **Grund:** \n" + reason); + builder.setTimestamp(Instant.now()); + + MessageBuilder messageBuilder = new MessageBuilder(); + messageBuilder.setEmbeds(builder.build()); + dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).complete(); + } + } + + public static void sendAccept(Schematic schematic, SteamwarUser user) { + if(user.getDiscordId() != null) { + User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete(); + EmbedBuilder builder = new EmbedBuilder(); + builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png"); + builder.setColor(Color.GREEN); + builder.setTitle("SteamWar-Schematic Info"); + builder.setDescription("Deine Schematic **" + schematic.getSchemName() + "** wurde angenommen."); + builder.setTimestamp(Instant.now()); + + MessageBuilder messageBuilder = new MessageBuilder(); + messageBuilder.setEmbeds(builder.build()); + messageBuilder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")))); + dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).complete(); + } + } +} diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 85589203..27f5947d 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; +import de.steamwar.bungeecore.bot.util.DiscordSchemAlert; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.sql.CheckedSchematic; import de.steamwar.bungeecore.sql.Schematic; @@ -288,8 +289,11 @@ public class CheckCommand extends BasicCommand { CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben"); SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); - if(player != null) + if(player != null) { Message.send("CHECK_ACCEPTED", player, schematic.getSchemType().name(), schematic.getSchemName()); + } else { + DiscordSchemAlert.sendAccept(schematic, user); + } Message.team("CHECK_ACCEPTED_TEAM", schematic.getSchemName(), user.getUserName()); stop(); } @@ -299,8 +303,11 @@ public class CheckCommand extends BasicCommand { CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason); SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); - if(player != null) + if(player != null) { Message.send("CHECK_DECLINED", player, schematic.getSchemType().name(), schematic.getSchemName(), reason); + } else { + DiscordSchemAlert.sendDecline(schematic, user, reason); + } Message.team("CHECK_DECLINED_TEAM", schematic.getSchemName(), user.getUserName(), reason); stop(); }