Skip to content

Commit 68a4b36

Browse files
committed
Begin adjusting to be a generalized multiserver bot. Add info commands and stuff
1 parent efbb758 commit 68a4b36

10 files changed

Lines changed: 123 additions & 60 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ jobs:
3232
uses: actions/upload-artifact@v4
3333
with:
3434
name: Build Only Artifacts
35-
path: build/libs/*[0-9].jar
35+
path: build/libs/*[0-9]*.jar

config.example.properties

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/main/kotlin/io/github/nocomment1105/modmailbot/ModMailBot.kt

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,25 @@ package io.github.nocomment1105.modmailbot
1313

1414
import dev.kord.cache.map.MapLikeCollection
1515
import dev.kord.cache.map.internal.MapEntryCache
16+
import dev.kord.cache.map.lruLinkedHashMap
1617
import dev.kord.gateway.Intent
1718
import dev.kord.gateway.PrivilegedIntent
19+
import dev.kord.rest.builder.message.actionRow
20+
import dev.kord.rest.builder.message.embed
1821
import dev.kordex.core.ExtensibleBot
22+
import dev.kordex.core.i18n.SupportedLocales
23+
import dev.kordex.data.api.DataCollection
1924
import io.github.nocomment1105.modmailbot.extensions.commands.CloseCommands
2025
import io.github.nocomment1105.modmailbot.extensions.commands.ReplyCommands
2126
import io.github.nocomment1105.modmailbot.extensions.events.MessageEditing
2227
import io.github.nocomment1105.modmailbot.extensions.events.MessageReceiving
23-
import kotlinx.coroutines.Dispatchers
24-
import kotlinx.coroutines.withContext
25-
import java.io.FileInputStream
26-
import java.util.*
27-
28-
val file = FileInputStream("config.properties")
29-
val config = Properties()
28+
import modmailbot.i18n.Translations
3029

3130
suspend fun main() {
32-
withContext(Dispatchers.IO) {
33-
config.load(file)
34-
}
35-
3631
val bot = ExtensibleBot(BOT_TOKEN) {
37-
database(false)
32+
dataCollectionMode = DataCollection.None
3833

39-
applicationCommands {
40-
defaultGuild(MAIL_SERVER)
41-
}
34+
database(false)
4235

4336
extensions {
4437
add(::MessageReceiving)
@@ -60,20 +53,80 @@ suspend fun main() {
6053
}
6154

6255
presence {
63-
when (config.getProperty("statusType")) {
64-
"playing" -> playing(config.getProperty("status"))
65-
"watching" -> watching(config.getProperty("status"))
66-
else -> watching("for your DMs!")
67-
}
56+
watching("for your DMs!")
6857
}
6958

7059
kord {
60+
stackTraceRecovery = true
61+
7162
cache {
7263
messages { cache, description ->
73-
MapEntryCache(cache, description, MapLikeCollection.concurrentHashMap())
64+
// Set a max message cache size of 1000 messages to avoid creating a crazy large cache
65+
MapEntryCache(cache, description, MapLikeCollection.lruLinkedHashMap(1000))
66+
}
67+
}
68+
}
69+
70+
about {
71+
ephemeral = false
72+
general {
73+
message { locale ->
74+
embed {
75+
title = Translations.About.embedTitle.translate()
76+
77+
// TODO A logo that can go here
78+
// thumbnail {
79+
// url = ""
80+
// }
81+
82+
description = Translations.About.embedDesc.translate()
83+
84+
field {
85+
name = Translations.About.howSupportTitle.translate()
86+
value = Translations.About.howSupportValue.translate()
87+
}
88+
89+
field {
90+
name = Translations.About.version.translate()
91+
// TODO Install Blossom and do the thing for versions
92+
value = ""
93+
}
94+
95+
field {
96+
name = Translations.About.usefulLinksName.translate()
97+
value = Translations.About.usefulLinksValue.translate()
98+
}
99+
}
100+
101+
actionRow {
102+
// TODO All of this lmao
103+
linkButton("") {
104+
label = Translations.About.inviteButton.translate()
105+
}
106+
107+
linkButton("") {
108+
label = Translations.About.privacyButton.translate()
109+
}
110+
111+
linkButton("") {
112+
label = Translations.About.tosButton.translate()
113+
}
114+
}
74115
}
75116
}
76117
}
118+
119+
i18n {
120+
interactionUserLocaleResolver()
121+
interactionGuildLocaleResolver()
122+
123+
applicationCommandLocale(SupportedLocales.ENGLISH)
124+
}
125+
126+
// TODO Install Doc gen
127+
// docGenerator {
128+
//
129+
// }
77130
}
78131

79132
bot.start()

src/main/kotlin/io/github/nocomment1105/modmailbot/_Constants.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@
99

1010
package io.github.nocomment1105.modmailbot
1111

12-
import dev.kord.common.entity.Snowflake
12+
import dev.kordex.core.utils.env
13+
import dev.kordex.core.utils.envOrNull
1314

1415
/** The token of the bot. */
15-
val BOT_TOKEN: String = config.getProperty("bot_token")
16-
17-
/** The ID of the mail server. */
18-
val MAIL_SERVER = Snowflake(config.getProperty("mail_server_id"))
19-
20-
/** The ID of the main server. */
21-
val MAIN_SERVER = Snowflake(config.getProperty("main_server_id"))
16+
val BOT_TOKEN: String = env("BOT_TOKEN")
2217

2318
/** The URI to connect to the database. */
24-
val MONGO_URI = config.getProperty("mongo_uri") ?: "mongodb://localhost:27017"
19+
val MONGO_URI = envOrNull("MONGO_URI") ?: "mongodb://localhost:27017"

src/main/kotlin/io/github/nocomment1105/modmailbot/_Utils.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import io.github.nocomment1105.modmailbot.database.collections.MetaCollection
2525
import io.github.nocomment1105.modmailbot.database.collections.OpenThreadsCollection
2626
import kotlinx.coroutines.runBlocking
2727
import kotlinx.datetime.Clock
28+
import modmailbot.i18n.Translations
2829
import org.koin.dsl.bind
2930

3031
/**
@@ -72,14 +73,14 @@ suspend fun EmbedBuilder.messageEmbed(
7273
name = author.tag
7374
icon = author.avatar?.cdnUrl?.toUrl()
7475
} else {
75-
name = author.asMember(MAIL_SERVER).getTopRole()!!.name
76+
name = author.asMemberOrNull(guildId)?.getTopRole()?.name
7677
}
7778
}
7879
description = message
7980
timestamp = Clock.System.now()
8081
color = embedColor ?: DISCORD_RED
8182
footer {
82-
text = author.asMember(guildId).getTopRole()!!.name
83+
text = author.asMemberOrNull(guildId)?.getTopRole()?.name ?: ""
8384
}
8485
}
8586

@@ -101,11 +102,11 @@ fun EmbedBuilder.editedMessageEmbed(
101102
embedColor: Color? = null
102103
) {
103104
field {
104-
name = "Previous content"
105+
name = Translations.Utils.EditedMessage.previous.translate()
105106
value = oldContent
106107
}
107108
field {
108-
name = "New content"
109+
name = Translations.Utils.EditedMessage.new.translate()
109110
value = newContent
110111
}
111112
timestamp = Clock.System.now()

src/main/kotlin/io/github/nocomment1105/modmailbot/extensions/commands/CloseCommands.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import dev.kord.core.behavior.channel.createMessage
1313
import dev.kord.core.entity.channel.DmChannel
1414
import dev.kord.core.entity.channel.MessageChannel
1515
import dev.kord.rest.builder.message.embed
16+
import dev.kordex.core.checks.anyGuild
1617
import dev.kordex.core.commands.Arguments
1718
import dev.kordex.core.commands.converters.impl.coalescingOptionalDuration
1819
import dev.kordex.core.commands.converters.impl.defaultingBoolean
@@ -21,7 +22,6 @@ import dev.kordex.core.extensions.Extension
2122
import dev.kordex.core.extensions.ephemeralSlashCommand
2223
import dev.kordex.core.utils.scheduling.Scheduler
2324
import dev.kordex.core.utils.scheduling.Task
24-
import io.github.nocomment1105.modmailbot.MAIL_SERVER
2525
import io.github.nocomment1105.modmailbot.database.collections.CloseQueueCollection
2626
import io.github.nocomment1105.modmailbot.database.collections.OpenThreadsCollection
2727
import io.github.nocomment1105.modmailbot.database.collections.SentMessagesCollection
@@ -48,7 +48,10 @@ class CloseCommands : Extension() {
4848
name = Translations.Commands.Close.name
4949
description = Translations.Commands.Close.description
5050

51-
guild(MAIL_SERVER)
51+
check {
52+
// Command is not to be run in DM with bot
53+
anyGuild()
54+
}
5255

5356
action {
5457
val userToDm = inThreadChannel() ?: return@action

src/main/kotlin/io/github/nocomment1105/modmailbot/extensions/commands/ReplyCommands.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ package io.github.nocomment1105.modmailbot.extensions.commands
1212
import dev.kord.core.behavior.channel.createMessage
1313
import dev.kord.rest.builder.message.embed
1414
import dev.kordex.core.DISCORD_GREEN
15+
import dev.kordex.core.checks.anyGuild
1516
import dev.kordex.core.commands.Arguments
1617
import dev.kordex.core.commands.converters.impl.string
1718
import dev.kordex.core.extensions.Extension
1819
import dev.kordex.core.extensions.ephemeralSlashCommand
19-
import io.github.nocomment1105.modmailbot.MAIL_SERVER
2020
import io.github.nocomment1105.modmailbot.database.collections.SentMessagesCollection
2121
import io.github.nocomment1105.modmailbot.database.entities.SentMessageData
2222
import io.github.nocomment1105.modmailbot.inThreadChannel
@@ -31,7 +31,10 @@ class ReplyCommands : Extension() {
3131
name = Translations.Commands.Reply.Reply.name
3232
description = Translations.Commands.Reply.Reply.description
3333

34-
guild(MAIL_SERVER)
34+
check {
35+
// This is for the mailed to reply with not the mailer
36+
anyGuild()
37+
}
3538

3639
action {
3740
val userToDm = inThreadChannel() ?: return@action
@@ -69,7 +72,10 @@ class ReplyCommands : Extension() {
6972
name = Translations.Commands.Reply.Anonreply.name
7073
description = Translations.Commands.Reply.Anonreply.name
7174

72-
guild(MAIL_SERVER)
75+
check {
76+
// This is for the mailed to reply with not the mailer
77+
anyGuild()
78+
}
7379

7480
action {
7581
val userToDm = inThreadChannel() ?: return@action

src/main/kotlin/io/github/nocomment1105/modmailbot/extensions/events/MessageEditing.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package io.github.nocomment1105.modmailbot.extensions.events
1111

12+
import dev.kord.common.entity.Snowflake
1213
import dev.kord.core.behavior.edit
1314
import dev.kord.core.behavior.getChannelOf
1415
import dev.kord.core.entity.channel.GuildMessageChannel
@@ -27,7 +28,6 @@ import dev.kordex.core.extensions.event
2728
import dev.kordex.core.i18n.toKey
2829
import dev.kordex.core.i18n.types.Key
2930
import dev.kordex.modules.dev.unsafe.annotations.UnsafeAPI
30-
import io.github.nocomment1105.modmailbot.MAIL_SERVER
3131
import io.github.nocomment1105.modmailbot.database.collections.OpenThreadsCollection
3232
import io.github.nocomment1105.modmailbot.database.collections.SentMessagesCollection
3333
import io.github.nocomment1105.modmailbot.editedMessageEmbed
@@ -51,7 +51,8 @@ class MessageEditing : Extension() {
5151
val threadMessageIdToEdit =
5252
SentMessagesCollection().getInternalMessageById(userThread!!.threadId, event.messageId)!!
5353
val threadMessageToEdit =
54-
kord.getGuildOrNull(MAIL_SERVER)!!.getChannelOf<GuildMessageChannel>(userThread.threadId)
54+
// TODO Add a config system to enable the mail server gotten
55+
kord.getGuildOrNull(Snowflake(""))!!.getChannelOf<GuildMessageChannel>(userThread.threadId)
5556
.getMessage(threadMessageIdToEdit)
5657

5758
threadMessageToEdit.edit {
@@ -112,7 +113,8 @@ class MessageEditing : Extension() {
112113
messageEmbed(
113114
modal?.newContents.toString(),
114115
user.asUser(),
115-
MAIL_SERVER,
116+
// TODO Add a config system to enable the mail server gotten
117+
Snowflake(""),
116118
DISCORD_GREEN,
117119
originalSentMessage?.isAnonymous == true
118120
)

src/main/kotlin/io/github/nocomment1105/modmailbot/extensions/events/MessageReceiving.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package io.github.nocomment1105.modmailbot.extensions.events
1111

12+
import dev.kord.common.entity.Snowflake
1213
import dev.kord.core.behavior.channel.createMessage
1314
import dev.kord.core.behavior.createTextChannel
1415
import dev.kord.core.behavior.getChannelOf
@@ -24,8 +25,6 @@ import dev.kordex.core.extensions.event
2425
import dev.kordex.core.time.TimestampType
2526
import dev.kordex.core.time.toDiscord
2627
import dev.kordex.core.utils.createdAt
27-
import io.github.nocomment1105.modmailbot.MAIL_SERVER
28-
import io.github.nocomment1105.modmailbot.MAIN_SERVER
2928
import io.github.nocomment1105.modmailbot.database.collections.OpenThreadsCollection
3029
import io.github.nocomment1105.modmailbot.database.collections.SentMessagesCollection
3130
import io.github.nocomment1105.modmailbot.database.entities.OpenThreadData
@@ -56,7 +55,8 @@ class MessageReceiving : Extension() {
5655

5756
if (!openThread) {
5857
// Get the mail channel
59-
mailChannel = kord.getGuildOrNull(MAIL_SERVER)!!.createTextChannel(event.message.author!!.tag)
58+
// TODO CONFIG
59+
mailChannel = kord.getGuildOrNull(Snowflake(""))!!.createTextChannel(event.message.author!!.tag)
6060

6161
// Store the users thread in the database
6262
OpenThreadsCollection().add(
@@ -78,13 +78,15 @@ class MessageReceiving : Extension() {
7878

7979
field {
8080
name = translations.nickname.translate()
81-
value = event.message.author!!.asMember(MAIN_SERVER).nickname
81+
// TODO CONFIG
82+
value = event.message.author!!.asMember(Snowflake("")).nickname
8283
?: Translations.Utils.none.translate()
8384
inline = true
8485
}
8586

8687
field {
87-
val roles = event.message.author!!.asMember(MAIN_SERVER).roles.toList().map { it }
88+
// TODO CONFIG
89+
val roles = event.message.author!!.asMember(Snowflake("")).roles.toList().map { it }
8890
name = translations.roles.translate()
8991
value = if (roles.isEmpty()) {
9092
Translations.Utils.none.translate()
@@ -130,7 +132,8 @@ class MessageReceiving : Extension() {
130132
event.message.addReaction(Emojis.whiteCheckMark)
131133
} else {
132134
// Get the mail server from the config file
133-
mailChannel = kord.getGuildOrNull(MAIL_SERVER)!!.getChannelOf(
135+
// TODO MORE CONFIG SYSTEM LMFAO
136+
mailChannel = kord.getGuildOrNull(Snowflake(""))!!.getChannelOf(
134137
OpenThreadsCollection().getOpenThreadsForUser(event.message.author!!.id)!!.threadId
135138
)
136139

src/main/resources/translations/modmailbot/strings.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
about.embedTitle=Info about ModMailBot.
2+
about.embedDesc=ModMailBot is a FOSS ModMail Bot for Discord, created by the HyacinthBots organization. Designed to be easy to use, complete with all the features you find in the bigger bots, but safe from a paywall.
3+
about.howSupportTitle=How can I support the continued development of ModMailBot
4+
about.howSupportValue=ModMailBot is developed primarily by NoComment#6411 in their free time. Hyacinth doesn't have the resources to invest in dedicated hosting, so financial donations via [Buy Me a Coffee](https://buymeacoffee.com/Hyacinthbots) help keep Lily afloat. Currently, we run lily on a Hetzner cloud server, which we can afford in our current situation. We also have domain costs for our website.\n\nContributions of code & documentation are also incredibly appreciated!
5+
about.version=Version
6+
about.usefulLinksName=Useful links
7+
about.usefulLinksValue==Website: https://hyacinthbots.org\nGitHub: https://github.com/HyacinthBots\nBuy Me a Coffee: https://buymeacoffee.com/HyacinthBots\nTwitter: https://twitter.com/HyacinthBots\nEmail: `hyacinthbots@outlook.com`\nDiscord: https://discord.gg/hy2329f
8+
about.inviteButton=Invite link
9+
about.privacyButton=Privacy Policy
10+
about.tosButton=Terms of Service
11+
112
commands.close.name=close
213
commands.close.description=Close this thread
314
commands.close.args.delay.name=delay

0 commit comments

Comments
 (0)