WIP: Port Discord Bot to JDA 5.0 #462
@ -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'
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -76,11 +76,7 @@ public class SteamwarDiscordBot {
|
||||
JDABuilder builder = JDABuilder.createDefault(SteamwarDiscordBotConfig.TOKEN);
|
||||
builder.setStatus(OnlineStatus.ONLINE);
|
||||
builder.setMemberCachePolicy(MemberCachePolicy.ONLINE);
|
||||
try {
|
||||
jda = builder.build();
|
||||
} catch (LoginException e) {
|
||||
throw new SecurityException("Could not Login: " + SteamwarDiscordBotConfig.TOKEN, e);
|
||||
}
|
||||
jda = builder.build();
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
||||
try {
|
||||
jda.awaitReady();
|
||||
@ -131,8 +127,8 @@ public class SteamwarDiscordBot {
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren