Skip to content

Commit

Permalink
Translate moooaaarrrrrr
Browse files Browse the repository at this point in the history
  • Loading branch information
NoComment1105 committed Nov 5, 2024
1 parent fd6c8e9 commit 316f1fa
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,41 @@ package org.hyacinthbots.lilybot.extensions.logging.config
import dev.kordex.core.commands.Arguments
import dev.kordex.core.commands.converters.impl.boolean
import dev.kordex.core.commands.converters.impl.optionalChannel
import lilybot.i18n.Translations

class LoggingArgs : Arguments() {
val enableMessageDeleteLogs by boolean {
name = "enable-delete-logs"
description = "Enable logging of message deletions"
name = Translations.Config.Arguments.Logging.EnableDelete.name
description = Translations.Config.Arguments.Logging.EnableDelete.description
}

val enableMessageEditLogs by boolean {
name = "enable-edit-logs"
description = "Enable logging of message edits"
name = Translations.Config.Arguments.Logging.EnableEdit.name
description = Translations.Config.Arguments.Logging.EnableEdit.description
}

val enableMemberLogging by boolean {
name = "enable-member-logging"
description = "Enable logging of members joining and leaving the guild"
name = Translations.Config.Arguments.Logging.EnableMember.name
description = Translations.Config.Arguments.Logging.EnableMember.description
}

val enablePublicMemberLogging by boolean {
name = "enable-public-member-logging"
description =
"Enable logging of members joining and leaving the guild with a public message and ping if enabled"
name = Translations.Config.Arguments.Logging.EnablePublicMember.name
description = Translations.Config.Arguments.Logging.EnablePublicMember.description
}

val messageLogs by optionalChannel {
name = "message-logs"
description = "The channel for logging message deletions"
name = Translations.Config.Arguments.Logging.MessageLog.name
description = Translations.Config.Arguments.Logging.MessageLog.description
}

val memberLog by optionalChannel {
name = "member-log"
description = "The channel for logging members joining and leaving the guild"
name = Translations.Config.Arguments.Logging.MemberLog.name
description = Translations.Config.Arguments.Logging.MemberLog.description
}

val publicMemberLog by optionalChannel {
name = "public-member-log"
description = "The channel for the public logging of members joining and leaving the guild"
name = Translations.Config.Arguments.Logging.PublicMemberLog.name
description = Translations.Config.Arguments.Logging.PublicMemberLog.description
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import dev.kordex.core.utils.botHasPermissions
import dev.kordex.modules.dev.unsafe.annotations.UnsafeAPI
import dev.kordex.modules.dev.unsafe.commands.slash.InitialSlashCommandResponse
import dev.kordex.modules.dev.unsafe.extensions.unsafeSubCommand
import lilybot.i18n.Translations
import org.hyacinthbots.lilybot.database.collections.LoggingConfigCollection
import org.hyacinthbots.lilybot.database.entities.LoggingConfigData
import org.hyacinthbots.lilybot.database.entities.PublicMemberLogData
Expand All @@ -22,8 +23,8 @@ import org.hyacinthbots.lilybot.utils.getLoggingChannelWithPerms

@OptIn(UnsafeAPI::class)
suspend fun SlashCommand<*, *, *>.loggingCommand() = unsafeSubCommand(::LoggingArgs) {
name = "logging"
description = "Configure Lily's logging system"
name = Translations.Config.Logging.name
description = Translations.Config.Logging.description

initialResponse = InitialSlashCommandResponse.None

Expand All @@ -39,28 +40,27 @@ suspend fun SlashCommand<*, *, *>.loggingCommand() = unsafeSubCommand(::LoggingA
if (loggingConfig != null) {
ackEphemeral()
respondEphemeral {
content = "You already have a logging configuration set. " +
"Please clear it before attempting to set a new one."
content = Translations.Config.configAlreadyExists.translate("Logging")
}
return@action
}

if (arguments.enableMemberLogging && arguments.memberLog == null) {
ackEphemeral()
respondEphemeral {
content = "You must specify a channel to log members joining and leaving to!"
content = Translations.Config.Logging.memberMissing.translate()
}
return@action
} else if ((arguments.enableMessageDeleteLogs || arguments.enableMessageEditLogs) &&
arguments.messageLogs == null
) {
ackEphemeral()
respondEphemeral { content = "You must specify a channel to log deleted/edited messages to!" }
respondEphemeral { content = Translations.Config.Logging.editMissing.translate() }
return@action
} else if (arguments.enablePublicMemberLogging && arguments.publicMemberLog == null) {
ackEphemeral()
respondEphemeral {
content = "You must specify a channel to publicly log members joining and leaving to!"
content = Translations.Config.Logging.publicMemberMissing.translate()
}
return@action
}
Expand All @@ -71,8 +71,7 @@ suspend fun SlashCommand<*, *, *>.loggingCommand() = unsafeSubCommand(::LoggingA
if (memberLog?.botHasPermissions(Permission.ViewChannel, Permission.SendMessages) != true) {
ackEphemeral()
respondEphemeral {
content = "The member log you've selected is invalid, or I can't view it. " +
"Please attempt to resolve this and try again."
content = Translations.Config.invalidChannel.translate("member log")
}
return@action
}
Expand All @@ -84,8 +83,7 @@ suspend fun SlashCommand<*, *, *>.loggingCommand() = unsafeSubCommand(::LoggingA
if (messageLog?.botHasPermissions(Permission.ViewChannel, Permission.SendMessages) != true) {
ackEphemeral()
respondEphemeral {
content = "The message log you've selected is invalid, or I can't view it. " +
"Please attempt to resolve this and try again."
content = Translations.Config.invalidChannel.translate("message log")
}
return@action
}
Expand All @@ -101,8 +99,7 @@ suspend fun SlashCommand<*, *, *>.loggingCommand() = unsafeSubCommand(::LoggingA
) {
ackEphemeral()
respondEphemeral {
content = "The public member log you've selected is invalid, or I can't view it. " +
"Please attempt to resolve this and try again."
content = Translations.Config.invalidChannel.translate("public memeber log")
}
return@action
}
Expand All @@ -115,10 +112,10 @@ suspend fun SlashCommand<*, *, *>.loggingCommand() = unsafeSubCommand(::LoggingA
this@unsafeSubCommand.componentRegistry.register(modalObj)

event.interaction.modal(
modalObj.title,
modalObj.title.translate(),
modalObj.id
) {
modalObj.applyToBuilder(this, getLocale(), null)
modalObj.applyToBuilder(this, getLocale())
}

modalObj.awaitCompletion { modalSubmitInteraction ->
Expand Down Expand Up @@ -155,7 +152,7 @@ suspend fun SlashCommand<*, *, *>.loggingCommand() = unsafeSubCommand(::LoggingA

if (utilityLog == null) {
respondEphemeral {
content = "Consider setting a utility config to log changes to configurations."
content = Translations.Config.considerUtility.translate()
}
return@action
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package org.hyacinthbots.lilybot.extensions.logging.config

import dev.kordex.core.components.forms.ModalForm
import lilybot.i18n.Translations

class PublicLoggingModal : ModalForm() {
override var title = "Public logging configuration"
override var title = Translations.Config.Logging.Modal.title

val joinMessage = paragraphText {
label = "What would you like sent when a user joins"
placeholder = "Welcome to the server!"
label = Translations.Config.Logging.Modal.JoinMessage.label
placeholder = Translations.Config.Logging.Modal.JoinMessage.placeholder
required = true
}

val leaveMessage = paragraphText {
label = "What would you like sent when a user leaves"
placeholder = "Adiós amigo!"
label = Translations.Config.Logging.Modal.LeaveMessage.label
placeholder = Translations.Config.Logging.Modal.LeaveMessage.placeholder
required = true
}

val ping = lineText {
label = "Type `yes` to ping new users when they join"
placeholder = "Defaults to false if input is invalid or not `yes`"
label = Translations.Config.Logging.Modal.Ping.label
placeholder = Translations.Config.Logging.Modal.Ping.placeholder
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import dev.kordex.core.extensions.Extension
import dev.kordex.core.extensions.event
import dev.kordex.core.utils.botHasPermissions
import kotlinx.datetime.Clock
import lilybot.i18n.Translations
import org.hyacinthbots.lilybot.database.collections.LeftMemberFlagCollection
import org.hyacinthbots.lilybot.database.collections.LoggingConfigCollection
import org.hyacinthbots.lilybot.database.collections.ModerationActionCollection
Expand Down Expand Up @@ -49,16 +50,16 @@ class MemberLogging : Extension() {

memberLog?.createEmbed {
author {
name = "User joined the server!"
name = Translations.Events.MemberLogging.MemberJoin.embedAuthor.translate()
icon = event.member.avatar?.cdnUrl?.toUrl()
}
field {
name = "Welcome:"
name = Translations.Events.MemberLogging.MemberJoin.embedWelcome.translate()
value = "${event.member.mention} (${event.member.username})"
inline = true
}
field {
name = "ID:"
name = Translations.Events.MemberLogging.MemberEvent.embedId.translate()
value = event.member.id.toString()
inline = false
}
Expand All @@ -77,13 +78,13 @@ class MemberLogging : Extension() {
if (config.publicMemberLogData?.pingNewUsers == true) content = event.member.mention
embed {
author {
name = "Welcome ${event.member.username}"
name = Translations.Events.MemberLogging.MemberJoin.publicEmbedAuthor.translate(event.member.username)
icon = event.member.avatar?.cdnUrl?.toUrl()
}
description = if (config.publicMemberLogData?.joinMessage != null) {
config.publicMemberLogData.joinMessage
} else {
"Welcome to the server!"
Translations.Events.MemberLogging.MemberJoin.publicEmbedWelcomeMessage.translate()
}
timestamp = Clock.System.now()
color = DISCORD_GREEN
Expand All @@ -107,16 +108,16 @@ class MemberLogging : Extension() {

memberLog?.createEmbed {
author {
name = "User left the server!"
name = Translations.Events.MemberLogging.MemberLeave.embedAuthor.translate()
icon = event.user.avatar?.cdnUrl?.toUrl()
}
field {
name = "Goodbye:"
name = Translations.Events.MemberLogging.MemberLeave.embedGoodbye.translate()
value = event.user.username
inline = true
}
field {
name = "ID:"
name = Translations.Events.MemberLogging.MemberEvent.embedId.translate()
value = event.user.id.toString()
}
timestamp = Clock.System.now()
Expand All @@ -129,6 +130,7 @@ class MemberLogging : Extension() {
val targetUser = event.kord.getUser(kickData.targetUserId)!!
val actioner = kickData.data.actioner?.let { event.kord.getUser(it) }!!
getLoggingChannelWithPerms(ConfigOptions.ACTION_LOG, event.guild)?.createEmbed {
// TODO translate these with the moderation events
title = "Kicked a user"
description = "${targetUser.mention} has been kicked"
image = kickData.data.imageUrl
Expand All @@ -147,13 +149,13 @@ class MemberLogging : Extension() {

publicLog?.createEmbed {
author {
name = "Goodbye ${event.user.username}"
name = Translations.Events.MemberLogging.MemberLeave.publicEmbedAuthor.translate(event.user.username)
icon = event.user.avatar?.cdnUrl?.toUrl()
}
description = if (config.publicMemberLogData?.leaveMessage != null) {
config.publicMemberLogData.leaveMessage
} else {
"Farewell!"
Translations.Events.MemberLogging.MemberLeave.publicEmbedGoodbyeMessage.translate()
}
timestamp = Clock.System.now()
color = DISCORD_RED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import dev.kordex.modules.pluralkit.events.UnProxiedMessageDeleteEvent
import io.ktor.client.request.forms.ChannelProvider
import io.ktor.utils.io.jvm.javaio.toByteReadChannel
import kotlinx.datetime.Clock
import lilybot.i18n.Translations
import org.hyacinthbots.lilybot.extensions.config.ConfigOptions
import org.hyacinthbots.lilybot.utils.attachmentsAndProxiedMessageInfo
import org.hyacinthbots.lilybot.utils.generateBulkDeleteFile
Expand Down Expand Up @@ -65,7 +66,7 @@ class MessageDelete : Extension() {
requiredConfigs(ConfigOptions.MESSAGE_DELETE_LOGGING_ENABLED, ConfigOptions.MESSAGE_LOG)
failIf {
event.message?.author?.id == kord.selfId ||
event.message?.author?.isBot == true
event.message?.author?.isBot == true
}
}

Expand All @@ -82,7 +83,7 @@ class MessageDelete : Extension() {

action {
val messageLog =
getLoggingChannelWithPerms(ConfigOptions.MESSAGE_LOG, event.getGuildOrNull()!!) ?: return@action
getLoggingChannelWithPerms(ConfigOptions.MESSAGE_LOG, event.getGuildOrNull()!!) ?: return@action

val messages = generateBulkDeleteFile(event.messages)

Expand All @@ -101,16 +102,18 @@ class MessageDelete : Extension() {
*/
private suspend fun UserMessageCreateBuilder.bulkDeleteEmbed(event: MessageBulkDeleteEvent, messages: String?) {
embed {
title = "Bulk Message Delete"
description = "A Bulk delete of messages occurred"
title = Translations.Events.MessageDelete.Bulk.embedTitle.translate()
description = Translations.Events.MessageDelete.Bulk.embedDescription.translate()
field {
name = "Location"
name = Translations.Events.MessageDelete.Bulk.embedLocation.translate()
value = "${event.channel.mention} " +
"(${event.channel.asChannelOfOrNull<GuildMessageChannel>()?.name
?: "Could not get channel name"})"
"(${
event.channel.asChannelOfOrNull<GuildMessageChannel>()?.name
?: Translations.Events.MessageEvent.failedContents.translate()
})"
}
field {
name = "Number of messages"
name = Translations.Events.MessageDelete.Bulk.embedNumber.translate()
value = event.messages.size.toString()
}
color = DISCORD_PINK
Expand All @@ -122,7 +125,7 @@ class MessageDelete : Extension() {
ChannelProvider { messages.byteInputStream().toByteReadChannel() }
)
} else {
content = "The messages from this event could not be gathered and logged."
content = Translations.Events.MessageDelete.Bulk.embedFailedContent.translate()
}
}

Expand All @@ -144,18 +147,20 @@ class MessageDelete : Extension() {

messageLog.createEmbed {
author {
name = "Message deleted"
name = Translations.Events.MessageDelete.Single.embedAuthor.translate()
icon = proxiedMessage?.member?.avatarUrl ?: message.author?.avatar?.cdnUrl?.toUrl()
}
description =
"Location: ${message.channel.mention} " +
"(${message.channel.asChannelOfOrNull<GuildMessageChannel>()?.name ?: "Could not get channel name"})"
description = Translations.Events.MessageEvent.location.translate(
message.channel.mention,
message.channel.asChannelOfOrNull<GuildMessageChannel>()?.name
?: Translations.Events.MessageDelete.noChannelName.translate()
)
color = DISCORD_PINK
timestamp = Clock.System.now()

field {
name = "Message contents"
value = message.trimmedContents().ifNullOrEmpty { "Failed to retrieve previous message contents" }
name = Translations.Events.MessageDelete.Single.embedContents.translate()
value = message.trimmedContents().ifNullOrEmpty { Translations.Events.MessageEvent.failedContents.translate() }
inline = false
}
attachmentsAndProxiedMessageInfo(guild, message, proxiedMessage)
Expand Down
Loading

0 comments on commit 316f1fa

Please sign in to comment.