Skip to content

Commit

Permalink
Merge pull request #74 from nicholasgrose/develop-1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasgrose authored Apr 1, 2023
2 parents 3c03320 + 97ac6c3 commit 31a3dba
Show file tree
Hide file tree
Showing 21 changed files with 118 additions and 53 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/pull_request_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Check Pull Request
on:
pull_request:
branches:
- develop**
- main

paths:
Expand Down Expand Up @@ -41,7 +42,7 @@ jobs:
- uses: actions/checkout@v3

# https://github.com/marketplace/actions/run-ktlint-with-reviewdog
- uses: ScaCap/action-ktlint@1.4
- uses: ScaCap/action-ktlint@1.5.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
ktlint_version: '0.45.2'
Expand All @@ -57,7 +58,7 @@ jobs:

# https://github.com/marketplace/actions/run-detekt-with-reviewdog
- name: Run detekt with reviewdog
uses: alaegin/[email protected]-RC3
uses: alaegin/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
detekt_config: config/detekt/detekt.yml
Expand Down
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
plugins {
// https://kotlinlang.org/
kotlin("jvm") version "1.7.21"
kotlin("jvm") version "1.8.10"
// https://kotlinlang.org/docs/serialization.html
kotlin("plugin.serialization") version "1.7.21"
kotlin("plugin.serialization") version "1.8.10"
// https://github.com/johnrengelman/shadow
id("com.github.johnrengelman.shadow") version "7.1.2"
id("com.github.johnrengelman.shadow") version "8.1.1"
// https://github.com/jpenilla/run-paper
id("xyz.jpenilla.run-paper") version "2.0.1"
// https://github.com/jlleitschuh/ktlint-gradle
id("org.jlleitschuh.gradle.ktlint") version "11.0.0"
id("org.jlleitschuh.gradle.ktlint") version "11.3.1"
// https://detekt.dev/
id("io.gitlab.arturbosch.detekt") version "1.22.0"
}
Expand Down Expand Up @@ -42,7 +42,7 @@ repositories {
}
maven {
name = "Kotlin Discord"
url = uri("https://maven.kotlindiscord.com/repository/maven-public/")
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
maven {
name = "Jitpack"
Expand Down Expand Up @@ -90,7 +90,7 @@ tasks {
processResources {
filesMatching("plugin.yml") {
expand(
"version" to version
"version" to version,
)
}
}
Expand Down
18 changes: 9 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Project info
version=1.5.0
version=1.6.0-alpha-1
group=com.rose.gateway
# Plugin configuration
# https://github.com/pinterest/ktlint
# Must use 0.45.2 until https://github.com/JLLeitschuh/ktlint-gradle/pull/595 is closed and plugin updated
ktlintVersion=0.45.2
# Dependencies
minecraftVersion=1.19.3
# https://papermc.io/using-the-api#gradle
minecraftVersion=1.19.4
# https://docs.papermc.io/paper/dev/project-setup
paperApiRevision=R0.1
# https://github.com/sksamuel/hoplite
hopliteVersion=2.7.0
hopliteVersion=2.7.3
# https://github.com/charleskorn/kaml
kamlVersion=0.49.0
kamlVersion=0.53.0
# https://kordex.kotlindiscord.com/
kordexVersion=1.5.6-SNAPSHOT
kordexVersion=1.5.7-SNAPSHOT
# https://github.com/utybo/Lixy
lixyVersion=master-SNAPSHOT
# https://ktor.io/
ktorVersion=2.2.1
ktorVersion=2.2.4
# Compilation options for Kotlin
jvmVersion=17
kotlinLanguageVersion=1.7
kotlinApiVersion=1.7
kotlinLanguageVersion=1.8
kotlinApiVersion=1.8
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 14 additions & 4 deletions src/main/kotlin/com/rose/gateway/config/schema/ChatConfig.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rose.gateway.config.schema

import com.rose.gateway.config.markers.CommonExtensionConfig
import com.rose.gateway.config.markers.ConfigItem
import com.rose.gateway.discord.bot.extensions.chat.ChatExtension
import com.rose.gateway.shared.serialization.SurrogateBasedSerializer
import com.rose.gateway.shared.serialization.SurrogateConverter
Expand All @@ -9,30 +10,39 @@ import kotlinx.serialization.Serializable
/**
* Config options for the "chat extension"
*
* @property showRoleColor Whether Discord role colors are shown
* @constructor Creates a "chat config" with the provided data
*
* @param enabled Whether the extension is enabled
*/
@Serializable(with = ChatConfigSerializer::class)
class ChatConfig(
enabled: Boolean
enabled: Boolean,
@ConfigItem("Whether Discord role colors are shown in Minecraft chat") val showRoleColor: Boolean
) : CommonExtensionConfig(enabled, ChatExtension.extensionName())

/**
* Surrogate for serialization of [ChatConfig]
*
* @property enabled Whether the extension is enabled
* @property showRoleColor Whether Discord role colors are shown
* @constructor Create a "chat config" surrogate with the provided data
*
* @see ChatConfig
* @see ChatConfigSerializer
*/
@Serializable
data class ChatConfigSurrogate(val enabled: Boolean) {
data class ChatConfigSurrogate(val enabled: Boolean, val showRoleColor: Boolean) {
companion object : SurrogateConverter<ChatConfig, ChatConfigSurrogate> {
override fun fromBase(base: ChatConfig): ChatConfigSurrogate = ChatConfigSurrogate(base.enabled)
override fun fromBase(base: ChatConfig): ChatConfigSurrogate = ChatConfigSurrogate(
base.enabled,
base.showRoleColor
)

override fun toBase(surrogate: ChatConfigSurrogate): ChatConfig = ChatConfig(surrogate.enabled)
override fun toBase(surrogate: ChatConfigSurrogate): ChatConfig = ChatConfig(
surrogate.enabled,
surrogate.showRoleColor
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.rose.gateway.discord.bot.extensions.about
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand
import com.kotlindiscord.kord.extensions.types.respond
import com.rose.gateway.GatewayPlugin
import com.rose.gateway.config.PluginConfig
import com.rose.gateway.config.access.aboutExtensionEnabled
import com.rose.gateway.config.access.secondaryColor
import com.rose.gateway.discord.bot.extensions.ExtensionToggle
import com.rose.gateway.minecraft.logging.Logger
import dev.kord.common.Color
import dev.kord.rest.builder.message.create.embed
import org.bukkit.Bukkit
import org.koin.core.component.inject

/**
Expand All @@ -29,22 +29,20 @@ class AboutExtension : Extension() {
override fun isEnabled(): Boolean = config.aboutExtensionEnabled()
}

private val plugin: GatewayPlugin by inject()

override val name = extensionName()

override suspend fun setup() {
ephemeralSlashCommand {
name = "version"
description = "Gives the current version of the Gateway plugin"
description = "Gives the current version of the Minecraft server"

action {
Logger.info("${user.asUserOrNull()?.username} requested plugin version!")

respond {
embed {
title = plugin.description.version
description = "All versions are available at https://github.com/nicholasgrose/Gateway/releases."
title = "Minecraft Version"
description = Bukkit.getMinecraftVersion()
color = Color(config.secondaryColor().value())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ChannelMentionTokenProcessor : TokenProcessor<Component, MessageCreateEven
override suspend fun process(token: LixyToken, additionalData: MessageCreateEvent): Component {
val snowflakeString = token.string.substring(2 until token.string.length - 1)
val id = Snowflake(snowflakeString)
val channel = additionalData.getGuild()!!.getChannelOrNull(id) ?: return token.string.component()
val channel = additionalData.getGuildOrNull()?.getChannelOrNull(id) ?: return token.string.component()

return "#${channel.name}".primaryComponent()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rose.gateway.discord.bot.extensions.chat.processing

import com.kotlindiscord.kord.extensions.utils.getTopRole
import com.rose.gateway.config.PluginConfig
import com.rose.gateway.config.access.secondaryColor
import com.rose.gateway.minecraft.component.atMember
Expand All @@ -16,8 +17,10 @@ import com.rose.gateway.shared.parsing.TextProcessor
import dev.kord.core.entity.Member
import dev.kord.core.entity.Message
import dev.kord.core.event.message.MessageCreateEvent
import kotlinx.coroutines.flow.toList
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.JoinConfiguration
import net.kyori.adventure.text.format.TextColor
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

Expand All @@ -40,7 +43,7 @@ object DiscordMessageProcessor : KoinComponent {
generateNameBlock(event),
generateMessagePrefixBlock(event),
generateMessageBlock(event),
generateMessageSuffixBlock(event)
generateMessageSuffixBlock(event),
)
}

Expand All @@ -50,11 +53,21 @@ object DiscordMessageProcessor : KoinComponent {
* @param event The event to convert into a name block
* @return The name block
*/
private fun generateNameBlock(event: MessageCreateEvent): Component {
private suspend fun generateNameBlock(event: MessageCreateEvent): Component {
if (!(config.config.bot.extensions.chat.showRoleColor) || event.member!!.roles.toList().isEmpty()) {
return join(
"<".component(),
member(event.member!!),
"> ".component(),
)
}

val roleColor = event.member!!.getTopRole()?.color?.let { TextColor.color(it.rgb) }

return join(
"<".component(),
member(event.member!!),
"> ".component()
member(event.member!!).color(roleColor),
"> ".component(),
)
}

Expand All @@ -70,7 +83,7 @@ object DiscordMessageProcessor : KoinComponent {
return join(
"(Replying to ".primaryComponent().italic(),
referenceComponent,
") ".primaryComponent().italic()
") ".primaryComponent().italic(),
)
}

Expand Down Expand Up @@ -109,7 +122,7 @@ object DiscordMessageProcessor : KoinComponent {
private suspend fun referencedMessageAuthor(referencedMessage: Message, event: MessageCreateEvent): Member? {
val referencedAuthor = referencedMessage.author?.id ?: return null

return event.getGuild()?.getMemberOrNull(referencedAuthor)
return event.getGuildOrNull()?.getMemberOrNull(referencedAuthor)
}

private val textProcessor = TextProcessor(
Expand All @@ -118,8 +131,8 @@ object DiscordMessageProcessor : KoinComponent {
UserMentionTokenProcessor(),
RoleMentionTokenProcessor(),
ChannelMentionTokenProcessor(),
TextTokenProcessor()
)
TextTokenProcessor(),
),
)

/**
Expand Down Expand Up @@ -148,9 +161,9 @@ object DiscordMessageProcessor : KoinComponent {
event.message.attachments.mapIndexed { index, attachment ->
"Attachment$index".tertiaryComponent().italic().underlined()
.showTextOnHover("Open attachment link".component()).openUrlOnClick(attachment.url)
}
},
),
")".primaryComponent().italic()
")".primaryComponent().italic(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RoleMentionTokenProcessor : TokenProcessor<Component, MessageCreateEvent>,
override suspend fun process(token: LixyToken, additionalData: MessageCreateEvent): Component {
val snowflakeString = token.string.substring(SNOWFLAKE_START_INDEX until token.string.length - 1)
val id = Snowflake(snowflakeString)
val role = additionalData.getGuild()!!.getRoleOrNull(id) ?: return token.string.component()
val role = additionalData.getGuildOrNull()?.getRoleOrNull(id) ?: return token.string.component()

return "@${role.name}".primaryComponent()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class UserMentionTokenProcessor : TokenProcessor<Component, MessageCreateEvent>,
override suspend fun process(token: LixyToken, additionalData: MessageCreateEvent): Component {
val snowflakeString = token.string.substring(SNOWFLAKE_START_INDEX until token.string.length - 1)
val id = Snowflake(snowflakeString)
val member = additionalData.getGuild()!!.getMemberOrNull(id) ?: return token.string.component()
val member = additionalData.getGuildOrNull()?.getMemberOrNull(id) ?: return token.string.component()

return atMember(member, config.primaryColor())
}
Expand Down
Loading

0 comments on commit 31a3dba

Please sign in to comment.