Archiviert
1
0

Merge pull request 'Add Schem alert' (#231) from discord-bot into master

Reviewed-on: SteamWar/BungeeCore#231
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
YoyoNow 2021-07-29 00:02:55 +02:00
Commit 687fc11fda
2 geänderte Dateien mit 78 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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();
}
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.bot.util.DiscordSchemAlert;
import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.listeners.ConnectionListener;
import de.steamwar.bungeecore.sql.CheckedSchematic; import de.steamwar.bungeecore.sql.CheckedSchematic;
import de.steamwar.bungeecore.sql.Schematic; 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"); CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben");
SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner()); SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner());
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
if(player != null) if(player != null) {
Message.send("CHECK_ACCEPTED", player, schematic.getSchemType().name(), schematic.getSchemName()); Message.send("CHECK_ACCEPTED", player, schematic.getSchemType().name(), schematic.getSchemName());
} else {
DiscordSchemAlert.sendAccept(schematic, user);
}
Message.team("CHECK_ACCEPTED_TEAM", schematic.getSchemName(), user.getUserName()); Message.team("CHECK_ACCEPTED_TEAM", schematic.getSchemName(), user.getUserName());
stop(); 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); CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason);
SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner()); SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner());
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
if(player != null) if(player != null) {
Message.send("CHECK_DECLINED", player, schematic.getSchemType().name(), schematic.getSchemName(), reason); 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); Message.team("CHECK_DECLINED_TEAM", schematic.getSchemName(), user.getUserName(), reason);
stop(); stop();
} }