From 8de19123b976ff16770e865e2abd4485fc94e335 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 28 Jul 2021 21:39:35 +0200 Subject: [PATCH] Latest and Greatest --- .../bungeecore/bot/SteamwarDiscordBot.java | 1 + .../bot/listeners/DiscordTicketListener.java | 40 ++++++++++++++++++- .../bungeecore/bot/util/DiscordRanks.java | 1 + .../steamwar/messages/BungeeCore.properties | 7 +++- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java index 9d458e51..03dceb9a 100644 --- a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java +++ b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java @@ -35,6 +35,7 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.OnlineStatus; import net.dv8tion.jda.api.entities.Activity; +import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.utils.MemberCachePolicy; import net.md_5.bungee.api.ProxyServer; diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java index 7ba2e4ec..2c88f8bb 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java @@ -19,16 +19,22 @@ package de.steamwar.bungeecore.bot.listeners; +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.bot.config.DiscordTicketType; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent; +import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.interactions.InteractionType; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.Button; +import net.dv8tion.jda.api.interactions.components.selections.SelectionMenu; +import net.md_5.bungee.api.chat.ClickEvent; import org.jetbrains.annotations.NotNull; import java.awt.Color; @@ -43,7 +49,8 @@ public class DiscordTicketListener extends BasicDiscordListener { if(event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && SteamwarDiscordBotConfig.TICKET_TYPES.containsKey(event.getComponentId())) { DiscordTicketType ticketType = SteamwarDiscordBotConfig.TICKET_TYPES.get(event.getComponentId()); Category ct = event.getGuild().getCategoryById(SteamwarDiscordBotConfig.TICKET_CATEGORY); - TextChannel ticketChannel = ct.createTextChannel(event.getUser().getName() + "-" + event.getComponentId() + "-" + System.currentTimeMillis() % 1000).complete(); + SteamwarUser swUser = SteamwarUser.get(event.getUser().getIdLong()); + TextChannel ticketChannel = ct.createTextChannel((swUser == null?event.getUser().getName():swUser.getUserName()) + "-" + event.getComponentId() + "-" + System.currentTimeMillis() % 1000).complete(); ticketChannel.createPermissionOverride(event.getMember()).setAllow(Permission.VIEW_CHANNEL, Permission.MESSAGE_WRITE, Permission.MESSAGE_ATTACH_FILES, @@ -51,6 +58,7 @@ public class DiscordTicketListener extends BasicDiscordListener { Permission.MESSAGE_READ, Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_HISTORY).complete(); + ticketChannel.getManager().setTopic(event.getUser().getId()).complete(); MessageBuilder messageBuilder = new MessageBuilder(); EmbedBuilder builder = new EmbedBuilder(); @@ -64,6 +72,7 @@ public class DiscordTicketListener extends BasicDiscordListener { ticketChannel.sendMessage(messageBuilder.build()).complete(); event.reply(SteamwarDiscordBotConfig.TICKET_CREATED.replace("%channel%", ticketChannel.getAsMention())).setEphemeral(true).complete(); + Message.team("DISCORD_TICKET_NEW", ticketChannel.getName()); } else if(event.getComponentId().startsWith("close-")) { TextChannel logChannel = event.getGuild().getTextChannelById(SteamwarDiscordBotConfig.TICKET_LOG); @@ -71,6 +80,7 @@ public class DiscordTicketListener extends BasicDiscordListener { StringBuilder stringBuilder = new StringBuilder(); new LinkedList<>(event.getTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> { + if(message.getAuthor().isSystem() || message.getAuthor().isBot()) return; stringBuilder.append(" ") .append("**") .append(message.getAuthor().getName()) @@ -87,6 +97,10 @@ public class DiscordTicketListener extends BasicDiscordListener { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setColor(Color.GREEN); + User user = event.getJDA().retrieveUserById(event.getTextChannel().getTopic()).complete(); + SteamwarUser swuser = SteamwarUser.get(user.getIdLong()); + + embedBuilder.setAuthor(user.getName(), swuser==null?"https://steamwar.de/":("https://steamwar.de/users/" + swuser.getUserName().toLowerCase() + "/"), user.getAvatarUrl()); embedBuilder.setTimestamp(Instant.now()); embedBuilder.setTitle(event.getTextChannel().getName()); embedBuilder.setDescription(stringBuilder); @@ -95,8 +109,32 @@ public class DiscordTicketListener extends BasicDiscordListener { logChannel.sendMessage(builder.build()).complete(); + Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName()); event.getTextChannel().delete().reason("Closed").complete(); } } } + + @Override + public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) { + if(event.getChannel().getParent() != null && event.getChannel().getParent().getId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) { + if(!event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && !event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_LOG)) { + BungeeCore.get().getProxy().getPlayers().forEach(player -> { + if(event.getAuthor().isBot() || event.getAuthor().isSystem()) return; + SteamwarUser user = SteamwarUser.get(player); + if(user.getDiscordId() == null) { + if(user.getUserGroup().isTeamGroup()) { + Message.sendPrefixless("DISCORD_TICKET_MESSAGE", player, "Zur nachricht", new ClickEvent(ClickEvent.Action.OPEN_URL, event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw()); + } + } else { + if(event.getAuthor().getId().equals(user.getDiscordId())) return; + Member member = event.getGuild().retrieveMemberById(user.getDiscordId()).complete(); + if(member.hasPermission(event.getChannel().getManager().getChannel(), Permission.MESSAGE_WRITE)) { + Message.sendPrefixless("DISCORD_TICKET_MESSAGE", player, "Zur nachricht", new ClickEvent(ClickEvent.Action.OPEN_URL, event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw()); + } + } + }); + } + } + } } diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java b/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java index fe70ace4..9b976cef 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java @@ -59,6 +59,7 @@ public class DiscordRanks { } guild.removeRoleFromMember(member, role).complete(); } + if (!needed.isEmpty()) { guild.addRoleToMember(member, guild.getRoleById(needed)).complete(); } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index c3e27daf..a5b77046 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -516,4 +516,9 @@ WHOIS_NO_PUNISHMENT=§a✓ §7Der Spieler hat noch nichts getan. #VerifyCommand VERIFY_USAGE=§c/verify [Code] VERIFY_INVALID=§cInvalider Code -VERIFY_SUCCESS=§eErfolgreich mit dem Discord Account {0} verknüpft \ No newline at end of file +VERIFY_SUCCESS=§eErfolgreich mit dem Discord Account {0} verknüpft + +#Discord +DISCORD_TICKET_MESSAGE=§3Ticket {0}§7» §f§l{1}: §7{2} +DISCORD_TICKET_NEW=§3Ticket {0}§7» §aTicket wurde geöffnet! +DISCORD_TICKET_CLOSED=§3Ticket {0}§7» §cTicket wurde geschlossen! \ No newline at end of file