Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Commit

Permalink
Add more fields to the Member interface, add InteractionMember interf…
Browse files Browse the repository at this point in the history
…ace, use our own custom Kord fork for now (#22)

* Add more fields to the Member interface, add InteractionMember interface

Does not compile because kordlib/kord#502 needs to be merged first

* Use our own fork while Kord our changes aren't merged yet
  • Loading branch information
MrPowerGamerBR authored Feb 9, 2022
1 parent 37e9e22 commit 6957ea0
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 21 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object Versions {
const val DISCORD_INTERAKTIONS = "0.0.12-SNAPSHOT"
const val KOTLIN = "1.6.10"
const val KORD = "0.8.x-SNAPSHOT"
const val KORD = "0.8.x-lori-fork-SNAPSHOT"
const val KTOR = "1.6.7"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ package net.perfectdreams.discordinteraktions.common.autocomplete

import dev.kord.common.entity.DiscordInteraction
import dev.kord.common.entity.Snowflake
import net.perfectdreams.discordinteraktions.common.InteractionContext
import net.perfectdreams.discordinteraktions.common.entities.Member
import net.perfectdreams.discordinteraktions.common.entities.InteractionMember
import net.perfectdreams.discordinteraktions.common.entities.User
import net.perfectdreams.discordinteraktions.common.interactions.InteractionData
import net.perfectdreams.discordinteraktions.common.requests.RequestBridge

open class GuildAutocompleteContext(
sender: User,
channelId: Snowflake,
data: InteractionData,
discordInteractionData: DiscordInteraction,
val guildId: Snowflake,
val member: Member
val member: InteractionMember
) : AutocompleteContext(sender, channelId, data, discordInteractionData)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.perfectdreams.discordinteraktions.common.commands

import net.perfectdreams.discordinteraktions.common.entities.Member
import net.perfectdreams.discordinteraktions.common.entities.InteractionMember
import net.perfectdreams.discordinteraktions.common.entities.User
import net.perfectdreams.discordinteraktions.common.commands.options.SlashCommandArguments
import net.perfectdreams.discordinteraktions.common.entities.messages.Message
Expand Down Expand Up @@ -33,7 +33,7 @@ abstract class SlashCommandExecutor : ApplicationCommandExecutor() {
* want to create an User Command.
*/
abstract class UserCommandExecutor : ApplicationCommandExecutor() {
abstract suspend fun execute(context: ApplicationCommandContext, targetUser: User, targetMember: Member?)
abstract suspend fun execute(context: ApplicationCommandContext, targetUser: User, targetMember: InteractionMember?)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package net.perfectdreams.discordinteraktions.common.commands

import dev.kord.common.entity.DiscordInteraction
import dev.kord.common.entity.Snowflake
import net.perfectdreams.discordinteraktions.common.entities.Member
import net.perfectdreams.discordinteraktions.common.entities.InteractionMember
import net.perfectdreams.discordinteraktions.common.entities.User
import net.perfectdreams.discordinteraktions.common.requests.RequestBridge
import net.perfectdreams.discordinteraktions.common.interactions.InteractionData
Expand All @@ -14,5 +14,5 @@ open class GuildApplicationCommandContext(
data: InteractionData,
discordInteractionData: DiscordInteraction,
val guildId: Snowflake,
val member: Member
val member: InteractionMember
) : ApplicationCommandContext(bridge, sender, channelId, data, discordInteractionData)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package net.perfectdreams.discordinteraktions.common.components

import dev.kord.common.entity.DiscordInteraction
import dev.kord.common.entity.Snowflake
import net.perfectdreams.discordinteraktions.common.entities.Member
import net.perfectdreams.discordinteraktions.common.entities.InteractionMember
import net.perfectdreams.discordinteraktions.common.entities.User
import net.perfectdreams.discordinteraktions.common.requests.RequestBridge
import net.perfectdreams.discordinteraktions.common.entities.messages.Message
Expand All @@ -16,5 +16,5 @@ open class GuildComponentContext(
data: InteractionData,
discordInteractionData: DiscordInteraction,
val guildId: Snowflake,
val member: Member
val member: InteractionMember
) : ComponentContext(bridge, sender, channelId, message, data, discordInteractionData)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.perfectdreams.discordinteraktions.common.entities

import dev.kord.common.entity.Permissions
import dev.kord.common.entity.Snowflake
import kotlinx.datetime.Instant

interface InteractionMember : Member {
val permissions: Permissions
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package net.perfectdreams.discordinteraktions.common.entities

import dev.kord.common.entity.Snowflake
import kotlinx.datetime.Instant

interface Member {
val user: User
val nick: String?
val roles: List<Snowflake>
val joinedAt: Instant
val premiumSince: Instant?
val pending: Boolean
val avatar: UserAvatar?
val communicationDisabledUntil: Instant?
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.perfectdreams.discordinteraktions.common.entities.messages
import dev.kord.common.entity.DiscordAttachment
import dev.kord.common.entity.Snowflake
import kotlinx.datetime.Instant
import net.perfectdreams.discordinteraktions.common.entities.InteractionMember
import net.perfectdreams.discordinteraktions.common.entities.Member
import net.perfectdreams.discordinteraktions.common.entities.User

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.perfectdreams.discordinteraktions.common.interactions

import dev.kord.common.entity.Snowflake
import net.perfectdreams.discordinteraktions.common.entities.Member
import net.perfectdreams.discordinteraktions.common.entities.InteractionMember
import net.perfectdreams.discordinteraktions.common.entities.User
import net.perfectdreams.discordinteraktions.common.entities.messages.Message

// TODO: channels
// TODO: roles
class ResolvedObjects(
val users: Map<Snowflake, User>?,
val members: Map<Snowflake, Member>?,
val members: Map<Snowflake, InteractionMember>?,
val messages: Map<Snowflake, Message>?
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
package net.perfectdreams.discordinteraktions.platforms.kord.entities

import dev.kord.common.entity.DiscordInteractionGuildMember
import net.perfectdreams.discordinteraktions.common.entities.Member
import kotlinx.datetime.Instant
import net.perfectdreams.discordinteraktions.common.entities.InteractionMember
import net.perfectdreams.discordinteraktions.common.entities.User
import net.perfectdreams.discordinteraktions.common.entities.UserAvatar

// This is the same thing as KordMember, however an Interaction guild member does not have a deaf or mute flag
class KordInteractionMember(
val handle: DiscordInteractionGuildMember,
override val user: User // The user object is here too because sometimes the handle user value may be null!
) : Member {
override val roles = handle.roles
) : InteractionMember {
override val nick: String?
get() = handle.nick.value
override val roles by handle::roles
override val joinedAt = Instant.parse(handle.joinedAt)
override val premiumSince = handle.premiumSince.value?.let { Instant.parse(it) }
override val permissions by handle::permissions
override val pending: Boolean
get() = handle.pending.discordBoolean
override val avatar = handle.avatar.value?.let {
UserAvatar(
user.id.value,
user.discriminator.toInt(),
it
)
}
override val communicationDisabledUntil: Instant?
get() = handle.communicationDisabledUntil.value
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
package net.perfectdreams.discordinteraktions.platforms.kord.entities

import dev.kord.common.entity.DiscordGuildMember
import dev.kord.common.entity.DiscordInteractionGuildMember
import kotlinx.datetime.Instant
import net.perfectdreams.discordinteraktions.common.entities.InteractionMember
import net.perfectdreams.discordinteraktions.common.entities.Member
import net.perfectdreams.discordinteraktions.common.entities.User
import net.perfectdreams.discordinteraktions.common.entities.UserAvatar

// This is the same thing as KordMember, however an Interaction guild member does not have a deaf or mute flag
class KordMember(
val handle: DiscordGuildMember,
override val user: User // The user object is here too because sometimes the handle user value may be null!
) : Member {
override val roles = handle.roles
override val nick: String?
get() = handle.nick.value
override val roles by handle::roles
override val joinedAt = Instant.parse(handle.joinedAt)
override val premiumSince = handle.premiumSince.value?.let { Instant.parse(it) }
override val pending: Boolean
get() = handle.pending.discordBoolean
override val avatar = handle.avatar.value?.let {
UserAvatar(
user.id.value,
user.discriminator.toInt(),
it
)
}
override val communicationDisabledUntil: Instant?
get() = handle.communicationDisabledUntil.value
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package net.perfectdreams.discordinteraktions.platforms.kord.entities.messages
import dev.kord.common.entity.DiscordAttachment
import dev.kord.common.entity.Snowflake
import kotlinx.datetime.Instant
import net.perfectdreams.discordinteraktions.common.entities.Member
import net.perfectdreams.discordinteraktions.common.entities.InteractionMember
import net.perfectdreams.discordinteraktions.common.entities.User
import net.perfectdreams.discordinteraktions.common.entities.messages.Message

Expand All @@ -16,7 +16,7 @@ open class OriginalInteractionMessage : Message {
get() = fail()
override val author: User
get() = fail()
override val member: Member?
override val member: InteractionMember?
get() = fail()
override val content: String
get() = fail()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.perfectdreams.discordinteraktions.platforms.kord.utils

import dev.kord.common.entity.ResolvedObjects
import dev.kord.common.entity.optional.Optional
import net.perfectdreams.discordinteraktions.platforms.kord.entities.KordInteractionMember
import net.perfectdreams.discordinteraktions.platforms.kord.entities.KordMember
import net.perfectdreams.discordinteraktions.platforms.kord.entities.KordUser
import net.perfectdreams.discordinteraktions.platforms.kord.entities.messages.KordMessage
Expand All @@ -16,7 +17,7 @@ fun ResolvedObjects.toDiscordInteraKTionsResolvedObjects(): net.perfectdreams.di

val members = this.members.value?.map {
// In this case, the user map contains the user object, so we need to get it from there
it.key to KordMember(
it.key to KordInteractionMember(
it.value,
users?.get(it.key)!! // Should NEVER be null!
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package com.mrpowergamerbr.nicolebot.commands

import com.mrpowergamerbr.nicolebot.utils.Counter
import dev.kord.common.entity.ButtonStyle
import dev.kord.common.entity.Snowflake
import dev.kord.rest.builder.message.create.UserMessageCreateBuilder
import dev.kord.rest.service.RestClient
import kotlinx.serialization.json.JsonNull.content
import net.perfectdreams.discordinteraktions.common.builder.message.MessageBuilder
import net.perfectdreams.discordinteraktions.common.builder.message.actionRow
import net.perfectdreams.discordinteraktions.common.commands.ApplicationCommandContext
import net.perfectdreams.discordinteraktions.common.commands.SlashCommandExecutor
import net.perfectdreams.discordinteraktions.common.commands.SlashCommandExecutorDeclaration
import net.perfectdreams.discordinteraktions.common.commands.options.SlashCommandArguments
import net.perfectdreams.discordinteraktions.common.components.interactiveButton
import net.perfectdreams.discordinteraktions.common.entities.messages.editMessage

class CounterExecutor(private val counter: Counter) : SlashCommandExecutor() {
companion object : SlashCommandExecutorDeclaration(CounterExecutor::class) {
Expand All @@ -33,6 +38,8 @@ class CounterExecutor(private val counter: Counter) : SlashCommandExecutor() {
override suspend fun execute(context: ApplicationCommandContext, args: SlashCommandArguments) {
val currentCount = counter.get()

context.sendMessage(createCounterMessage(currentCount))
context.sendMessage {
apply(createCounterMessage(currentCount))
}
}
}

0 comments on commit 6957ea0

Please sign in to comment.