Skip to content

Commit

Permalink
Refactoring Welcome Module
Browse files Browse the repository at this point in the history
  • Loading branch information
WinG4merBR committed Jan 15, 2025
1 parent a61d8fa commit 1e72e95
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
13 changes: 13 additions & 0 deletions common/src/main/kotlin/net/cakeyfox/common/Placeholders.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.cakeyfox.common

object Placeholders {
const val USER_GLOBAL_NAME = "{user}"
const val USER_MENTION = "{@user}"
const val USER_USERNAME = "{user.username}"
const val USER_ID = "{user.id}"
const val USER_AVATAR = "{user.avatar}"
const val GUILD_NAME = "{guild.name}"
const val GUILD_ID = "{guild.id}"
const val GUILD_MEMBERS = "{guild.memberCount}"
const val GUILD_ICON = "{guild.icon}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.cakeyfox.foxy.modules.welcomer
import net.cakeyfox.foxy.FoxyInstance
import net.cakeyfox.foxy.modules.welcomer.utils.WelcomerWrapper
import net.cakeyfox.foxy.modules.welcomer.utils.WelcomerJSONParser
import net.dv8tion.jda.api.Permission
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent

Expand All @@ -23,8 +24,9 @@ class WelcomerModule(
val channel = event.guild.getTextChannelById(guildData.GuildJoinLeaveModule.joinChannel ?: "0")
?: return

channel.sendMessage(content).setEmbeds(embeds).queue()

if (channel.canTalk() && event.guild.selfMember.hasPermission(Permission.MESSAGE_SEND)) {
channel.sendMessage(content).setEmbeds(embeds).queue()
}
}
}

Expand All @@ -40,7 +42,9 @@ class WelcomerModule(
val channel = event.guild.getTextChannelById(guildData.GuildJoinLeaveModule.leaveChannel ?: "0")
?: return

channel.sendMessage(content).setEmbeds(embeds).queue()
if (channel.canTalk() && event.guild.selfMember.hasPermission(Permission.MESSAGE_SEND)) {
channel.sendMessage(content).setEmbeds(embeds).queue()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.cakeyfox.foxy.modules.welcomer.utils

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import net.cakeyfox.common.Placeholders
import net.dv8tion.jda.api.EmbedBuilder
import net.dv8tion.jda.api.entities.Guild
import net.dv8tion.jda.api.entities.MessageEmbed
Expand Down Expand Up @@ -85,15 +86,15 @@ class WelcomerJSONParser {

fun getPlaceholders(guild: Guild, user: User): Map<String, String?> {
return mapOf(
"{user}" to user.globalName,
"{@user}" to user.asMention,
"{user.username}" to user.name,
"{user.id}" to user.id,
"{guild.name}" to guild.name,
"{guild.id}" to guild.id,
"{guild.memberCount}" to guild.memberCount.toString(),
"{user.avatar}" to user.effectiveAvatarUrl + "?size=2048",
"{guild.icon}" to guild.iconUrl
Placeholders.USER_GLOBAL_NAME to user.globalName,
Placeholders.USER_MENTION to user.asMention,
Placeholders.USER_USERNAME to user.name,
Placeholders.USER_ID to user.id,
Placeholders.GUILD_NAME to guild.name,
Placeholders.GUILD_ID to guild.id,
Placeholders.GUILD_MEMBERS to guild.memberCount.toString(),
Placeholders.USER_AVATAR to user.effectiveAvatarUrl + "?size=2048",
Placeholders.GUILD_ICON to guild.iconUrl
)
}

Expand Down

0 comments on commit 1e72e95

Please sign in to comment.