SteamWar/BungeeCore
Archiviert
13
2

Commits vergleichen

...
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.

9 Commits

Autor SHA1 Nachricht Datum
yoyosource
8a23089bee Fix messages for Discord chat 2023-04-07 09:32:49 +02:00
yoyosource
775b0db552 Merge branch 'dc_5.0' into dc_5.0_neue_features 2023-04-07 09:27:55 +02:00
Chaoscaot
14ab2b05b6 Update DEP 2023-04-04 16:06:07 +02:00
yoyosource
54bdee79dc Fix ChannelManager 2023-03-23 16:33:52 +01:00
yoyosource
0bab12ed6c Add unfinished ChannelManager 2023-03-22 20:35:54 +01:00
Chaoscaot
36b329dc4f Merge branch 'master' into dc_5.0 2023-03-19 20:28:31 +01:00
Chaoscaot
49cfb11bf1 Fix Merge Conflicts and Force Shutdown 2023-02-23 10:51:37 +01:00
Chaoscaot
56227a4a9f Merge remote-tracking branch 'origin/master' into dc_5.0
# Conflicts:
#	src/de/steamwar/bungeecore/bot/AuthManager.java
#	src/de/steamwar/bungeecore/bot/commands/BanCommand.java
#	src/de/steamwar/bungeecore/bot/commands/MuteCommand.java
#	src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java
#	src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java
#	src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java
2023-02-23 10:50:10 +01:00
Chaoscaot
40e61f7000 Port Discord Bot to JDA 5.0 2023-02-21 17:16:27 +01:00
31 geänderte Dateien mit 395 neuen und 160 gelöschten Zeilen

Datei anzeigen

@ -97,7 +97,7 @@ dependencies {
compileOnly 'de.steamwar:waterfall:RELEASE'
compileOnly 'de.steamwar:persistentbungeecore:RELEASE'
implementation("net.dv8tion:JDA:4.4.0_352") {
implementation("net.dv8tion:JDA:5.0.0-beta.6") {
exclude module: 'opus-java'
}

Datei anzeigen

@ -55,6 +55,7 @@ import net.md_5.bungee.config.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@ -224,6 +225,10 @@ public class BungeeCore extends Plugin {
if (SteamwarDiscordBotConfig.loaded) {
try {
SteamwarDiscordBot.instance().getJda().shutdown();
if(!SteamwarDiscordBot.instance().getJda().awaitShutdown(Duration.ofSeconds(10))) {
SteamwarDiscordBot.instance().getJda().shutdownNow();
SteamwarDiscordBot.instance().getJda().awaitShutdown();
}
} catch (Throwable e) {
getLogger().log(Level.SEVERE, "Could not shutdown discord bot", e);
}

Datei anzeigen

@ -22,11 +22,11 @@ package de.steamwar.bungeecore.bot;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import de.steamwar.sql.SteamwarUser;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Emoji;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.Button;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import java.util.*;
import java.util.concurrent.TimeUnit;
@ -56,9 +56,9 @@ public class AuthManager {
Member member = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).retrieveMemberById(TOKENS.get(code).longValue()).complete();
if(member == null) return null;
user.setDiscordId(member.getIdLong());
MessageBuilder builder = new MessageBuilder();
MessageCreateBuilder builder = new MessageCreateBuilder();
builder.setContent(":white_check_mark: Dein Discord Konto wurde mit **" + user.getUserName() + "** verknüpft");
builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")), Button.danger("invalid", "Ich war das nicht")));
builder.setComponents(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")), Button.danger("invalid", "Ich war das nicht")));
try {
member.getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(builder.build()).queue());

Datei anzeigen

@ -0,0 +1,187 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 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;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.requests.restaction.ChannelAction;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.IntFunction;
public class ChannelManager extends ListenerAdapter {
private static final String[] ROMEN_NUMERALS = {
"",
"I",
"II",
"III",
"IV",
"V",
"VI",
"VII",
"VIII",
"IX",
"X",
"XI",
"XII",
"XIII",
"XIV",
"XV",
"XVI",
"XVII",
"XVIII",
"XIX",
"XX",
};
private ChannelManagerOptions options;
private Guild guild;
private List<String> channelNames = new ArrayList<>();
private List<VoiceChannel> channels = new ArrayList<>();
public ChannelManager(ChannelManagerOptions options) {
options.check();
this.options = options;
JDA jda = options.jda;
jda.addEventListener(this);
guild = jda.getGuildById(options.guildID);
if (guild == null) {
throw new IllegalArgumentException("Guild with ID " + options.guildID + " not found");
}
for (int i = 1; i <= options.maxChannels; i++) {
channelNames.add(options.channelName.apply(i));
}
startUp();
}
private void startUp() {
Objects.requireNonNull(guild.getCategoryById(options.categoryID))
.getVoiceChannels()
.stream()
.filter(voiceChannel -> channelNames.contains(voiceChannel.getName()))
.forEach(channels::add);
channels.sort((o1, o2) -> {
int i1 = channelNames.indexOf(o1.getName());
int i2 = channelNames.indexOf(o2.getName());
return Integer.compare(i1, i2);
});
for (int i = channels.size() - 1; i >= 0; i--) {
VoiceChannel channel = channels.get(i);
if (channel.getMembers().isEmpty()) {
channel.delete().queue();
channels.remove(i);
}
}
if (channels.size() == options.maxChannels) {
return;
}
createChannelWithIndex(channels.size());
}
@Override
public synchronized void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) {
if (event.getChannelLeft() instanceof VoiceChannel) {
leave((VoiceChannel) event.getChannelLeft());
}
if (event.getChannelJoined() instanceof VoiceChannel) {
join((VoiceChannel) event.getChannelJoined());
}
}
private void leave(VoiceChannel voiceChannel) {
if (voiceChannel.getGuild().getIdLong() != options.guildID) return;
if (voiceChannel.getParentCategoryIdLong() != options.categoryID) return;
if (!channelNames.contains(voiceChannel.getName())) return;
if (!voiceChannel.getMembers().isEmpty()) return;
if (channels.size() <= 1) return;
int index = channels.indexOf(voiceChannel);
boolean needsRecreate = channels.size() == options.maxChannels && index < options.maxChannels - 1 && !channels.get(channels.size() - 1).getMembers().isEmpty();
channels.remove(index);
voiceChannel.delete().complete();
for (int i = index; i < channels.size(); i++) {
VoiceChannel channel = channels.get(i);
channel.getManager().setName(options.channelName.apply(i + 1)).queue();
}
if (needsRecreate) {
createChannelWithIndex(channels.size());
}
}
private void join(VoiceChannel voiceChannel) {
if (voiceChannel.getGuild().getIdLong() != options.guildID) return;
if (voiceChannel.getParentCategoryIdLong() != options.categoryID) return;
if (!channelNames.contains(voiceChannel.getName())) return;
int index = channels.indexOf(voiceChannel);
if (index < channels.size() - 1) return;
if (index >= options.maxChannels - 1) return;
createChannelWithIndex(index + 1);
}
private void createChannelWithIndex(int index) {
ChannelAction<VoiceChannel> channelAction = guild.createVoiceChannel(channelNames.get(index))
.setParent(guild.getCategoryById(options.categoryID));
if (options.channelCreator != null) {
options.channelCreator.accept(channelAction);
}
VoiceChannel newChannel = channelAction.complete();
channels.add(newChannel);
}
@Setter
@Accessors(fluent = true)
public static final class ChannelManagerOptions {
private JDA jda;
private long guildID;
private long categoryID;
private int maxChannels = 20;
private IntFunction<String> channelName = USER_LOUNGE;
private Consumer<ChannelAction<VoiceChannel>> channelCreator = null;
private void check() {
if (jda == null) throw new IllegalStateException("JDA is null");
if (guildID == 0) throw new IllegalStateException("GuildID is 0");
if (categoryID == 0) throw new IllegalStateException("CategoryID is 0");
if (maxChannels < 1) throw new IllegalStateException("MaxChannels is less than 1");
if (maxChannels > 20) throw new IllegalStateException("MaxChannels is greater than 20");
if (channelName == null) throw new IllegalStateException("ChannelName is null");
}
}
public static final IntFunction<String> USER_LOUNGE = i -> "\uD83D\uDCAC」User Lounge " + ROMEN_NUMERALS[i];
public static final IntFunction<String> TEAM_LOUNGE = i -> "\uD83D\uDCAC」Team Lounge " + ROMEN_NUMERALS[i];
}

Datei anzeigen

@ -38,11 +38,12 @@ import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
import net.dv8tion.jda.api.utils.MemberCachePolicy;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import net.md_5.bungee.api.ProxyServer;
import javax.security.auth.login.LoginException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@ -74,13 +75,11 @@ public class SteamwarDiscordBot {
public SteamwarDiscordBot() {
INSTANCE = this;
JDABuilder builder = JDABuilder.createDefault(SteamwarDiscordBotConfig.TOKEN);
builder.enableIntents(GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.GUILD_EMOJIS_AND_STICKERS);
builder.setStatus(OnlineStatus.ONLINE);
builder.setMemberCachePolicy(MemberCachePolicy.ONLINE);
try {
jda = builder.build();
} catch (LoginException e) {
throw new SecurityException("Could not Login: " + SteamwarDiscordBotConfig.TOKEN, e);
}
builder.enableCache(CacheFlag.VOICE_STATE);
builder.setMemberCachePolicy(MemberCachePolicy.ONLINE.or(MemberCachePolicy.VOICE));
jda = builder.build();
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
try {
jda.awaitReady();
@ -92,6 +91,14 @@ public class SteamwarDiscordBot {
} catch (Exception e) {
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not set initial activity to discord", e);
}
new ChannelManager(new ChannelManager.ChannelManagerOptions()
.guildID(869612801499476068L)
.categoryID(869612801520435312L)
.maxChannels(3)
.jda(jda)
);
EventManager.update();
SchematicsManager.update();
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
@ -117,22 +124,26 @@ public class SteamwarDiscordBot {
new SlashCommandListener();
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue());
Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD);
guild.retrieveCommands().complete().forEach(command -> guild.deleteCommandById(command.getId()).complete());
CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands();
addCommand(commands, new MuteCommand());
addCommand(commands, new BanCommand());
addCommand(commands, new WhoisCommand());
addCommand(commands, new TeamCommand());
addCommand(commands, new ListCommand());
addCommand(commands, new UnbanCommand());
commands.complete();
try {
Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD);
guild.retrieveCommands().complete().forEach(command -> guild.deleteCommandById(command.getId()).complete());
CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands();
addCommand(commands, new MuteCommand());
addCommand(commands, new BanCommand());
addCommand(commands, new WhoisCommand());
addCommand(commands, new TeamCommand());
addCommand(commands, new ListCommand());
addCommand(commands, new UnbanCommand());
commands.complete();
} catch (Exception e) {
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not register slash commands", e);
}
});
}
private void addCommand(CommandListUpdateAction commands, BasicDiscordCommand basicDiscordCommand) {
commands.addCommands(basicDiscordCommand);
discordCommandMap.put(basicDiscordCommand.getName(), basicDiscordCommand);
commands.addCommands(basicDiscordCommand.getData());
discordCommandMap.put(basicDiscordCommand.getData().getName(), basicDiscordCommand);
}
private int index = 0;

Datei anzeigen

@ -22,7 +22,7 @@ package de.steamwar.bungeecore.bot.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.commands.PunishmentCommand;
import de.steamwar.sql.SteamwarUser;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import java.sql.Timestamp;
@ -32,13 +32,13 @@ public class BanCommand extends BasicDiscordCommand {
public BanCommand() {
super("ban", "Banne einen Nutzer, wenn du die Rechte hast.");
addOption(OptionType.STRING, "user", "Der Benutzer", true);
addOption(OptionType.STRING, "time", "Bis Wann", true);
addOption(OptionType.STRING, "reason", "Warum", true);
getData().addOption(OptionType.STRING, "user", "Der Benutzer", true);
getData().addOption(OptionType.STRING, "time", "Bis Wann", true);
getData().addOption(OptionType.STRING, "reason", "Warum", true);
}
@Override
public void run(SlashCommandEvent event) {
public void run(SlashCommandInteractionEvent event) {
if (!testPermission(event)) {
return;
}

Datei anzeigen

@ -22,27 +22,33 @@ package de.steamwar.bungeecore.bot.commands;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserGroup;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import org.jetbrains.annotations.NotNull;
public abstract class BasicDiscordCommand extends CommandData {
public abstract class BasicDiscordCommand {
private final SlashCommandData data;
protected BasicDiscordCommand(String name, String description) {
super(name, description);
data = Commands.slash(name, description);
}
public abstract void run(SlashCommandEvent event);
public SlashCommandData getData() {
return data;
}
protected SteamwarUser getSteamwarUser(SlashCommandEvent event) {
public abstract void run(SlashCommandInteractionEvent event);
protected SteamwarUser getSteamwarUser(SlashCommandInteractionEvent event) {
Member member = event.getMember();
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
if (steamwarUser == null) {
return null;
}
return steamwarUser;
}
protected boolean testPermission(SlashCommandEvent event) {
protected boolean testPermission(SlashCommandInteractionEvent event) {
Member member = event.getMember();
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
if (steamwarUser == null || (!steamwarUser.getUserGroup().isTeamGroup() && steamwarUser.getUserGroup() != UserGroup.Builder)) {

Datei anzeigen

@ -20,7 +20,7 @@
package de.steamwar.bungeecore.bot.commands;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import java.util.stream.Collectors;
@ -31,7 +31,7 @@ public class ListCommand extends BasicDiscordCommand {
}
@Override
public void run(SlashCommandEvent event) {
public void run(SlashCommandInteractionEvent event) {
de.steamwar.bungeecore.commands.ListCommand.getCustomTablist();
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("List");

Datei anzeigen

@ -23,7 +23,7 @@ import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.commands.PunishmentCommand;
import de.steamwar.sql.Punishment;
import de.steamwar.sql.SteamwarUser;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import java.sql.Timestamp;
@ -33,13 +33,13 @@ public class MuteCommand extends BasicDiscordCommand {
public MuteCommand() {
super("mute", "Mute einen Nutzer, wenn du die Rechte hast.");
addOption(OptionType.STRING, "user", "Der Benutzer", true);
addOption(OptionType.STRING, "time", "Bis Wann", true);
addOption(OptionType.STRING, "reason", "Warum", true);
getData().addOption(OptionType.STRING, "user", "Der Benutzer", true);
getData().addOption(OptionType.STRING, "time", "Bis Wann", true);
getData().addOption(OptionType.STRING, "reason", "Warum", true);
}
@Override
public void run(SlashCommandEvent event) {
public void run(SlashCommandInteractionEvent event) {
if (!testPermission(event)) {
return;
}

Datei anzeigen

@ -24,8 +24,8 @@ import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.Team;
import de.steamwar.sql.TeamTeilnahme;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Emoji;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
@ -40,7 +40,7 @@ public class TeamCommand extends BasicDiscordCommand {
public TeamCommand() {
super("team", "Alle Team bezogenen Befehle");
addSubcommands(new SubcommandData("info", "Infos über das Team oder deins")
getData().addSubcommands(new SubcommandData("info", "Infos über das Team oder deins")
.addOption(OptionType.STRING, "team", "Name oder Kuerzel", false)
);
}
@ -48,7 +48,7 @@ public class TeamCommand extends BasicDiscordCommand {
private Emoji emoji = Emoji.fromUnicode("U+1F7E2");
@Override
public void run(SlashCommandEvent event) {
public void run(SlashCommandInteractionEvent event) {
SteamwarUser steamwarUser = getSteamwarUser(event);
if (event.getSubcommandName() != null) {
@ -78,8 +78,8 @@ public class TeamCommand extends BasicDiscordCommand {
embedBuilder.setColor(Color.GRAY);
List<SteamwarUser> members = team.getMembers().stream().map(SteamwarUser::get).collect(Collectors.toList());
embedBuilder.addField("Leader", members.stream().filter(SteamwarUser::isLeader).map(user -> "`" + (isOnline(user) ? emoji.getAsMention() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false);
embedBuilder.addField("Member", members.stream().filter(user -> !user.isLeader()).map(user -> "`" + (isOnline(user) ? emoji.getAsMention() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false);
embedBuilder.addField("Leader", members.stream().filter(SteamwarUser::isLeader).map(user -> "`" + (isOnline(user) ? emoji.getAsReactionCode() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false);
embedBuilder.addField("Member", members.stream().filter(user -> !user.isLeader()).map(user -> "`" + (isOnline(user) ? emoji.getAsReactionCode() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false);
embedBuilder.addField("Events", "`" + TeamTeilnahme.getEvents(team.getTeamId()).stream().map(Event::getEventName).collect(Collectors.joining("` `")) + "`", false);
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue();
return;

Datei anzeigen

@ -23,7 +23,7 @@ import de.steamwar.bungeecore.commands.PunishmentCommand;
import de.steamwar.sql.BannedUserIPs;
import de.steamwar.sql.Punishment;
import de.steamwar.sql.SteamwarUser;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import java.sql.Timestamp;
@ -34,11 +34,11 @@ public class UnbanCommand extends BasicDiscordCommand {
public UnbanCommand() {
super("unban", "Entbannt einen Nutzer, wenn du die Rechte hast.");
addOption(OptionType.STRING, "user", "Der Benutzer", true);
getData().addOption(OptionType.STRING, "user", "Der Benutzer", true);
}
@Override
public void run(SlashCommandEvent event) {
public void run(SlashCommandInteractionEvent event) {
if (!testPermission(event)) {
return;
}

Datei anzeigen

@ -23,7 +23,7 @@ import de.steamwar.sql.Punishment;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.Team;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import java.sql.Timestamp;
@ -35,11 +35,11 @@ public class WhoisCommand extends BasicDiscordCommand {
public WhoisCommand() {
super("whois", "Der whois Befehl");
addOption(OptionType.STRING, "user", "Der Benutzer", true);
getData().addOption(OptionType.STRING, "user", "Der Benutzer", true);
}
@Override
public void run(SlashCommandEvent event) {
public void run(SlashCommandInteractionEvent event) {
if (!testPermission(event)) {
return;
}

Datei anzeigen

@ -21,9 +21,9 @@ package de.steamwar.bungeecore.bot.config;
import lombok.AllArgsConstructor;
import lombok.Data;
import net.dv8tion.jda.api.entities.Emoji;
import net.dv8tion.jda.api.interactions.components.Button;
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
@Data
@AllArgsConstructor

Datei anzeigen

@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.config;
import lombok.AllArgsConstructor;
import lombok.Data;
import net.dv8tion.jda.api.interactions.components.Button;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
@Data
@AllArgsConstructor

Datei anzeigen

@ -21,9 +21,9 @@ package de.steamwar.bungeecore.bot.config;
import lombok.AllArgsConstructor;
import lombok.Data;
import net.dv8tion.jda.api.entities.Emoji;
import net.dv8tion.jda.api.interactions.components.Button;
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
@Data
@AllArgsConstructor

Datei anzeigen

@ -27,12 +27,15 @@ import de.steamwar.sql.TeamTeilnahme;
import de.steamwar.sql.Event;
import lombok.experimental.UtilityClass;
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.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.selections.SelectionMenu;
import net.dv8tion.jda.api.interactions.components.Component;
import net.dv8tion.jda.api.interactions.components.selections.SelectMenu;
import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageEditData;
import java.awt.*;
import java.sql.Timestamp;
@ -50,7 +53,7 @@ public class EventManager {
static {
textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.EVENTS_CHANNEL);
assert textChannel != null;
if(textChannel.hasLatestMessage()) {
if(textChannel.getLatestMessageIdLong() != 0) {
message = textChannel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
}
}
@ -70,7 +73,7 @@ public class EventManager {
embedBuilder.setAuthor("SteamWar", "https://www.steamwar.de");
Timestamp now = Timestamp.from(Instant.now());
SelectionMenu.Builder menuBuilder = SelectionMenu.create("eventName");
StringSelectMenu.Builder menuBuilder = StringSelectMenu.create("eventName");
menuBuilder.setPlaceholder("Wähle ein Event aus!")
.setMinValues(1)
.setMaxValues(1);
@ -91,15 +94,15 @@ public class EventManager {
}
});
MessageBuilder messageBuilder = new MessageBuilder();
MessageCreateBuilder messageBuilder = new MessageCreateBuilder();
messageBuilder.setEmbeds(embedBuilder.build());
if(events.stream().anyMatch(event -> event.getDeadline().after(Timestamp.from(Instant.now())))) {
messageBuilder.setActionRows(ActionRow.of(menuBuilder.build()));
messageBuilder.setComponents(ActionRow.of(menuBuilder.build()));
}
if (message == null) {
message = textChannel.sendMessage(messageBuilder.build()).complete();
} else {
message.editMessage(messageBuilder.build()).complete();
message.editMessage(MessageEditData.fromCreateData(messageBuilder.build())).complete();
}
}
@ -131,12 +134,12 @@ public class EventManager {
embedBuilder.addField(teamBlue.getTeamKuerzel() + " vs. " + teamRed.getTeamKuerzel(), st.toString(), true);
});
MessageBuilder messageBuilder = new MessageBuilder();
MessageCreateBuilder messageBuilder = new MessageCreateBuilder();
messageBuilder.setEmbeds(embedBuilder.build());
if (message == null) {
textChannel.sendMessage(messageBuilder.build()).queue(message1 -> message = message1);
} else {
message.editMessage(messageBuilder.build()).complete();
message.editMessage(MessageEditData.fromCreateData(messageBuilder.build())).complete();
}
}

Datei anzeigen

@ -25,9 +25,10 @@ import de.steamwar.bungeecore.commands.CheckCommand;
import de.steamwar.sql.SteamwarUser;
import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageEditData;
import java.awt.*;
@ -40,7 +41,7 @@ public class SchematicsManager {
static {
textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.SCHEMATICS_CHANNEL);
assert textChannel != null;
if(textChannel.hasLatestMessage()) {
if(textChannel.getLatestMessageIdLong() != 0) {
message = textChannel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
}
}
@ -62,12 +63,12 @@ public class SchematicsManager {
embedBuilder.addField(schematic.getName(), st.toString(), true);
});
MessageBuilder messageBuilder = new MessageBuilder();
MessageCreateBuilder messageBuilder = new MessageCreateBuilder();
messageBuilder.setEmbeds(embedBuilder.build());
if (message == null) {
textChannel.sendMessage(messageBuilder.build()).queue(message1 -> message = message1);
} else {
message.editMessage(messageBuilder.build()).queue();
message.editMessage(MessageEditData.fromCreateData(messageBuilder.build())).queue();
}
}
}

Datei anzeigen

@ -22,15 +22,18 @@ package de.steamwar.bungeecore.bot.listeners;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import org.jetbrains.annotations.NotNull;
public class AnnouncementListener extends BasicDiscordListener {
@Override
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
if(!event.isFromGuild()) {
return;
}
if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.ANNOUNCEMENTS_CHANNEL)) {
return;
}
@ -43,8 +46,8 @@ public class AnnouncementListener extends BasicDiscordListener {
public void announce(String message) {
TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ANNOUNCEMENTS_CHANNEL);
assert textChannel != null;
MessageBuilder messageBuilder = new MessageBuilder();
messageBuilder.append(message.replace("&", ""));
MessageCreateBuilder messageBuilder = new MessageCreateBuilder();
messageBuilder.setContent(message.replace("&", ""));
textChannel.sendMessage(messageBuilder.build()).queue();
}
}

Datei anzeigen

@ -22,8 +22,8 @@ package de.steamwar.bungeecore.bot.listeners;
import de.steamwar.bungeecore.bot.AuthManager;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import de.steamwar.sql.SteamwarUser;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent;
import net.dv8tion.jda.api.interactions.InteractionType;
import org.jetbrains.annotations.NotNull;

Datei anzeigen

@ -25,10 +25,10 @@ import de.steamwar.bungeecore.listeners.ChatListener;
import de.steamwar.sql.Punishment;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.messages.ChatSender;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
@ -48,7 +48,10 @@ public class DiscordChatListener extends BasicDiscordListener {
}
@Override
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
if(!event.isFromGuild()) {
return;
}
if (!event.getChannel().getId().equals(channel) || event.getAuthor().isBot())
return;
@ -64,8 +67,8 @@ public class DiscordChatListener extends BasicDiscordListener {
public void send(String message) {
TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(channel);
assert textChannel != null;
MessageBuilder messageBuilder = new MessageBuilder();
messageBuilder.append(message.replace("&", "").replace("@everyone", "`@everyone`").replace("@here", "`@here`").replaceAll("<[@#]!?\\d+>", "`$0`"));
MessageCreateBuilder messageBuilder = new MessageCreateBuilder();
messageBuilder.setContent(message.replace("&", "").replace("@everyone", "`@everyone`").replace("@here", "`@here`").replaceAll("<[@#]!?\\d+>", "`$0`"));
textChannel.sendMessage(messageBuilder.build()).queue();
}
}

Datei anzeigen

@ -25,7 +25,7 @@ import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.Team;
import de.steamwar.sql.TeamTeilnahme;
import de.steamwar.sql.Event;
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
import net.dv8tion.jda.api.interactions.components.Component;
import org.jetbrains.annotations.NotNull;
@ -35,8 +35,8 @@ 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) {
public void onStringSelectInteraction(@NotNull StringSelectInteractionEvent event) {
if(event.getChannel().getId().equals(SteamwarDiscordBotConfig.EVENTS_CHANNEL) && event.getComponentType() == Component.Type.STRING_SELECT) {
if(event.getSelectedOptions().isEmpty()) {
event.deferReply(true).queue();
return;

Datei anzeigen

@ -25,18 +25,22 @@ import de.steamwar.bungeecore.bot.config.DiscordTicketType;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import de.steamwar.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.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.Category;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
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.buttons.Button;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.md_5.bungee.api.chat.ClickEvent;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.awt.Color;
import java.time.Instant;
import java.util.LinkedList;
@ -44,22 +48,21 @@ public class DiscordTicketListener extends BasicDiscordListener {
@Override
public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) {
if(event.getType() == InteractionType.COMPONENT && event.getChannelType() == ChannelType.TEXT && event.getTextChannel().getParent() != null && event.getTextChannel().getParent().getId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) {
if(event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && SteamwarDiscordBotConfig.TICKET_TYPES.containsKey(event.getComponentId())) {
if(event.getType() == InteractionType.COMPONENT && event.getChannelType() == ChannelType.TEXT && event.getChannel().asTextChannel().getParentCategoryIdLong() != 0 && event.getChannel().asTextChannel().getParentCategoryId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) {
if(event.getChannel().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);
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,
ticketChannel.upsertPermissionOverride(event.getMember()).setAllowed(Permission.VIEW_CHANNEL,
Permission.MESSAGE_SEND,
Permission.MESSAGE_ATTACH_FILES,
Permission.MESSAGE_ADD_REACTION,
Permission.MESSAGE_READ,
Permission.MESSAGE_EMBED_LINKS,
Permission.MESSAGE_HISTORY).complete();
ticketChannel.getManager().setTopic(event.getUser().getId()).complete();
MessageBuilder messageBuilder = new MessageBuilder();
MessageCreateBuilder messageBuilder = new MessageCreateBuilder();
EmbedBuilder builder = new EmbedBuilder();
builder.setDescription(ticketType.getPreMessage());
builder.setTitle("Steamwar Ticket");
@ -67,7 +70,7 @@ public class DiscordTicketListener extends BasicDiscordListener {
Button closeButton = Button.danger("close-" + ticketChannel.getName(), "Schließen").withEmoji(Emoji.fromUnicode("U+26A0"));
messageBuilder.setEmbeds(builder.build());
messageBuilder.setActionRows(ActionRow.of(closeButton));
messageBuilder.setComponents(ActionRow.of(closeButton));
ticketChannel.sendMessage(messageBuilder.build()).complete();
event.reply(SteamwarDiscordBotConfig.TICKET_CREATED.replace("%channel%", ticketChannel.getAsMention())).setEphemeral(true).complete();
@ -78,7 +81,7 @@ public class DiscordTicketListener extends BasicDiscordListener {
LinkedList<StringBuilder> stringBuilders = new LinkedList<>();
stringBuilders.add(new StringBuilder());
new LinkedList<>(event.getTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> {
new LinkedList<>(event.getChannel().asTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> {
if(message.getAuthor().isSystem() || message.getAuthor().isBot()) return;
StringBuilder currentBuilder = new StringBuilder();
currentBuilder.append("<t:").append(message.getTimeCreated().toInstant().getEpochSecond()).append("> ")
@ -112,39 +115,42 @@ public class DiscordTicketListener extends BasicDiscordListener {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(Color.GREEN);
User user = event.getJDA().retrieveUserById(event.getTextChannel().getTopic()).complete();
User user = event.getJDA().retrieveUserById(event.getChannel().asTextChannel().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.setTitle(event.getChannel().asTextChannel().getName());
stringBuilders.forEach(stringBuilder -> {
embedBuilder.setDescription(stringBuilder.toString());
MessageBuilder builder = new MessageBuilder();
MessageCreateBuilder builder = new MessageCreateBuilder();
builder.setEmbeds(embedBuilder.build());
logChannel.sendMessage(builder.build()).queue();
});
Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName());
event.getTextChannel().delete().reason("Closed").queue();
Message.team("DISCORD_TICKET_CLOSED", event.getChannel().getName());
event.getChannel().asTextChannel().delete().reason("Closed").queue();
}
}
}
@Override
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
if(event.getChannel().getParent() != null && event.getChannel().getParent().getId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) {
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
if(!event.isFromGuild()) {
return;
}
if(event.getChannel().asTextChannel().getParentCategoryIdLong() != 0 && event.getChannel().asTextChannel().getParentCategoryId().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.getUniqueId());
boolean sendMessage;
if(user.getDiscordId() == null) {
sendMessage = user.getUserGroup().isCheckSchematics();
sendMessage = user.getUserGroup().isCheckSchematics();
} else {
if(event.getAuthor().getId().equals(user.getDiscordId())) return;
sendMessage = user.getDiscordId().equals(event.getChannel().getTopic()) || user.getUserGroup().isCheckSchematics();
if(event.getAuthor().getIdLong() == user.getDiscordId()) return;
sendMessage = user.getDiscordId().toString().equals(event.getChannel().asTextChannel().getTopic()) || user.getUserGroup().isCheckSchematics();
}
if(sendMessage) {
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());

Datei anzeigen

@ -24,14 +24,20 @@ import de.steamwar.sql.Punishment;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.jetbrains.annotations.NotNull;
import java.io.InputStream;
public class PrivateMessageListener extends BasicDiscordListener {
@Override
public void onPrivateMessageReceived(PrivateMessageReceivedEvent event) {
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
if(!event.isFromType(ChannelType.PRIVATE)) {
return;
}
if(!event.getMessage().getAttachments().isEmpty()) {
SteamwarUser user = SteamwarUser.get(event.getAuthor().getIdLong());
if (user == null) {
@ -47,7 +53,7 @@ public class PrivateMessageListener extends BasicDiscordListener {
for (Message.Attachment attachment : event.getMessage().getAttachments()) {
if(attachment.getFileExtension() == null ||
(!attachment.getFileExtension().equalsIgnoreCase("schem") &&
!attachment.getFileExtension().equalsIgnoreCase("schematic"))) {
!attachment.getFileExtension().equalsIgnoreCase("schematic"))) {
event.getMessage().reply("`" + attachment.getFileName() + "` wird ignoriert, da die Datei keine Schematic ist").queue();
continue;
}

Datei anzeigen

@ -20,16 +20,17 @@
package de.steamwar.bungeecore.bot.listeners;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent;
import net.dv8tion.jda.api.interactions.InteractionType;
import org.jetbrains.annotations.NotNull;
public class RolesInteractionButtonListener extends BasicDiscordListener {
@Override
public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) {
if(event.getType() == InteractionType.COMPONENT && event.getChannelType() == ChannelType.TEXT && event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.ROLES_CHANNEL) && SteamwarDiscordBotConfig.ROLES.stream().anyMatch(discordRole -> discordRole.getRoleId().equals(event.getComponentId()))) {
if(event.getType() == InteractionType.COMPONENT && event.getChannelType() == ChannelType.TEXT && event.getChannel().getId().equals(SteamwarDiscordBotConfig.ROLES_CHANNEL) && SteamwarDiscordBotConfig.ROLES.stream().anyMatch(discordRole -> discordRole.getRoleId().equals(event.getComponentId()))) {
if (event.getMember().getRoles().stream().anyMatch(role -> role.getId().equals(event.getComponentId()))) {
event.getGuild().removeRoleFromMember(event.getMember(), event.getGuild().getRoleById(event.getComponentId())).complete();
event.reply(SteamwarDiscordBotConfig.ROLES_REMOVED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).queue();

Datei anzeigen

@ -20,13 +20,13 @@
package de.steamwar.bungeecore.bot.listeners;
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull;
public class SlashCommandListener extends BasicDiscordListener {
@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
SteamwarDiscordBot.getDiscordCommandMap().get(event.getName()).run(event);
}
}

Datei anzeigen

@ -22,11 +22,12 @@ package de.steamwar.bungeecore.bot.util;
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.Button;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageEditData;
import java.util.ArrayList;
import java.util.List;
@ -39,17 +40,17 @@ public class DiscordRolesMessage {
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ROLES_CHANNEL);
assert channel != null;
MessageBuilder builder = new MessageBuilder();
MessageCreateBuilder builder = new MessageCreateBuilder();
builder.setContent(SteamwarDiscordBotConfig.ROLES_BASE_MESSAGE);
List<Button> buttons = new ArrayList<>();
SteamwarDiscordBotConfig.ROLES.forEach(discordRole -> buttons.add(discordRole.toButton()));
builder.setActionRows(ActionRow.of(buttons));
builder.setComponents(ActionRow.of(buttons));
if(channel.hasLatestMessage()) {
if(channel.getLatestMessageIdLong() != 0) {
channel.getIterableHistory().queue(messages -> {
Message message = messages.stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
if (message != null) {
message.editMessage(builder.build()).queue();
message.editMessage(MessageEditData.fromCreateData(builder.build())).queue();
} else {
channel.sendMessage(builder.build()).queue();
}

Datei anzeigen

@ -23,12 +23,13 @@ import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import lombok.experimental.UtilityClass;
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.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.Button;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageEditData;
import java.awt.*;
import java.util.ArrayList;
@ -41,7 +42,7 @@ public class DiscordRulesMessage {
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.RULES_CHANNEL);
assert channel != null;
Message message = null;
if(channel.hasLatestMessage()) {
if(channel.getLatestMessageIdLong() != 0) {
message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
}
@ -56,11 +57,11 @@ public class DiscordRulesMessage {
Button authButton = Button.primary("auth", Emoji.fromUnicode("U+2705")).withLabel("Minecraft verknüpfen");
MessageBuilder messageBuilder = new MessageBuilder();
MessageCreateBuilder messageBuilder = new MessageCreateBuilder();
messageBuilder.setEmbeds(builder.build());
messageBuilder.setActionRows(ActionRow.of(buttons), ActionRow.of(authButton));
messageBuilder.setComponents(ActionRow.of(buttons), ActionRow.of(authButton));
if (message != null) {
message.editMessage(messageBuilder.build()).queue();
message.editMessage(MessageEditData.fromCreateData(messageBuilder.build())).queue();
} else {
channel.sendMessage(messageBuilder.build()).queue();
}

Datei anzeigen

@ -24,11 +24,11 @@ import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import lombok.experimental.UtilityClass;
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.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.Button;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import java.awt.*;
import java.time.Instant;
@ -46,7 +46,7 @@ public class DiscordSchemAlert {
builder.setDescription("Deine Schematic **" + schematic.getName() + "** wurde abgelehnt. **Grund:** \n" + reason);
builder.setTimestamp(Instant.now());
MessageBuilder messageBuilder = new MessageBuilder();
MessageCreateBuilder messageBuilder = new MessageCreateBuilder();
messageBuilder.setEmbeds(builder.build());
try {
dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue();
@ -66,9 +66,9 @@ public class DiscordSchemAlert {
builder.setDescription("Deine Schematic **" + schematic.getName() + "** wurde angenommen.");
builder.setTimestamp(Instant.now());
MessageBuilder messageBuilder = new MessageBuilder();
MessageCreateBuilder messageBuilder = new MessageCreateBuilder();
messageBuilder.setEmbeds(builder.build());
messageBuilder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389"))));
messageBuilder.setComponents(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389"))));
try {
dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue();
} catch (Exception e) {

Datei anzeigen

@ -24,11 +24,12 @@ import de.steamwar.bungeecore.bot.config.DiscordTicketType;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.Button;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageEditData;
import java.awt.*;
import java.util.ArrayList;
@ -42,7 +43,7 @@ public class DiscordTicketMessage {
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.TICKET_CHANNEL);
assert channel != null;
Message message = null;
if(channel.hasLatestMessage()) {
if(channel.getLatestMessageIdLong() != 0) {
message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
}
@ -56,11 +57,11 @@ public class DiscordTicketMessage {
buttons.add(discordTicketTypes.stream().map(DiscordTicketType::toButton).collect(Collectors.toList()));
});
MessageBuilder messageBuilder = new MessageBuilder();
MessageCreateBuilder messageBuilder = new MessageCreateBuilder();
messageBuilder.setEmbeds(builder.build());
messageBuilder.setActionRows(buttons.stream().map(ActionRow::of).collect(Collectors.toList()));
messageBuilder.setComponents(buttons.stream().map(ActionRow::of).collect(Collectors.toList()));
if (message != null) {
message.editMessage(messageBuilder.build()).queue();
message.editMessage(MessageEditData.fromCreateData(messageBuilder.build())).queue();
} else {
channel.sendMessage(messageBuilder.build()).queue();
}

Datei anzeigen

@ -535,7 +535,7 @@ CHAT_EMPTY=§cDon't write meaningless empty messages.
CHAT_SERVERTEAM=§8STC §e{0}§8» §f{2}
CHAT_GLOBAL={3}{4}{5}{6}{0}§8» {7}{2}
CHAT_DISCORD_GLOBAL=§8Dc {5}{6}{0}§8» {7}{2}
CHAT_DISCORD_GLOBAL=§8§lDC {5}{6}{0}§8» {7}{2}
CHAT_TEAM=§8TC §e{0}§8» §f{2}
CHAT_MSG=§e{0}§8»§e{1} §7{2}

Datei anzeigen

@ -514,7 +514,7 @@ CHAT_EMPTY=§cSchreibe keine inhaltslosen Nachrichten.
CHAT_SERVERTEAM=§8STC §e{0}§8» §f{2}
CHAT_GLOBAL={3}{4}{5}{6}{0}§8» {7}{2}
CHAT_DISCORD_GLOBAL=§8Dc {5}{6}{0}§8» {7}{2}
CHAT_DISCORD_GLOBAL=§8§lDC {5}{6}{0}§8» {7}{2}
CHAT_TEAM=§8TC §e{0}§8» §f{2}
CHAT_MSG=§e{0}§8»§e{1} §7{2}