Skip to content

Commit

Permalink
Merge pull request #6 from logixism/next-gen
Browse files Browse the repository at this point in the history
feat: add option to toggle Discord mentions
  • Loading branch information
K-Lqrs authored Nov 30, 2024
2 parents c76d130 + 0eda908 commit c6e5bb2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/net/rk4z/fabricord/Fabricord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Fabricord : DedicatedServerModInitializer {
var botActivityMessage: String? = null

var messageStyle: String? = null
var allowMentions: Boolean? = true
var webHookId: String? = null
//endregion
}
Expand Down Expand Up @@ -181,6 +182,7 @@ class Fabricord : DedicatedServerModInitializer {
botActivityMessage = config.getNullableString("BotActivityMessage")

messageStyle = config.getNullableString("MessageStyle")
allowMentions = config.getNullableBoolean("AllowMentions")
webHookId = extractWebhookIdFromUrl(config.getNullableString("WebhookUrl"))
}
} catch (e: IOException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,13 @@ object DiscordBotManager : ListenerAdapter() {

fun sendToDiscord(message: String) {
executorService.submit {
Fabricord.logChannelID?.let { jda?.getTextChannelById(it)?.sendMessage(message)?.queue() }
Fabricord.logChannelID?.let {
val messageAction = jda?.getTextChannelById(it)?.sendMessage(message)
if (Fabricord.allowMentions == false) {
messageAction?.setAllowedMentions(emptySet())
}
messageAction?.queue()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ object DiscordPlayerEventHandler {

val data = MessageCreateBuilder()
.setContent(message)
.build()


webHookClient!!.sendMessage(data)
if (Fabricord.allowMentions == false) {
data.setAllowedMentions(emptySet())
}


webHookClient!!.sendMessage(data.build())
.setUsername(player.name.string)
.setAvatarUrl("https://visage.surgeplay.com/face/256/${player.uuid}")
.queue()
Expand Down
17 changes: 3 additions & 14 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,60 @@
# GitHub -> https://github.com/KT-Ruxy/Fabricord
# Modrinth -> https://modrinth.com/mod/fabricord


# BotToken for use with Discord.
# To get a BotToken -> https://discord.com/developers/applications
BotToken: ""


# Channel for sending Minecraft logs.
# If Blank, the mod will not send Minecraft Server General Chat to Discord.
# To get a Channel ID -> https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID
LogChannelID: ""


# >----- Advanced Settings -----< #


# The bot's activity can be changed.
# "PLAYING", "STREAMING", "LISTENING" and "WATCHING" are available.
# If blank, "PLAYING" is automatically selected.
BotActivityStatus: ""


# The bot's activity text can be changed.
# If blank, "Minecraft" is automatically selected.
BotActivityMessage: ""


# The bot's online status can be changed.
# "ONLINE", "IDLE" and "DO_NOT_DISTURB" are available.
# If blank, "ONLINE" is automatically selected.
BotOnlineStatus: ""


# The Log Style can be changed.
# "Classic", "modern" are available.
# If blank, "classic" is automatically selected.
MessageStyle: ""


# If Message_Style is "modern", you need to set the Webhook URL.
# To get a Webhook URL -> https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
WebhookUrl: ""

# Whether to allow pings like @everyone to be sent from Minecraft to Discord.
AllowMentions: false

# The message that appears when the server starts.
# If blank, the message will use the default message.
ServerStartMessage: ""


# The message that appears when the server stops.
# If blank, the message will use the default message.
ServerStopMessage: ""


# The message that appears when a player joins the server.
# You can use the "% player%" placeholder.
# It will be replaced with the player's name.
# If blank, the message will use the default message.
PlayerJoinMessage: ""


# The message that appears when a player leaves the server.
# You can use the "% player%" placeholder.
# It will be replaced with the player's name.
# If blank, the message will use the default message.
PlayerLeaveMessage: ""


# >-----------------------------< #
# >-----------------------------< #

0 comments on commit c6e5bb2

Please sign in to comment.