Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Fix sending embed DMs to users
Browse files Browse the repository at this point in the history
  • Loading branch information
NoComment1105 committed Mar 8, 2024
1 parent bd35ba7 commit 4168b2e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

object Meta {
const val projectVersion = "0.2.2"
const val projectVersion = "0.2.3"
const val description =
"Create moderation actions with ease, reduce code duplication and making things easy in KordEx discord bots"
const val githubRepo = "HyacinthBots/discord-moderation-actions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ internal suspend inline fun SlashCommandContext<*, *, *>.sendDm(
).getMemberOrNull(targetUserId)
val dm = if (member != null) {
event.kord.getUser(targetUserId)?.dm {
embeds?.add(EmbedBuilder().applyBuilder(dmEmbedBuilder))
val embed = EmbedBuilder().applyBuilder(dmEmbedBuilder)
// Cannot flatten because compiler rules are annoying
if (embeds?.add(embed) != null) {
embeds?.add(embed)
} else {
embeds = mutableListOf(embed)
}
}
} else {
null
Expand Down Expand Up @@ -129,11 +135,11 @@ internal suspend inline fun sendPrivateLog(
PrivateLogResult.LOG_NOT_SENT
}

@OptIn(ExperimentalContracts::class)
public suspend inline fun <T> T.applyBuilder(crossinline block: suspend T.() -> Unit): T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
block()
return this
}
@OptIn(ExperimentalContracts::class)
public suspend inline fun <T> T.applyBuilder(crossinline block: suspend T.() -> Unit): T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
block()
return this
}

0 comments on commit 4168b2e

Please sign in to comment.