-
Notifications
You must be signed in to change notification settings - Fork 9
Potential fix for #26 #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
071d5ba
3d4ff9b
0177632
cc4a277
6dda772
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,8 @@ fun String.discordEscape() = this.replace("""_""", "\\_") | |
| data class DiscordConfig( | ||
| val enable: Boolean = false, | ||
| val networkToken: String = "nouNetwork", | ||
| val channelId: Long = 1234L, | ||
| val chadId: Long = 1234L, | ||
| val gameChatChannelId: Long = 1234L, | ||
| val patrickId: Long = 1234L, | ||
| val playingMessage: String = "on the ORE Network", | ||
| val discordFormat: String = "`%prefix%` **%sender%**: %message%", | ||
| val serverTokens: Map<String, String> = mapOf( | ||
|
|
@@ -70,8 +70,8 @@ fun PluginScope.createDiscordFeature( | |
| } | ||
| } | ||
| val discordMap = spawnServerBots(proxy, logger, config) | ||
| val serverChannels = discordMap.mapValues { (_, api) -> getGameChat(api, config.channelId) } | ||
| val mainBotChannel = getGameChat(discordNetwork, config.channelId) | ||
| val serverChannels = discordMap.mapValues { (_, api) -> getGameChat(api, config.gameChatChannelId) } | ||
| val mainBotChannel = getGameChat(discordNetwork, config.gameChatChannelId) | ||
| val listener = DiscordListener(logger, messenger, proxy, emojis, config) | ||
| @OptIn(KordPreview::class) | ||
| mainBotChannel.live().onMessageCreate(block = listener::onMessageCreate) | ||
|
|
@@ -90,8 +90,8 @@ fun PluginScope.createDiscordFeature( | |
| } | ||
| } | ||
|
|
||
| private suspend fun getGameChat(api: Kord, id: Long): TextChannel = api.getChannelOf(Snowflake(id)) | ||
| ?: throw IllegalArgumentException("Cannot find game-chat channel") | ||
| private suspend fun getGameChat(api: Kord, channelId: Long): TextChannel = api.getChannelOf(Snowflake(channelId)) | ||
| ?: throw IllegalArgumentException("Cannot find game-chat channel (with id $channelId)") | ||
|
|
||
| private class DiscordBroadcastListener( | ||
| private val config: DiscordConfig, | ||
|
|
@@ -141,10 +141,15 @@ private class DiscordListener( | |
| fun onMessageCreate(event: MessageCreateEvent) { | ||
| // guaranteed to not happen because events are filtered beforehand | ||
| val sender = event.member ?: throw IllegalStateException("onMessageCreate: event.member is null") | ||
| if (sender.isBot && sender.id != Snowflake(config.chadId)) return | ||
|
|
||
| var displayName = sender.effectiveName | ||
| if (sender.isBot) { | ||
| if (sender.id != Snowflake(config.patrickId)) return | ||
| displayName = "[Bot] " + displayName | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this is the easiest way to attach the bot prefix, it doesn't stand out from the rest of the display name. (Someone could nick themselves |
||
| } | ||
|
|
||
| val attachments = event.message.attachments.joinToString(" ", " ") { it.url } | ||
| val toSend = replaceEmojis(event.message.content) + attachments | ||
| val displayName = sender.effectiveName | ||
| logger.info("[Discord] $displayName (${sender.id}): $toSend") | ||
| val transformedMessage = toSend.replace(urlMarkdownRegex) { matchResult -> | ||
| val text = matchResult.groupValues[1].trim() | ||
|
|
@@ -170,10 +175,10 @@ private suspend fun CoroutineScope.spawnServerBots( | |
| if (availableServers != configServers) { | ||
| logger.warn( | ||
| """ | ||
| Supplied server keys in Discord configuration section does not match available servers: | ||
| Available servers: ${availableServers.joinToString()} | ||
| Configured servers: ${configServers.joinToString()} | ||
| """.trimIndent() | ||
| Supplied server keys in Discord configuration section does not match available servers: | ||
| Available servers: ${availableServers.joinToString()} | ||
| Configured servers: ${configServers.joinToString()} | ||
| """.trimIndent() | ||
| ) | ||
| } | ||
| return serverTokens.mapValues { (_, token) -> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes in config like this require a matching migration in
Config.kt, so that we don't have to manually edit config files unless actually necessary.For the comment: Better to remove it and instead rename the
channelIdfield itself to reflect the usage, if it's important. I thinkchannelIdis ok, butgameChatChannelIdwould indeed be more explicit. (And this would also require a migration)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought here would be to have an
allowedBotslist of IDs instead. It'd be a bit cleaner, if not a bit overengineered for our needs. (Although I can see that being useful on a testing server with multiple game chat bridges and Patrick instances... hmm)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought about a list too, but I didn't want to put too much into this PR. If you say these should come together though, I'll work on that today or tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to put it in this PR since it's being changed anyway (saves one config migration later too 😎). I think it's a nice idea so ye go ahead