Skip to content

Commit decfda1

Browse files
committed
Update Kotlin and JDA
1 parent bf453fa commit decfda1

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

build.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
55
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
66

77
plugins {
8-
// Kotlin 2.1.20 causes build failures on riscv64 and other archs
9-
// see GH-86.
10-
kotlin("jvm") version "2.1.10"
8+
kotlin("jvm") version "2.1.21"
119

1210
id("org.cadixdev.licenser") version "0.6.1"
1311
id("com.gradleup.shadow") version "8.3.5"
@@ -27,7 +25,7 @@ repositories {
2725
dependencies {
2826
implementation("org.kitteh.irc:client-lib:9.0.0")
2927
implementation("club.minnced:discord-webhooks:0.8.4")
30-
implementation("net.dv8tion:JDA:5.6.1") {
28+
implementation("net.dv8tion:JDA:6.0.0") {
3129
exclude(module = "opus-java")
3230
exclude(module = "tink")
3331
}

src/main/kotlin/io/zachbr/dis4irc/bridge/command/executors/PinnedMessagesCommand.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,23 @@ class PinnedMessagesCommand(private val bridge: Bridge) : Executor {
2323
}
2424

2525
val mappedChannel = bridge.channelMappings.getMappingFor(command.source) ?: throw IllegalStateException("No mapping for source channel: ${command.source}?!?")
26-
val pinnedMessages = bridge.discordConn.getPinnedMessages(mappedChannel) ?: return null
2726
// TODO add max limit (10 most recent?), flood concerns, UX spam, opinionated
28-
for (msg in pinnedMessages) {
29-
bridge.mutatorManager.applyMutator(TranslateFormatting::class.java, msg)
30-
val senderInfo = IrcMessageFormatter.createSenderPrefix(msg.sender, bridge.config.irc.antiPing, bridge.config.irc.useNickNameColor)
31-
var msgContent = msg.contents
32-
if (msg.attachments.isNotEmpty()) {
33-
msg.attachments.forEach { msgContent += " $it"}
27+
val pinnedMessages = bridge.discordConn.getPinnedMessages(mappedChannel) { pinned ->
28+
if (pinned == null) {
29+
bridge.ircConn.sendNotice(command.sender.displayName, "There are no pinned messages for ${command.source.channelName}.")
30+
return@getPinnedMessages
3431
}
3532

36-
bridge.ircConn.sendNotice(command.sender.displayName, "$senderInfo $msgContent")
33+
for (msg in pinned) {
34+
bridge.mutatorManager.applyMutator(TranslateFormatting::class.java, msg)
35+
val senderInfo = IrcMessageFormatter.createSenderPrefix(msg.sender, bridge.config.irc.antiPing, bridge.config.irc.useNickNameColor)
36+
var msgContent = msg.contents
37+
if (msg.attachments.isNotEmpty()) {
38+
msg.attachments.forEach { msgContent += " $it"}
39+
}
40+
41+
bridge.ircConn.sendNotice(command.sender.displayName, "$senderInfo $msgContent")
42+
}
3743
}
3844

3945
return null // don't send a message publicly

src/main/kotlin/io/zachbr/dis4irc/bridge/pier/discord/DiscordPier.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import net.dv8tion.jda.api.entities.Guild
3030
import net.dv8tion.jda.api.entities.Member
3131
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel
3232
import net.dv8tion.jda.api.requests.GatewayIntent
33+
import net.dv8tion.jda.api.requests.restaction.pagination.PinnedMessagePaginationAction
3334
import net.dv8tion.jda.api.utils.MemberCachePolicy
3435
import net.dv8tion.jda.api.utils.cache.CacheFlag
3536
import org.slf4j.Logger
@@ -46,7 +47,7 @@ class DiscordPier(private val bridge: Bridge) : Pier {
4647
override fun start() {
4748
logger.info("Connecting to Discord API...")
4849

49-
val intents = listOf(GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_EMOJIS_AND_STICKERS, GatewayIntent.MESSAGE_CONTENT)
50+
val intents = listOf(GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_EXPRESSIONS, GatewayIntent.MESSAGE_CONTENT)
5051
val discordApiBuilder = JDABuilder.createLight(bridge.config.discord.apiKey, intents)
5152
.setMemberCachePolicy(MemberCachePolicy.ALL) // so we can cache invisible members and ping people not online
5253
.enableCache(CacheFlag.EMOJI, CacheFlag.STICKER)
@@ -234,11 +235,13 @@ class DiscordPier(private val bridge: Bridge) : Pier {
234235
/**
235236
* Gets the pinned messages from the specified discord channel or null if the channel cannot be found
236237
*/
237-
fun getPinnedMessages(channelId: String): List<DiscordMessage>? {
238-
val channel = getTextChannelBy(channelId) ?: return null
239-
val messages = channel.retrievePinnedMessages().complete()
240-
241-
return messages.map { it.toPlatformMessage(logger) }.toList()
238+
fun getPinnedMessages(channelId: String, callback: (List<DiscordMessage>?) -> Unit) {
239+
getTextChannelBy(channelId)?.let { channel ->
240+
channel.retrievePinnedMessages().queue { pinnedMessages ->
241+
val platformMessages = pinnedMessages.map { it.message.toPlatformMessage(logger) }
242+
callback(platformMessages)
243+
}
244+
} ?: callback(null)
242245
}
243246

244247
/**

0 commit comments

Comments
 (0)