geforkt von SteamWar/BungeeCore
Discord Ticket System
Dieser Commit ist enthalten in:
Ursprung
eda6a199fa
Commit
22523fa5be
@ -22,7 +22,9 @@ package de.steamwar.bungeecore.bot;
|
|||||||
import de.steamwar.bungeecore.BungeeCore;
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
import de.steamwar.bungeecore.bot.events.EventManager;
|
import de.steamwar.bungeecore.bot.events.EventManager;
|
||||||
|
import de.steamwar.bungeecore.bot.listeners.DiscordTicketListener;
|
||||||
import de.steamwar.bungeecore.bot.listeners.RolesInteractionButtonListener;
|
import de.steamwar.bungeecore.bot.listeners.RolesInteractionButtonListener;
|
||||||
|
import de.steamwar.bungeecore.bot.util.DiscordTicketMessage;
|
||||||
import de.steamwar.bungeecore.bot.util.DiscordRolesMessage;
|
import de.steamwar.bungeecore.bot.util.DiscordRolesMessage;
|
||||||
import de.steamwar.bungeecore.bot.util.DiscordRulesMessage;
|
import de.steamwar.bungeecore.bot.util.DiscordRulesMessage;
|
||||||
import de.steamwar.bungeecore.sql.Event;
|
import de.steamwar.bungeecore.sql.Event;
|
||||||
@ -70,8 +72,10 @@ public class SteamwarDiscordBot {
|
|||||||
}, 30, 30, TimeUnit.SECONDS);
|
}, 30, 30, TimeUnit.SECONDS);
|
||||||
DiscordRolesMessage.sendMessage();
|
DiscordRolesMessage.sendMessage();
|
||||||
DiscordRulesMessage.sendMessage();
|
DiscordRulesMessage.sendMessage();
|
||||||
|
DiscordTicketMessage.sendMessage();
|
||||||
|
|
||||||
new RolesInteractionButtonListener();
|
new RolesInteractionButtonListener();
|
||||||
|
new DiscordTicketListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
@ -83,11 +87,11 @@ public class SteamwarDiscordBot {
|
|||||||
if (event != null) {
|
if (event != null) {
|
||||||
jda.getPresence().setActivity(Activity.competing("dem Event " + event.getEventName()));
|
jda.getPresence().setActivity(Activity.competing("dem Event " + event.getEventName()));
|
||||||
} else {
|
} else {
|
||||||
jda.getPresence().setActivity(Activity.playing("SteamWar.de"));
|
jda.getPresence().setActivity(Activity.playing("auf SteamWar.de"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
jda.getPresence().setActivity(Activity.playing("Online: " + BungeeCore.get().getProxy().getOnlineCount()));
|
jda.getPresence().setActivity(Activity.playing("mit " + BungeeCore.get().getProxy().getOnlineCount() + " Spielern"));
|
||||||
index = 0;
|
index = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
41
src/de/steamwar/bungeecore/bot/config/DiscordTicketType.java
Normale Datei
41
src/de/steamwar/bungeecore/bot/config/DiscordTicketType.java
Normale Datei
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.bot.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;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DiscordTicketType {
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
private String emoji;
|
||||||
|
private String label;
|
||||||
|
private String color;
|
||||||
|
private String preMessage;
|
||||||
|
|
||||||
|
public Button toButton() {
|
||||||
|
return Button.of(ButtonStyle.valueOf(color), key, Emoji.fromUnicode(emoji)).withLabel(label);
|
||||||
|
}
|
||||||
|
}
|
@ -22,7 +22,9 @@ package de.steamwar.bungeecore.bot.config;
|
|||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class SteamwarDiscordBotConfig {
|
public class SteamwarDiscordBotConfig {
|
||||||
|
|
||||||
@ -38,6 +40,12 @@ public class SteamwarDiscordBotConfig {
|
|||||||
public static String RULES_TITLE;
|
public static String RULES_TITLE;
|
||||||
public static List<String> RULES_RULES;
|
public static List<String> RULES_RULES;
|
||||||
public static List<DiscordRulesLink> RULES_LINKS;
|
public static List<DiscordRulesLink> RULES_LINKS;
|
||||||
|
public static String TICKET_CATEGORY;
|
||||||
|
public static String TICKET_CHANNEL;
|
||||||
|
public static String TICKET_MESSAGE;
|
||||||
|
public static String TICKET_CREATED;
|
||||||
|
public static String TICKET_LOG;
|
||||||
|
public static Map<String, DiscordTicketType> TICKET_TYPES;
|
||||||
|
|
||||||
public static void loadConfig(Configuration config) {
|
public static void loadConfig(Configuration config) {
|
||||||
TOKEN = config.getString("token");
|
TOKEN = config.getString("token");
|
||||||
@ -69,5 +77,22 @@ public class SteamwarDiscordBotConfig {
|
|||||||
RULES_LINKS.add(new DiscordRulesLink(link.getString("label"),
|
RULES_LINKS.add(new DiscordRulesLink(link.getString("label"),
|
||||||
link.getString("url")));
|
link.getString("url")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Configuration ticketSection = config.getSection("tickets");
|
||||||
|
TICKET_CATEGORY = ticketSection.getString("category");
|
||||||
|
TICKET_CHANNEL = ticketSection.getString("channel");
|
||||||
|
TICKET_MESSAGE = ticketSection.getString("message");
|
||||||
|
TICKET_CREATED = ticketSection.getString("created");
|
||||||
|
TICKET_LOG = ticketSection.getString("log");
|
||||||
|
TICKET_TYPES = new HashMap<>();
|
||||||
|
|
||||||
|
for (String types : ticketSection.getSection("types").getKeys()) {
|
||||||
|
Configuration type = ticketSection.getSection("types").getSection(types);
|
||||||
|
TICKET_TYPES.put(types, new DiscordTicketType(types,
|
||||||
|
type.getString("emoji"),
|
||||||
|
type.getString("label"),
|
||||||
|
type.getString("color"),
|
||||||
|
type.getString("pre")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
106
src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java
Normale Datei
106
src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java
Normale Datei
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.bot.listeners;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.config.DiscordTicketType;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
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.interactions.InteractionType;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
|
import net.dv8tion.jda.api.requests.restaction.MessageAction;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.io.File;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DiscordTicketListener extends BasicDiscordListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) {
|
||||||
|
if(event.getType() == InteractionType.COMPONENT && event.getTextChannel().getParent().getId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) {
|
||||||
|
if(event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && SteamwarDiscordBotConfig.TICKET_TYPES.containsKey(event.getComponentId())) {
|
||||||
|
DiscordTicketType ticketType = SteamwarDiscordBotConfig.TICKET_TYPES.get(event.getComponentId());
|
||||||
|
Category ct = event.getGuild().getCategoryById(SteamwarDiscordBotConfig.TICKET_CATEGORY);
|
||||||
|
TextChannel ticketChannel = ct.createTextChannel(event.getUser().getName() + "-" + event.getComponentId() + "-" + System.currentTimeMillis() % 1000).complete();
|
||||||
|
ticketChannel.createPermissionOverride(event.getMember()).setAllow(Permission.VIEW_CHANNEL,
|
||||||
|
Permission.MESSAGE_WRITE,
|
||||||
|
Permission.MESSAGE_ATTACH_FILES,
|
||||||
|
Permission.MESSAGE_ADD_REACTION,
|
||||||
|
Permission.MESSAGE_READ,
|
||||||
|
Permission.MESSAGE_EMBED_LINKS,
|
||||||
|
Permission.MESSAGE_HISTORY).complete();
|
||||||
|
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
|
builder.setDescription(ticketType.getPreMessage());
|
||||||
|
builder.setTitle("Steamwar Ticket");
|
||||||
|
builder.setColor(Color.GREEN);
|
||||||
|
|
||||||
|
Button closeButton = Button.danger("close-" + ticketChannel.getName(), "Schliesen").withEmoji(Emoji.fromUnicode("U+26A0"));
|
||||||
|
messageBuilder.setEmbeds(builder.build());
|
||||||
|
messageBuilder.setActionRows(ActionRow.of(closeButton));
|
||||||
|
|
||||||
|
ticketChannel.sendMessage(messageBuilder.build()).complete();
|
||||||
|
event.reply(SteamwarDiscordBotConfig.TICKET_CREATED.replace("%channel%", ticketChannel.getAsMention())).setEphemeral(true).complete();
|
||||||
|
} else if(event.getComponentId().startsWith("close-")) {
|
||||||
|
TextChannel logChannel = event.getGuild().getTextChannelById(SteamwarDiscordBotConfig.TICKET_LOG);
|
||||||
|
|
||||||
|
MessageBuilder builder = new MessageBuilder();
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
new LinkedList<>(event.getTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> {
|
||||||
|
stringBuilder.append("<t:").append(message.getTimeCreated().toInstant().getEpochSecond()).append("> ")
|
||||||
|
.append("**")
|
||||||
|
.append(message.getAuthor().getName())
|
||||||
|
.append("**: ")
|
||||||
|
.append(message.getContentRaw());
|
||||||
|
if(!message.getAttachments().isEmpty()) {
|
||||||
|
stringBuilder.append("\n")
|
||||||
|
.append("Files: ").append("\n");
|
||||||
|
message.getAttachments().forEach(attachment -> stringBuilder.append(attachment.getUrl()).append("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append("\n");
|
||||||
|
});
|
||||||
|
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||||
|
embedBuilder.setColor(Color.GREEN);
|
||||||
|
embedBuilder.setTimestamp(Instant.now());
|
||||||
|
embedBuilder.setTitle(event.getTextChannel().getName());
|
||||||
|
embedBuilder.setDescription(stringBuilder);
|
||||||
|
|
||||||
|
builder.setEmbeds(embedBuilder.build());
|
||||||
|
|
||||||
|
logChannel.sendMessage(builder.build()).complete();
|
||||||
|
|
||||||
|
event.getTextChannel().delete().reason("Closed").complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java
Normale Datei
56
src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java
Normale Datei
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.bot.util;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DiscordTicketMessage {
|
||||||
|
|
||||||
|
public static void sendMessage() {
|
||||||
|
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.TICKET_CHANNEL);
|
||||||
|
assert channel != null;
|
||||||
|
if(channel.hasLatestMessage()) {
|
||||||
|
channel.getIterableHistory().complete().forEach(message -> message.delete().complete());
|
||||||
|
}
|
||||||
|
|
||||||
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
|
builder.setDescription(SteamwarDiscordBotConfig.TICKET_MESSAGE);
|
||||||
|
builder.setTitle("Steamwar-Tickets");
|
||||||
|
builder.setColor(Color.RED);
|
||||||
|
|
||||||
|
List<Button> buttons = new ArrayList<>();
|
||||||
|
SteamwarDiscordBotConfig.TICKET_TYPES.forEach((s, discordTicketType) -> buttons.add(discordTicketType.toButton()));
|
||||||
|
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
messageBuilder.setEmbeds(builder.build());
|
||||||
|
messageBuilder.setActionRows(ActionRow.of(buttons));
|
||||||
|
channel.sendMessage(messageBuilder.build()).complete();
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren