[FEAT] Initial preparations for custom embeds and custom message types
This commit is contained in:
@@ -100,7 +100,8 @@ shadowJar {
|
|||||||
relocate 'oshi', shade_group + 'oshi'
|
relocate 'oshi', shade_group + 'oshi'
|
||||||
relocate 'kotlin', shade_group + 'kotlin'
|
relocate 'kotlin', shade_group + 'kotlin'
|
||||||
relocate 'org.jasypt', shade_group + 'jasypt'
|
relocate 'org.jasypt', shade_group + 'jasypt'
|
||||||
relocate 'com.google', shade_group + 'google'
|
relocate 'com.google.common', shade_group + 'google.common'
|
||||||
|
relocate 'com.google.thirdparty', shade_group + 'google.thirdparty'
|
||||||
relocate 'edu', shade_group + 'edu'
|
relocate 'edu', shade_group + 'edu'
|
||||||
relocate 'io', shade_group + 'io'
|
relocate 'io', shade_group + 'io'
|
||||||
relocate 'javassist', shade_group + 'javassist'
|
relocate 'javassist', shade_group + 'javassist'
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
version_major=0
|
version_major=0
|
||||||
version_minor=0
|
version_minor=0
|
||||||
version_patch=10
|
version_patch=12
|
||||||
|
|
||||||
shade_group=com.hypherionmc.sdlink.shaded.
|
shade_group=com.hypherionmc.sdlink.shaded.
|
||||||
|
|
||||||
|
@@ -10,9 +10,11 @@ import com.hypherionmc.sdlink.core.discord.BotController;
|
|||||||
import com.hypherionmc.sdlink.core.managers.RoleManager;
|
import com.hypherionmc.sdlink.core.managers.RoleManager;
|
||||||
import com.hypherionmc.sdlink.core.messaging.Result;
|
import com.hypherionmc.sdlink.core.messaging.Result;
|
||||||
import com.hypherionmc.sdlink.core.services.SDLinkPlatform;
|
import com.hypherionmc.sdlink.core.services.SDLinkPlatform;
|
||||||
import com.hypherionmc.sdlink.core.util.SystemUtils;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
import net.dv8tion.jda.api.entities.UserSnowflake;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@@ -24,7 +24,7 @@ public class SDLinkConfig extends ModuleConfig {
|
|||||||
// DO NOT REMOVE TRANSIENT HERE... OTHERWISE, THE STUPID CONFIG LIBRARY
|
// DO NOT REMOVE TRANSIENT HERE... OTHERWISE, THE STUPID CONFIG LIBRARY
|
||||||
// WILL TRY TO WRITE THESE TO THE CONFIG
|
// WILL TRY TO WRITE THESE TO THE CONFIG
|
||||||
public transient static SDLinkConfig INSTANCE;
|
public transient static SDLinkConfig INSTANCE;
|
||||||
public transient static int configVer = 3;
|
public transient static int configVer = 5;
|
||||||
|
|
||||||
@Path("general")
|
@Path("general")
|
||||||
@SpecComment("General Mod Config")
|
@SpecComment("General Mod Config")
|
||||||
@@ -67,7 +67,7 @@ public class SDLinkConfig extends ModuleConfig {
|
|||||||
public MessageIgnoreConfig ignoreConfig = new MessageIgnoreConfig();
|
public MessageIgnoreConfig ignoreConfig = new MessageIgnoreConfig();
|
||||||
|
|
||||||
public SDLinkConfig() {
|
public SDLinkConfig() {
|
||||||
super("sdlink", "simple-discord-link");
|
super("sdlink", "simple-discord-link", "simple-discord-link");
|
||||||
registerAndSetup(this);
|
registerAndSetup(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,27 +16,31 @@ public class MessageChannelConfig {
|
|||||||
|
|
||||||
@Path("chat")
|
@Path("chat")
|
||||||
@SpecComment("Control where CHAT messages are delivered")
|
@SpecComment("Control where CHAT messages are delivered")
|
||||||
public DestinationObject chat = DestinationObject.of(MessageDestination.CHAT, false);
|
public DestinationObject chat = DestinationObject.of(MessageDestination.CHAT, false, "default");
|
||||||
|
|
||||||
@Path("startStop")
|
@Path("startStop")
|
||||||
@SpecComment("Control where START/STOP messages are delivered")
|
@SpecComment("Control where START/STOP messages are delivered")
|
||||||
public DestinationObject startStop = DestinationObject.of(MessageDestination.EVENT, false);
|
public DestinationObject startStop = DestinationObject.of(MessageDestination.EVENT, false, "default");
|
||||||
|
|
||||||
@Path("joinLeave")
|
@Path("joinLeave")
|
||||||
@SpecComment("Control where JOIN/LEAVE messages are delivered")
|
@SpecComment("Control where JOIN/LEAVE messages are delivered")
|
||||||
public DestinationObject joinLeave = DestinationObject.of(MessageDestination.EVENT, false);
|
public DestinationObject joinLeave = DestinationObject.of(MessageDestination.EVENT, false, "default");
|
||||||
|
|
||||||
@Path("advancements")
|
@Path("advancements")
|
||||||
@SpecComment("Control where ADVANCEMENT messages are delivered")
|
@SpecComment("Control where ADVANCEMENT messages are delivered")
|
||||||
public DestinationObject advancements = DestinationObject.of(MessageDestination.EVENT, false);
|
public DestinationObject advancements = DestinationObject.of(MessageDestination.EVENT, false, "default");
|
||||||
|
|
||||||
@Path("death")
|
@Path("death")
|
||||||
@SpecComment("Control where DEATH messages are delivered")
|
@SpecComment("Control where DEATH messages are delivered")
|
||||||
public DestinationObject death = DestinationObject.of(MessageDestination.EVENT, false);
|
public DestinationObject death = DestinationObject.of(MessageDestination.EVENT, false, "default");
|
||||||
|
|
||||||
@Path("commands")
|
@Path("commands")
|
||||||
@SpecComment("Control where COMMAND messages are delivered")
|
@SpecComment("Control where COMMAND messages are delivered")
|
||||||
public DestinationObject commands = DestinationObject.of(MessageDestination.EVENT, false);
|
public DestinationObject commands = DestinationObject.of(MessageDestination.EVENT, false, "default");
|
||||||
|
|
||||||
|
@Path("custom")
|
||||||
|
@SpecComment("Control where messages that match none of the above are delivered")
|
||||||
|
public DestinationObject custom = DestinationObject.of(MessageDestination.EVENT, false, "default");
|
||||||
|
|
||||||
public static class DestinationObject {
|
public static class DestinationObject {
|
||||||
@Path("channel")
|
@Path("channel")
|
||||||
@@ -47,13 +51,18 @@ public class MessageChannelConfig {
|
|||||||
@SpecComment("Should the message be sent using EMBED style messages")
|
@SpecComment("Should the message be sent using EMBED style messages")
|
||||||
public boolean useEmbed;
|
public boolean useEmbed;
|
||||||
|
|
||||||
DestinationObject(MessageDestination destination, boolean useEmbed) {
|
@Path("embedLayout")
|
||||||
|
@SpecComment("Embed Layout to use")
|
||||||
|
public String embedLayout;
|
||||||
|
|
||||||
|
DestinationObject(MessageDestination destination, boolean useEmbed, String embedLayout) {
|
||||||
this.channel = destination;
|
this.channel = destination;
|
||||||
this.useEmbed = useEmbed;
|
this.useEmbed = useEmbed;
|
||||||
|
this.embedLayout = embedLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DestinationObject of(MessageDestination destination, boolean useEmbed) {
|
public static DestinationObject of(MessageDestination destination, boolean useEmbed, String embedLayout) {
|
||||||
return new DestinationObject(destination, useEmbed);
|
return new DestinationObject(destination, useEmbed, embedLayout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,8 +20,10 @@ import net.dv8tion.jda.api.JDABuilder;
|
|||||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||||
import net.dv8tion.jda.api.utils.ChunkingFilter;
|
import net.dv8tion.jda.api.utils.ChunkingFilter;
|
||||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -62,8 +64,23 @@ public class BotController {
|
|||||||
INSTANCE = this;
|
INSTANCE = this;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
|
File newConfigDir = new File("./config/simple-discord-link");
|
||||||
|
if (!newConfigDir.exists())
|
||||||
|
newConfigDir.mkdirs();
|
||||||
|
|
||||||
|
File oldConfig = new File("./config/simple-discord-link.toml");
|
||||||
|
if (oldConfig.exists()) {
|
||||||
|
try {
|
||||||
|
FileUtils.moveFile(oldConfig, new File(newConfigDir.getAbsolutePath() + File.separator + "simple-discord-link.toml"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to move config file to new location", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize Config
|
||||||
new SDLinkConfig();
|
new SDLinkConfig();
|
||||||
|
|
||||||
|
// Initialize Account Storage
|
||||||
DatabaseManager.initialize();
|
DatabaseManager.initialize();
|
||||||
|
|
||||||
// Initialize Webhook Clients
|
// Initialize Webhook Clients
|
||||||
|
@@ -15,5 +15,6 @@ public enum MessageType {
|
|||||||
ADVANCEMENT,
|
ADVANCEMENT,
|
||||||
DEATH,
|
DEATH,
|
||||||
COMMAND,
|
COMMAND,
|
||||||
CONSOLE
|
CONSOLE,
|
||||||
|
CUSTOM
|
||||||
}
|
}
|
||||||
|
@@ -68,7 +68,7 @@ public final class DiscordMessage {
|
|||||||
* Send a Non Console relay message to discord
|
* Send a Non Console relay message to discord
|
||||||
*/
|
*/
|
||||||
private void sendNormalMessage() {
|
private void sendNormalMessage() {
|
||||||
Triple<StandardGuildMessageChannel, WebhookClient, Boolean> channel = resolveDestination();
|
Triple<StandardGuildMessageChannel, WebhookClient, MessageChannelConfig.DestinationObject> channel = resolveDestination();
|
||||||
|
|
||||||
// Check if a webhook is configured, and use that instead
|
// Check if a webhook is configured, and use that instead
|
||||||
if (channel.getMiddle() != null && SDLinkConfig.INSTANCE.channelsAndWebhooks.webhooks.enabled) {
|
if (channel.getMiddle() != null && SDLinkConfig.INSTANCE.channelsAndWebhooks.webhooks.enabled) {
|
||||||
@@ -79,8 +79,8 @@ public final class DiscordMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Message must be an Embed
|
// Message must be an Embed
|
||||||
if (channel.getRight()) {
|
if (channel.getRight().useEmbed) {
|
||||||
EmbedBuilder eb = buildEmbed(false);
|
EmbedBuilder eb = buildEmbed(false, channel.getRight().embedLayout);
|
||||||
WebhookEmbed web = WebhookEmbedBuilder.fromJDA(eb.build()).build();
|
WebhookEmbed web = WebhookEmbedBuilder.fromJDA(eb.build()).build();
|
||||||
builder.addEmbeds(web);
|
builder.addEmbeds(web);
|
||||||
} else {
|
} else {
|
||||||
@@ -93,8 +93,8 @@ public final class DiscordMessage {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Use the configured channel instead
|
// Use the configured channel instead
|
||||||
if (channel.getRight()) {
|
if (channel.getRight().useEmbed) {
|
||||||
EmbedBuilder eb = buildEmbed(true);
|
EmbedBuilder eb = buildEmbed(true, channel.getRight().embedLayout);
|
||||||
channel.getLeft().sendMessageEmbeds(eb.build()).queue(success -> {
|
channel.getLeft().sendMessageEmbeds(eb.build()).queue(success -> {
|
||||||
if (afterSend != null)
|
if (afterSend != null)
|
||||||
afterSend.run();
|
afterSend.run();
|
||||||
@@ -138,7 +138,7 @@ public final class DiscordMessage {
|
|||||||
* Build an embed with the supplied information
|
* Build an embed with the supplied information
|
||||||
* @param withAuthor Should the author be appended to the embed. Not used for Webhooks
|
* @param withAuthor Should the author be appended to the embed. Not used for Webhooks
|
||||||
*/
|
*/
|
||||||
private EmbedBuilder buildEmbed(boolean withAuthor) {
|
private EmbedBuilder buildEmbed(boolean withAuthor, String embedLayout) {
|
||||||
EmbedBuilder builder = new EmbedBuilder();
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
|
|
||||||
if (withAuthor) {
|
if (withAuthor) {
|
||||||
@@ -156,14 +156,14 @@ public final class DiscordMessage {
|
|||||||
/**
|
/**
|
||||||
* Figure out where the message must be delivered to, based on the config values
|
* Figure out where the message must be delivered to, based on the config values
|
||||||
*/
|
*/
|
||||||
private Triple<StandardGuildMessageChannel, WebhookClient, Boolean> resolveDestination() {
|
private Triple<StandardGuildMessageChannel, WebhookClient, MessageChannelConfig.DestinationObject> resolveDestination() {
|
||||||
switch (messageType) {
|
switch (messageType) {
|
||||||
case CHAT -> {
|
case CHAT -> {
|
||||||
MessageChannelConfig.DestinationObject chat = SDLinkConfig.INSTANCE.messageDestinations.chat;
|
MessageChannelConfig.DestinationObject chat = SDLinkConfig.INSTANCE.messageDestinations.chat;
|
||||||
return Triple.of(
|
return Triple.of(
|
||||||
ChannelManager.getDestinationChannel(chat.channel),
|
ChannelManager.getDestinationChannel(chat.channel),
|
||||||
WebhookManager.getWebhookClient(chat.channel),
|
WebhookManager.getWebhookClient(chat.channel),
|
||||||
chat.useEmbed
|
chat
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case START_STOP -> {
|
case START_STOP -> {
|
||||||
@@ -171,7 +171,7 @@ public final class DiscordMessage {
|
|||||||
return Triple.of(
|
return Triple.of(
|
||||||
ChannelManager.getDestinationChannel(startStop.channel),
|
ChannelManager.getDestinationChannel(startStop.channel),
|
||||||
WebhookManager.getWebhookClient(startStop.channel),
|
WebhookManager.getWebhookClient(startStop.channel),
|
||||||
startStop.useEmbed
|
startStop
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case JOIN_LEAVE -> {
|
case JOIN_LEAVE -> {
|
||||||
@@ -179,7 +179,7 @@ public final class DiscordMessage {
|
|||||||
return Triple.of(
|
return Triple.of(
|
||||||
ChannelManager.getDestinationChannel(joinLeave.channel),
|
ChannelManager.getDestinationChannel(joinLeave.channel),
|
||||||
WebhookManager.getWebhookClient(joinLeave.channel),
|
WebhookManager.getWebhookClient(joinLeave.channel),
|
||||||
joinLeave.useEmbed
|
joinLeave
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case ADVANCEMENT -> {
|
case ADVANCEMENT -> {
|
||||||
@@ -187,7 +187,7 @@ public final class DiscordMessage {
|
|||||||
return Triple.of(
|
return Triple.of(
|
||||||
ChannelManager.getDestinationChannel(advancement.channel),
|
ChannelManager.getDestinationChannel(advancement.channel),
|
||||||
WebhookManager.getWebhookClient(advancement.channel),
|
WebhookManager.getWebhookClient(advancement.channel),
|
||||||
advancement.useEmbed
|
advancement
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case DEATH -> {
|
case DEATH -> {
|
||||||
@@ -195,7 +195,7 @@ public final class DiscordMessage {
|
|||||||
return Triple.of(
|
return Triple.of(
|
||||||
ChannelManager.getDestinationChannel(death.channel),
|
ChannelManager.getDestinationChannel(death.channel),
|
||||||
WebhookManager.getWebhookClient(death.channel),
|
WebhookManager.getWebhookClient(death.channel),
|
||||||
death.useEmbed
|
death
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case COMMAND -> {
|
case COMMAND -> {
|
||||||
@@ -203,13 +203,21 @@ public final class DiscordMessage {
|
|||||||
return Triple.of(
|
return Triple.of(
|
||||||
ChannelManager.getDestinationChannel(command.channel),
|
ChannelManager.getDestinationChannel(command.channel),
|
||||||
WebhookManager.getWebhookClient(command.channel),
|
WebhookManager.getWebhookClient(command.channel),
|
||||||
command.useEmbed
|
command
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case CUSTOM -> {
|
||||||
|
MessageChannelConfig.DestinationObject custom = SDLinkConfig.INSTANCE.messageDestinations.custom;
|
||||||
|
return Triple.of(
|
||||||
|
ChannelManager.getDestinationChannel(custom.channel),
|
||||||
|
WebhookManager.getWebhookClient(custom.channel),
|
||||||
|
custom
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This code should never be reached, but it's added here as a fail-safe
|
// This code should never be reached, but it's added here as a fail-safe
|
||||||
MessageChannelConfig.DestinationObject chat = SDLinkConfig.INSTANCE.messageDestinations.chat;
|
MessageChannelConfig.DestinationObject chat = SDLinkConfig.INSTANCE.messageDestinations.chat;
|
||||||
return Triple.of(ChannelManager.getDestinationChannel(chat.channel), WebhookManager.getWebhookClient(chat.channel), chat.useEmbed);
|
return Triple.of(ChannelManager.getDestinationChannel(chat.channel), WebhookManager.getWebhookClient(chat.channel), chat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,8 +9,6 @@ import com.hypherionmc.sdlink.core.config.SDLinkConfig;
|
|||||||
import com.hypherionmc.sdlink.core.config.impl.MessageIgnoreConfig;
|
import com.hypherionmc.sdlink.core.config.impl.MessageIgnoreConfig;
|
||||||
import com.hypherionmc.sdlink.core.messaging.MessageType;
|
import com.hypherionmc.sdlink.core.messaging.MessageType;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
* Used to construct a {@link DiscordMessage} to be sent back to discord
|
* Used to construct a {@link DiscordMessage} to be sent back to discord
|
||||||
|
@@ -4,10 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.hypherionmc.sdlink.core.util;
|
package com.hypherionmc.sdlink.core.util;
|
||||||
|
|
||||||
import com.hypherionmc.sdlink.core.managers.RoleManager;
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
|
||||||
|
|
||||||
import java.text.CharacterIterator;
|
import java.text.CharacterIterator;
|
||||||
import java.text.StringCharacterIterator;
|
import java.text.StringCharacterIterator;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
Reference in New Issue
Block a user