Merge branch 'dev/update' into forums
# Conflicts: # build.gradle.kts # src/main/java/com/alttd/AltitudeBot.java # src/main/java/com/alttd/commandManager/commands/AddCommand/CommandManage.java # src/main/java/com/alttd/commandManager/commands/AddCommand/SubCommandGroupSet.java # src/main/java/com/alttd/commandManager/commands/AddCommand/SubCommandGroupUnset.java # src/main/java/com/alttd/commandManager/commands/CommandHelp.java # src/main/java/com/alttd/commandManager/commands/PollCommand/CommandPoll.java # src/main/java/com/alttd/listeners/JDAListener.java
This commit is contained in:
commit
e8a92c9995
|
|
@ -38,22 +38,18 @@ tasks {
|
|||
}
|
||||
}
|
||||
|
||||
// create<ConfigureShadowRelocation>("relocateJars") {
|
||||
// target = shadowJar.get()
|
||||
// prefix = "${project.name}.lib"
|
||||
// }
|
||||
//
|
||||
// shadowJar {
|
||||
// dependsOn(getByName("relocateJars") as ConfigureShadowRelocation)
|
||||
// archiveFileName.set("${project.name}-${project.version}.jar")
|
||||
// minimize()
|
||||
// configurations = listOf(project.configurations.shadow.get())
|
||||
// }
|
||||
//
|
||||
shadowJar {
|
||||
archiveFileName.set(rootProject.name + ".jar")
|
||||
}
|
||||
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
|
||||
jar {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
|
|||
34
example.requests.yml
Normal file
34
example.requests.yml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
request:
|
||||
guild: '776590138296893480'
|
||||
category: '776590138296893481'
|
||||
channel: '1017787342561476709'
|
||||
message: '1017839462111256667'
|
||||
types:
|
||||
bug-report:
|
||||
category: '776590138296893481'
|
||||
channel: '820222354180800525'
|
||||
name: Bug report
|
||||
title: What should the title be?
|
||||
description: Report a new bug.
|
||||
message: Describe the bug.
|
||||
act-request:
|
||||
category: '776590138296893481'
|
||||
channel: '820222354180800525'
|
||||
name: Act request
|
||||
title: What should the title be?
|
||||
description: Make a new act request.
|
||||
message: Describe the act request.
|
||||
admin-act-request:
|
||||
category: '776590138296893481'
|
||||
channel: '820222354180800525'
|
||||
name: Admin act request
|
||||
title: What should the title be?
|
||||
description: Make a new admin act request.
|
||||
message: Describe the admin act request.
|
||||
feature-request:
|
||||
category: '776590138296893481'
|
||||
channel: '820222354180800525'
|
||||
name: Feature request
|
||||
title: What should the title be?
|
||||
description: Make a new feature request.
|
||||
message: Describe the feature request.
|
||||
|
|
@ -32,7 +32,25 @@ public class AltitudeBot {
|
|||
initConfigs();
|
||||
ConsoleCommandManager.startConsoleCommands(jda);
|
||||
jda = JDABuilder.createDefault(SettingsConfig.TOKEN).build();
|
||||
try {
|
||||
jda = JDABuilder.createDefault(SettingsConfig.TOKEN).build().awaitReady();
|
||||
} catch (LoginException e) {
|
||||
Logger.info("Unable to log in, shutting down (check token in settings.yml).");
|
||||
exit(1);
|
||||
Logger.exception(e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
DatabaseTables.createTables(Database.getDatabase().getConnection());
|
||||
ConsoleCommandManager.startConsoleCommands(jda);
|
||||
try {
|
||||
jda.getPresence().setPresence(
|
||||
OnlineStatus.valueOf(SettingsConfig.STATUS),
|
||||
Activity.listening(SettingsConfig.ACTIVITY));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Logger.exception(e);
|
||||
}
|
||||
RequestManager.init();
|
||||
// try {
|
||||
// jda.getPresence().setPresence(
|
||||
// OnlineStatus.valueOf(SettingsConfig.STATUS),
|
||||
|
|
|
|||
|
|
@ -22,14 +22,14 @@ import java.util.Map;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
@SuppressWarnings({"unused", "SameParameterValue"})
|
||||
abstract class AbstractConfig {
|
||||
public abstract class AbstractConfig {
|
||||
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
|
||||
private static final String HEADER = "";
|
||||
|
||||
private YamlConfigurationLoader configLoader;
|
||||
private ConfigurationNode config;
|
||||
|
||||
AbstractConfig(String filename) {
|
||||
protected AbstractConfig(String filename) {
|
||||
init(new File(new File(AltitudeBot.getInstance().getDataFolder()).getParentFile(), filename), filename);
|
||||
}
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ abstract class AbstractConfig {
|
|||
}
|
||||
}
|
||||
|
||||
void readConfig(Class<?> clazz, Object instance) {
|
||||
protected void readConfig(Class<?> clazz, Object instance) {
|
||||
for (Method method : clazz.getDeclaredMethods()) {
|
||||
if (Modifier.isPrivate(method.getModifiers())) {
|
||||
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
|
||||
|
|
@ -80,7 +80,7 @@ abstract class AbstractConfig {
|
|||
save();
|
||||
}
|
||||
|
||||
private void save() {
|
||||
protected void save() {
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException ex) {
|
||||
|
|
@ -101,6 +101,17 @@ abstract class AbstractConfig {
|
|||
}
|
||||
}
|
||||
|
||||
protected void update(String path, Object def) {
|
||||
if(config.node(splitPath(path)).virtual()) {
|
||||
set(path, def);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
config.node(splitPath(path)).set(def);
|
||||
} catch (SerializationException e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void setString(String path, String def) {
|
||||
try {
|
||||
if(config.node(splitPath(path)).virtual())
|
||||
|
|
|
|||
|
|
@ -3,9 +3,14 @@ package com.alttd.listeners;
|
|||
import com.alttd.buttonManager.ButtonManager;
|
||||
import com.alttd.commandManager.CommandManager;
|
||||
import com.alttd.modalManager.ModalManager;
|
||||
import com.alttd.request.RequestManager;
|
||||
import com.alttd.util.Logger;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
|
@ -26,4 +31,28 @@ public class JDAListener extends ListenerAdapter {
|
|||
jda.addEventListener(buttonManager, modalManager, commandManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectMenuInteraction(@NotNull SelectMenuInteractionEvent event) {
|
||||
String s = event.getComponentId();
|
||||
if (s.startsWith("request:")) {
|
||||
RequestManager.onSelectMenuInteraction(event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModalInteraction(@NotNull ModalInteractionEvent event) {
|
||||
String s = event.getModalId();
|
||||
if (s.startsWith("request:")) {
|
||||
RequestManager.onModalInteractionEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onButtonInteraction(ButtonInteractionEvent event) {
|
||||
String s = event.getComponentId();
|
||||
if (s.startsWith("request:")) {
|
||||
RequestManager.onButtonInteractionEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
88
src/main/java/com/alttd/request/Request.java
Normal file
88
src/main/java/com/alttd/request/Request.java
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
package com.alttd.request;
|
||||
|
||||
import com.alttd.AltitudeBot;
|
||||
import com.alttd.util.Pair;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.ThreadChannel;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.Modal;
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
||||
import net.dv8tion.jda.api.interactions.components.text.TextInput;
|
||||
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
|
||||
import net.dv8tion.jda.api.requests.restaction.ThreadChannelAction;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class Request {
|
||||
// TODO check if all labels on the modal are max 45 in length
|
||||
@Getter
|
||||
private String id, category, channel, name, title, description, message;
|
||||
|
||||
public Modal modal(Member member) {
|
||||
TextInput requestTitle = TextInput
|
||||
.create("title", title, TextInputStyle.SHORT)
|
||||
.setPlaceholder(id)
|
||||
.setRequired(false)
|
||||
.build();
|
||||
|
||||
TextInput requestMessage = TextInput
|
||||
.create("request", message, TextInputStyle.PARAGRAPH)
|
||||
.build();
|
||||
|
||||
return Modal.create("request:" + id, name)
|
||||
.addActionRow(requestTitle)
|
||||
.addActionRow(requestMessage)
|
||||
.build();
|
||||
}
|
||||
|
||||
public void createThread(Member member, String title, String request) {
|
||||
TextChannel channel = AltitudeBot.getInstance().getJDA().getGuildById(RequestConfig.REQUEST_GUILD_ID).getTextChannelById(getChannel());
|
||||
if (title == null || title.isEmpty()) title = id;
|
||||
String finalTitle = title;
|
||||
ThreadChannelAction threadChannelAction = channel.createThreadChannel(finalTitle);
|
||||
threadChannelAction.queue(threadChannel -> {
|
||||
threadChannel.addThreadMember(member).queue();
|
||||
sendEmbed(threadChannel, finalTitle, request);
|
||||
channel.deleteMessageById(threadChannel.getId()).queue();
|
||||
// TODO store the request somewhere so it can be grabbed later
|
||||
});
|
||||
}
|
||||
|
||||
public void sendEmbed(ThreadChannel channel, String title, String request) {
|
||||
// Pair<EmbedBuilder, ActionRow> pair = getRequestEmbed(channel.getId(), title, request);
|
||||
// pairs are not really possible here :(
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setTitle(title)
|
||||
.addField(getName(), request, false)
|
||||
.setColor(new Color(41, 43, 47));
|
||||
channel.sendMessageEmbeds(embedBuilder.build()).queue(message1 ->
|
||||
channel.editMessageEmbedsById(message1.getId(), embedBuilder.build())
|
||||
.setActionRow(
|
||||
Button.primary("request:" + getId() + ":" + channel.getId() + ":" + message1.getId() + ":progress", "in progress"),
|
||||
Button.success("request:" + getId() + ":" + channel.getId() + ":" + message1.getId() + ":complete", "complete"),
|
||||
Button.danger("request:" + getId() + ":" + channel.getId() + ":" + message1.getId() + ":denied", "denied")
|
||||
).queue()
|
||||
);
|
||||
}
|
||||
|
||||
public Pair<EmbedBuilder, ActionRow> getRequestEmbed(String channellId, String title, String request) {
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setTitle("title")
|
||||
.addField(getName(), request, false)
|
||||
.setColor(new Color(41, 43, 47));
|
||||
|
||||
ActionRow actionRow = ActionRow.of(
|
||||
Button.primary("request:" + getId() + ":" + channellId + ":progress", "in progress"),
|
||||
Button.success("request:" + getId() + ":" + channellId + ":complete", "complete"),
|
||||
Button.danger("request:" + getId() + ":" + channellId + ":denied", "denied")
|
||||
);
|
||||
|
||||
return new Pair<>(embedBuilder, actionRow);
|
||||
}
|
||||
|
||||
}
|
||||
58
src/main/java/com/alttd/request/RequestConfig.java
Normal file
58
src/main/java/com/alttd/request/RequestConfig.java
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package com.alttd.request;
|
||||
|
||||
import com.alttd.config.AbstractConfig;
|
||||
import com.alttd.util.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RequestConfig extends AbstractConfig {
|
||||
|
||||
static RequestConfig requestConfig;
|
||||
|
||||
public RequestConfig() {
|
||||
super("requests.yml");
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
requestConfig = new RequestConfig();
|
||||
requestConfig.readConfig(RequestConfig.class, requestConfig);
|
||||
}
|
||||
|
||||
public static String REQUEST_GUILD_ID = "776590138296893480";
|
||||
public static String REQUEST_CATEGORY = "776590138296893481";
|
||||
public static String REQUEST_CHANNEL = "1017787342561476709";
|
||||
public static String REQUEST_MESSAGE = "";
|
||||
private void settings() {
|
||||
REQUEST_GUILD_ID = requestConfig.getString("request.guild", REQUEST_GUILD_ID);
|
||||
REQUEST_CATEGORY = requestConfig.getString("request.category", REQUEST_CATEGORY);
|
||||
REQUEST_CHANNEL = requestConfig.getString("request.channel", REQUEST_CHANNEL);
|
||||
REQUEST_MESSAGE = requestConfig.getString("request.message", REQUEST_MESSAGE);
|
||||
}
|
||||
|
||||
public static void setRequestMessage(String messageId) {
|
||||
REQUEST_MESSAGE = messageId;
|
||||
requestConfig.update("request.message", REQUEST_MESSAGE);
|
||||
requestConfig.save();
|
||||
}
|
||||
|
||||
public static final List<Request> requests = new ArrayList<>();
|
||||
private void loadRequests() {
|
||||
requests.clear();
|
||||
requestConfig.getNode("types").childrenMap().forEach((key, value) -> {
|
||||
String id = key.toString();
|
||||
String category = value.node("category").getString();
|
||||
String channel = value.node("channel").getString();
|
||||
String name = value.node("name").getString();
|
||||
String title = value.node("title").getString();
|
||||
String description = value.node("description").getString();
|
||||
String message = value.node("message").getString();
|
||||
if (id == null || category == null || channel == null || name == null || description == null || message == null) {
|
||||
Logger.warning("Requests are set up incorrectly!");
|
||||
} else {
|
||||
requests.add(new Request(id, category, channel, name, title, description, message));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
110
src/main/java/com/alttd/request/RequestManager.java
Normal file
110
src/main/java/com/alttd/request/RequestManager.java
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
package com.alttd.request;
|
||||
|
||||
import com.alttd.AltitudeBot;
|
||||
import com.alttd.util.Pair;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.ThreadChannel;
|
||||
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.components.selections.SelectMenu;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class RequestManager {
|
||||
|
||||
public static void init() {
|
||||
RequestConfig.reload();
|
||||
if (RequestConfig.REQUEST_MESSAGE == null || RequestConfig.REQUEST_MESSAGE.isEmpty())
|
||||
sendRequestMessage();
|
||||
}
|
||||
|
||||
public static Pair<EmbedBuilder, SelectMenu.Builder> getRequestEmbed() {
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
SelectMenu.Builder selectMenuBuilder = SelectMenu.create("request:create");
|
||||
embedBuilder.setDescription("Select an option below to open a request!\n")
|
||||
.setTitle("Create a new request.")
|
||||
.setColor(new Color(41, 43, 47));
|
||||
|
||||
for (Request request : RequestConfig.requests) {
|
||||
embedBuilder.addField(request.getName(), request.getDescription(), false);
|
||||
selectMenuBuilder.addOption(request.getName(), "request:open:" + request.getId(), request.getDescription(), null);
|
||||
}
|
||||
|
||||
return new Pair<>(embedBuilder, selectMenuBuilder);
|
||||
}
|
||||
|
||||
public static void sendRequestMessage() {
|
||||
TextChannel channel = AltitudeBot.getInstance().getJDA().getGuildById(RequestConfig.REQUEST_GUILD_ID).getTextChannelById(RequestConfig.REQUEST_CHANNEL);
|
||||
Pair<EmbedBuilder, SelectMenu.Builder> pair = getRequestEmbed();
|
||||
channel.sendMessageEmbeds(pair.getValue0().build()).setActionRow(
|
||||
pair.getValue1().build()
|
||||
).queue(m -> RequestConfig.setRequestMessage(m.getId()));
|
||||
}
|
||||
|
||||
public static void updateRequestMessage() {
|
||||
TextChannel channel = AltitudeBot.getInstance().getJDA().getGuildById(RequestConfig.REQUEST_GUILD_ID).getTextChannelById(RequestConfig.REQUEST_CHANNEL);
|
||||
Pair<EmbedBuilder, SelectMenu.Builder> pair = getRequestEmbed();
|
||||
channel.editMessageEmbedsById(RequestConfig.REQUEST_MESSAGE, pair.getValue0().build())
|
||||
.setActionRow(
|
||||
pair.getValue1().build()
|
||||
).queue(m -> RequestConfig.setRequestMessage(m.getId()));
|
||||
}
|
||||
|
||||
public static Request getRequestById(String id) {
|
||||
return RequestConfig.requests.stream().filter(request -> request.getId().equalsIgnoreCase(id)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static void onSelectMenuInteraction(SelectMenuInteractionEvent event) {
|
||||
String[] actions = event.getComponentId().split(":");
|
||||
if (actions[1].equals("create")) {
|
||||
String[] selection = event.getSelectedOptions().get(0).getValue().split(":");
|
||||
if (selection[0].equals("request") && selection[1].equals("open")) {
|
||||
String id = selection[2];
|
||||
event.replyModal(getRequestById(id).modal(event.getMember())).queue();
|
||||
updateRequestMessage(); // You can't use a select menu option twice in a row, updating it fixes that.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void onModalInteractionEvent(ModalInteractionEvent event) {
|
||||
String s = event.getModalId();
|
||||
String[] strings = s.split(":", 2);
|
||||
getRequestById(strings[1]).createThread(event.getMember(), event.getValue("title").getAsString(), event.getValue("request").getAsString());
|
||||
event.reply("Thanks for your request!").setEphemeral(true).queue();
|
||||
}
|
||||
|
||||
public static void onButtonInteractionEvent(ButtonInteractionEvent event) {
|
||||
String s = event.getComponentId();
|
||||
String[] strings = s.split(":", 5);
|
||||
String requestId = strings[1];
|
||||
String threadId = strings[2];
|
||||
String messageId = strings[3];
|
||||
String type = strings[4]; // progress, complete, denied
|
||||
|
||||
// TODO update the stored request in the database
|
||||
switch (type) {
|
||||
case "denied" -> {
|
||||
// TODO open a new modal to input a reason?
|
||||
// could also do this by command?
|
||||
event.reply("This request has been denied by " + event.getMember().getAsMention()).queue();
|
||||
ThreadChannel threadChannel = AltitudeBot.getInstance().getJDA().getGuildById(RequestConfig.REQUEST_GUILD_ID).getThreadChannelById(threadId);
|
||||
threadChannel.getManager().setArchived(true).setLocked(true).queue();
|
||||
}
|
||||
case "complete" -> {
|
||||
// TODO open a new modal to input a reason?
|
||||
// could also do this by command?
|
||||
event.reply("This request has been completed by " + event.getMember().getAsMention()).queue();
|
||||
ThreadChannel threadChannel = AltitudeBot.getInstance().getJDA().getGuildById(RequestConfig.REQUEST_GUILD_ID).getThreadChannelById(threadId);
|
||||
threadChannel.getManager().setArchived(true).setLocked(true).queue();
|
||||
}
|
||||
case "progress" -> {
|
||||
// TODO open a new modal to input a reason?
|
||||
// edit the message to show who is working on it?
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
21
src/main/java/com/alttd/util/Pair.java
Normal file
21
src/main/java/com/alttd/util/Pair.java
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package com.alttd.util;
|
||||
|
||||
public class Pair<X, Y> {
|
||||
|
||||
private final X x;
|
||||
private final Y y;
|
||||
|
||||
public Pair(X x, Y y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public X getValue0() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public Y getValue1() {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user