Archiviert
1
0

Merge branch 'master' into long_discord

Dieser Commit ist enthalten in:
Lixfel 2021-09-16 17:14:23 +02:00
Commit 9f985e4199
6 geänderte Dateien mit 145 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -99,6 +99,7 @@ public class SteamwarDiscordBot {
new RolesInteractionButtonListener(); new RolesInteractionButtonListener();
new DiscordTicketListener(); new DiscordTicketListener();
new DiscordAuthListener(); new DiscordAuthListener();
new DiscordEventListener();
announcementListener = new AnnouncementListener(); announcementListener = new AnnouncementListener();
ingameChatListener = new IngameChatListener(); ingameChatListener = new IngameChatListener();
serverTeamChatListener = new ServerTeamChatListener(); serverTeamChatListener = new ServerTeamChatListener();
@ -107,7 +108,7 @@ public class SteamwarDiscordBot {
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue()); jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue());
Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD); Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD);
guild.retrieveCommands().queue(commands -> commands.forEach(command -> guild.deleteCommandById(command.getId()).queue())); guild.retrieveCommands().complete().forEach(command -> guild.deleteCommandById(command.getId()).complete());
CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands(); CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands();
addCommand(commands, new MuteCommand()); addCommand(commands, new MuteCommand());
addCommand(commands, new BanCommand()); addCommand(commands, new BanCommand());
@ -115,7 +116,7 @@ public class SteamwarDiscordBot {
addCommand(commands, new TeamCommand()); addCommand(commands, new TeamCommand());
addCommand(commands, new ListCommand()); addCommand(commands, new ListCommand());
addCommand(commands, new UnbanCommand()); addCommand(commands, new UnbanCommand());
commands.queue(); commands.complete();
}); });
} }

Datei anzeigen

@ -32,10 +32,10 @@ public class ListCommand extends BasicDiscordCommand {
@Override @Override
public void run(SlashCommandEvent event) { public void run(SlashCommandEvent event) {
de.steamwar.bungeecore.commands.ListCommand.updateCustomTablist(); de.steamwar.bungeecore.commands.ListCommand.getCustomTablist();
EmbedBuilder embedBuilder = new EmbedBuilder(); EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("List"); embedBuilder.setTitle("List");
de.steamwar.bungeecore.commands.ListCommand.getPlayerMap().forEach((s, proxiedPlayers) -> { de.steamwar.bungeecore.commands.ListCommand.getCustomTablist().forEach((s, proxiedPlayers) -> {
embedBuilder.addField(s, proxiedPlayers.stream().map(player -> "`" + player.getName() + "`").collect(Collectors.joining(", ")), true); embedBuilder.addField(s, proxiedPlayers.stream().map(player -> "`" + player.getName() + "`").collect(Collectors.joining(", ")), true);
}); });
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue(); event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue();

Datei anzeigen

@ -28,13 +28,17 @@ import de.steamwar.bungeecore.sql.TeamTeilnahme;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Emoji;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.selections.SelectionMenu;
import java.awt.*; import java.awt.*;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@UtilityClass @UtilityClass
@ -66,7 +70,12 @@ public class EventManager {
embedBuilder.setAuthor("SteamWar", "https://www.steamwar.de"); embedBuilder.setAuthor("SteamWar", "https://www.steamwar.de");
Timestamp now = Timestamp.from(Instant.now()); Timestamp now = Timestamp.from(Instant.now());
Event.getComing().forEach(event -> { SelectionMenu.Builder menuBuilder = SelectionMenu.create("eventName");
menuBuilder.setPlaceholder("Wähle ein Event aus!")
.setMinValues(1)
.setMaxValues(1);
List<Event> events = Event.getComing();
events.forEach(event -> {
StringBuilder st = new StringBuilder(); StringBuilder st = new StringBuilder();
if (event.getDeadline().after(now)) { if (event.getDeadline().after(now)) {
st.append("Deadline: <t:").append(event.getDeadline().getTime() / 1000).append(":R>\n"); st.append("Deadline: <t:").append(event.getDeadline().getTime() / 1000).append(":R>\n");
@ -77,10 +86,16 @@ public class EventManager {
st.append("\nAngemeldete Teams: ").append(teilname); st.append("\nAngemeldete Teams: ").append(teilname);
} }
embedBuilder.addField(event.getEventName(), st.toString(), false); embedBuilder.addField(event.getEventName(), st.toString(), false);
if(event.getDeadline().after(Timestamp.from(Instant.now()))) {
menuBuilder.addOption(event.getEventName(), event.getEventID() + "", "An " + event.getEventName() + " teilnehmen", Emoji.fromUnicode("U+1F4DD"));
}
}); });
MessageBuilder messageBuilder = new MessageBuilder(); MessageBuilder messageBuilder = new MessageBuilder();
messageBuilder.setEmbeds(embedBuilder.build()); messageBuilder.setEmbeds(embedBuilder.build());
if(!events.isEmpty()) {
messageBuilder.setActionRows(ActionRow.of(menuBuilder.build()));
}
if (message == null) { if (message == null) {
message = textChannel.sendMessage(messageBuilder.build()).complete(); message = textChannel.sendMessage(messageBuilder.build()).complete();
} else { } else {

Datei anzeigen

@ -0,0 +1,93 @@
/*
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.listeners;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import de.steamwar.bungeecore.bot.events.EventManager;
import de.steamwar.bungeecore.sql.Event;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team;
import de.steamwar.bungeecore.sql.TeamTeilnahme;
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
import net.dv8tion.jda.api.interactions.components.Component;
import org.jetbrains.annotations.NotNull;
import java.time.Instant;
public class DiscordEventListener extends BasicDiscordListener {
@Override
public void onSelectionMenu(@NotNull SelectionMenuEvent event) {
if(event.getChannel().getId().equals(SteamwarDiscordBotConfig.EVENTS_CHANNEL) && event.getComponentType() == Component.Type.SELECTION_MENU) {
if(event.getSelectedOptions().isEmpty()) {
event.deferReply(true).queue();
return;
}
if(event.getSelectedOptions().get(0).getValue().matches("([0-9]+)")) {
SteamwarUser user = SteamwarUser.get(event.getUser().getIdLong());
if(user == null) {
event.reply("Du hast dein Minecraft nicht verknüpft").setEphemeral(true).queue();
return;
}
if(user.getTeam() == 0) {
event.reply("Du bist in keinem Team").setEphemeral(true).queue();
return;
}
if(!user.isLeader()) {
event.reply("Du bist kein Leader in deinem Team").setEphemeral(true).queue();
return;
}
if(Event.get() != null) {
event.reply("Du kannst dich nicht während einem Event an einem Event anmelden").setEphemeral(true).queue();
return;
}
Event swEvent = Event.get(Integer.decode(event.getSelectedOptions().get(0).getValue()));
if(swEvent == null){
event.reply("Das Event gibt es nicht").setEphemeral(true).queue();
return;
}
if(Instant.now().isAfter(swEvent.getDeadline().toInstant())){
event.reply("Du kannst dich nicht mehr an diesen Event anmelden").setEphemeral(true).queue();
return;
}
Team team = Team.get(user.getTeam());
if(TeamTeilnahme.nimmtTeil(team.getTeamId(), swEvent.getEventID())){
TeamTeilnahme.notTeilnehmen(team.getTeamId(), swEvent.getEventID());
event.reply("Dein Team **" + team.getTeamName() + "** nimmt nun nicht mehr an **" + swEvent.getEventName() + "** teil!").setEphemeral(true).queue();
}else{
TeamTeilnahme.teilnehmen(team.getTeamId(), swEvent.getEventID());
event.reply("Dein Team **" + team.getTeamName() + "** nimmt nun an **" + swEvent.getEventName() + "** teil!").setEphemeral(true).queue();
}
EventManager.update();
} else {
event.reply("Lefuq?").setEphemeral(true).queue();
}
}
}
}

Datei anzeigen

@ -75,29 +75,40 @@ public class DiscordTicketListener extends BasicDiscordListener {
} else if(event.getComponentId().startsWith("close-")) { } else if(event.getComponentId().startsWith("close-")) {
TextChannel logChannel = event.getGuild().getTextChannelById(SteamwarDiscordBotConfig.TICKET_LOG); TextChannel logChannel = event.getGuild().getTextChannelById(SteamwarDiscordBotConfig.TICKET_LOG);
MessageBuilder builder = new MessageBuilder(); LinkedList<StringBuilder> stringBuilders = new LinkedList<>();
StringBuilder stringBuilder = new StringBuilder(); stringBuilders.add(new StringBuilder());
new LinkedList<>(event.getTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> { new LinkedList<>(event.getTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> {
if(message.getAuthor().isSystem() || message.getAuthor().isBot()) return; if(message.getAuthor().isSystem() || message.getAuthor().isBot()) return;
stringBuilder.append("<t:").append(message.getTimeCreated().toInstant().getEpochSecond()).append("> ") StringBuilder currentBuilder = new StringBuilder();
currentBuilder.append("<t:").append(message.getTimeCreated().toInstant().getEpochSecond()).append("> ")
.append("**") .append("**")
.append(message.getAuthor().getName()) .append(message.getAuthor().getName())
.append("**: ") .append("**: ")
.append(message.getContentRaw()); .append(message.getContentRaw());
if(!message.getAttachments().isEmpty()) { if(!message.getAttachments().isEmpty()) {
stringBuilder.append("\n") currentBuilder.append("\n")
.append("Files: ").append("\n"); .append("Files: ").append("\n");
message.getAttachments().forEach(attachment -> stringBuilder.append(attachment.getUrl()).append("\n")); message.getAttachments().forEach(attachment -> currentBuilder.append(attachment.getUrl()).append("\n"));
} }
stringBuilder.append("\n"); currentBuilder.append("\n");
if(currentBuilder.length() >= 4096) {
stringBuilders.getLast().append(currentBuilder.substring(0, 4090));
stringBuilders.add(new StringBuilder(currentBuilder.substring(4090, currentBuilder.length() - 1)));
} else if (currentBuilder.length() + stringBuilders.getLast().length() >= 4096) {
stringBuilders.add(new StringBuilder(currentBuilder.toString()));
} else {
stringBuilders.getLast().append(currentBuilder);
}
}); });
stringBuilder.append("\n"); String footer = "<t:" + Instant.now().getEpochSecond() + "> **" + event.getUser().getName() + "**: Ticket geschlossen";
stringBuilder.append("<t:").append(Instant.now().getEpochSecond()).append("> ") if(stringBuilders.getLast().length() + footer.length() > 4090) {
.append("**").append(event.getUser().getName()).append("**: ") stringBuilders.add(new StringBuilder(footer));
.append("Ticket geschlossen"); } else {
stringBuilders.getLast().append(footer);
}
EmbedBuilder embedBuilder = new EmbedBuilder(); EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(Color.GREEN); embedBuilder.setColor(Color.GREEN);
@ -107,11 +118,13 @@ public class DiscordTicketListener extends BasicDiscordListener {
embedBuilder.setAuthor(user.getName(), swuser==null?"https://steamwar.de/":("https://steamwar.de/users/" + swuser.getUserName().toLowerCase() + "/"), user.getAvatarUrl()); embedBuilder.setAuthor(user.getName(), swuser==null?"https://steamwar.de/":("https://steamwar.de/users/" + swuser.getUserName().toLowerCase() + "/"), user.getAvatarUrl());
embedBuilder.setTimestamp(Instant.now()); embedBuilder.setTimestamp(Instant.now());
embedBuilder.setTitle(event.getTextChannel().getName()); embedBuilder.setTitle(event.getTextChannel().getName());
embedBuilder.setDescription(stringBuilder); stringBuilders.forEach(stringBuilder -> {
embedBuilder.setDescription(stringBuilder.toString());
MessageBuilder builder = new MessageBuilder();
builder.setEmbeds(embedBuilder.build());
builder.setEmbeds(embedBuilder.build()); logChannel.sendMessage(builder.build()).queue();
});
logChannel.sendMessage(builder.build()).complete();
Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName()); Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName());
event.getTextChannel().delete().reason("Closed").queue(); event.getTextChannel().delete().reason("Closed").queue();

Datei anzeigen

@ -22,7 +22,6 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver; import de.steamwar.bungeecore.Subserver;
import lombok.Getter;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
@ -40,12 +39,8 @@ public class ListCommand extends BasicCommand {
super("list", ""); super("list", "");
} }
@Getter public static synchronized TreeMap<String, List<ProxiedPlayer>> getCustomTablist(){
private static final TreeMap<String, List<ProxiedPlayer>> playerMap = new TreeMap<>(); TreeMap<String, List<ProxiedPlayer>> playerMap = new TreeMap<>();
public static synchronized void updateCustomTablist(){
//Calculate server-player-map
playerMap.clear();
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) { for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
Server pserver = player.getServer(); Server pserver = player.getServer();
if (pserver == null) //Happens temporarily if (pserver == null) //Happens temporarily
@ -62,11 +57,12 @@ public class ListCommand extends BasicCommand {
} }
} }
playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName()))); playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName())));
return playerMap;
} }
@Override @Override
public void execute(CommandSender commandSender, String[] strings) { public void execute(CommandSender commandSender, String[] strings) {
updateCustomTablist(); TreeMap<String, List<ProxiedPlayer>> playerMap = getCustomTablist();
for (String server : playerMap.navigableKeySet()) { for (String server : playerMap.navigableKeySet()) {
if (server.equals("Bau")) { if (server.equals("Bau")) {
server = Message.parse("TABLIST_BAU", commandSender); server = Message.parse("TABLIST_BAU", commandSender);