Skip to content

Commit

Permalink
Merge pull request #50 from nicholasgrose/discord_command_cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasgrose authored Dec 27, 2022
2 parents a7fa657 + 2051c7d commit 914ecf6
Show file tree
Hide file tree
Showing 34 changed files with 476 additions and 201 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project info
version=1.5.0-alpha-8
version=1.5.0-rc-1
group=com.rose.gateway
# Plugin configuration
# https://github.com/pinterest/ktlint
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.rose.gateway.config.access

import com.rose.gateway.config.PluginConfig

/**
* Gives whether the about extension is enabled from the plugin config
*
* @return Whether the extension is enabled
*/
fun PluginConfig.aboutExtensionEnabled(): Boolean {
return config.bot.extensions.about.enabled
}
21 changes: 21 additions & 0 deletions src/main/kotlin/com/rose/gateway/config/access/BotConfiguration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.rose.gateway.config.access

import com.rose.gateway.config.PluginConfig

/**
* Gives the Discord bot token from the plugin config
*
* @return The Discord bot's token
*/
fun PluginConfig.botToken(): String {
return config.bot.token
}

/**
* Gives the bot channels from the plugin config
*
* @return The Discord bot's bot channels
*/
fun PluginConfig.botChannels(): List<String> {
return config.bot.botChannels
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.rose.gateway.config.access

import com.rose.gateway.config.PluginConfig

/**
* Gives whether the chat extension is enabled from the plugin config
*
* @return Whether the extension is enabled
*/
fun PluginConfig.chatExtensionEnabled(): Boolean {
return config.bot.extensions.chat.enabled
}
21 changes: 21 additions & 0 deletions src/main/kotlin/com/rose/gateway/config/access/IpExtension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.rose.gateway.config.access

import com.rose.gateway.config.PluginConfig

/**
* Gives whether the ip extension is enabled from the plugin config
*
* @return Whether the extension is enabled
*/
fun PluginConfig.ipExtensionEnabled(): Boolean {
return config.bot.extensions.ip.enabled
}

/**
* The IP to display with the IP extension
*
* @return The IP to display
*/
fun PluginConfig.displayIp(): String {
return config.bot.extensions.ip.displayIp
}
21 changes: 21 additions & 0 deletions src/main/kotlin/com/rose/gateway/config/access/ListExtension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.rose.gateway.config.access

import com.rose.gateway.config.PluginConfig

/**
* Gives whether the list extension is enabled from the plugin config
*
* @return Whether the extension is enabled
*/
fun PluginConfig.listExtensionEnabled(): Boolean {
return config.bot.extensions.list.enabled
}

/**
* Gives the maximum number of players that can be displayed on each list page
*
* @return The maximum number of players per page
*/
fun PluginConfig.maxPlayersPerListPage(): Int {
return config.bot.extensions.list.maxPlayersPerPage
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.rose.gateway.config.extensions
package com.rose.gateway.config.access

import com.rose.gateway.config.PluginConfig
import com.rose.gateway.minecraft.color.asTextColor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.rose.gateway.config.access

import com.rose.gateway.config.PluginConfig

/**
* Gives whether the TPS extension is enabled from the plugin config
*
* @return Whether the extension is enabled
*/
fun PluginConfig.tpsExtensionEnabled(): Boolean {
return config.bot.extensions.tps.enabled
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.rose.gateway.config.access

import com.rose.gateway.config.PluginConfig

/**
* Gives whether the whitelist extension is enabled from the plugin config
*
* @return Whether the extension is enabled
*/
fun PluginConfig.whitelistExtensionEnabled(): Boolean {
return config.bot.extensions.whitelist.enabled
}

/**
* Gives the maximum number of players that can be displayed on each whitelist page
*
* @return The maximum number of players per page
*/
fun PluginConfig.maxPlayersPerWhitelistPage(): Int {
return config.bot.extensions.whitelist.maxPlayersPerPage
}

This file was deleted.

16 changes: 12 additions & 4 deletions src/main/kotlin/com/rose/gateway/config/schema/ListConfig.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.list.ListExtension
import com.rose.gateway.shared.serialization.SurrogateBasedSerializer
import com.rose.gateway.shared.serialization.SurrogateConverter
Expand All @@ -15,24 +16,31 @@ import kotlinx.serialization.Serializable
*/
@Serializable(with = ListConfigSerializer::class)
class ListConfig(
enabled: Boolean
enabled: Boolean,
/**
* The maximum number of player allowed per list page
*/
@ConfigItem("The maximum number of player allowed per list page") var maxPlayersPerPage: Int
) : CommonExtensionConfig(enabled, ListExtension.extensionName())

/**
* Surrogate for serialization of [ListConfig]
*
* @property enabled Whether the extension is enabled
* @property maxPlayersPerPage The maximum number of player allowed per list page
* @constructor Create a "list config" surrogate with the provided data
*
* @see ListConfig
* @see ListConfigSerializer
*/
@Serializable
data class ListConfigSurrogate(val enabled: Boolean) {
data class ListConfigSurrogate(val enabled: Boolean, val maxPlayersPerPage: Int) {
companion object : SurrogateConverter<ListConfig, ListConfigSurrogate> {
override fun fromBase(base: ListConfig): ListConfigSurrogate = ListConfigSurrogate(base.enabled)
override fun fromBase(base: ListConfig): ListConfigSurrogate =
ListConfigSurrogate(base.enabled, base.maxPlayersPerPage)

override fun toBase(surrogate: ListConfigSurrogate): ListConfig = ListConfig(surrogate.enabled)
override fun toBase(surrogate: ListConfigSurrogate): ListConfig =
ListConfig(surrogate.enabled, surrogate.maxPlayersPerPage)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import kotlinx.serialization.Serializable
/**
* Config options for Minecraft
*
* @property primaryColor The color used for labels and Discord mentions in-game
* @property secondaryColor The color used for differentiated text elements and names of Discord users in-game
* @property tertiaryColor The color used for labelling config paths
* @property warningColor The color used for marking problems and config items that can be null
* @property primaryColor Used to indicate success, color headers, and mark Discord mentions in-game
* @property secondaryColor Used to indicate information, differentiate text, and mark names of Discord users in-game
* @property tertiaryColor Used to indicate configuration paths and mark less important info
* @property warningColor Used to indicate errors/warnings and mark configurations that can be null
* @constructor Create empty Minecraft config
*/
@Serializable
data class MinecraftConfig(
@ConfigItem("Used for labels and Discord mentions in-game.")
@ConfigItem("Used to indicate success, color headers, and mark Discord mentions in-game")
var primaryColor: String,
@ConfigItem("Used for differentiated text elements and names of Discord users in-game.")
@ConfigItem("Used to indicate information, differentiate text, and mark names of Discord users in-game")
var secondaryColor: String,
@ConfigItem("Used for labelling config paths.")
@ConfigItem("Used to indicate configuration paths and mark less important info")
var tertiaryColor: String,
@ConfigItem("Used for marking problems and config items that can be null.")
@ConfigItem("Used to indicate errors/warnings and mark configurations that can be null")
var warningColor: String
) : ConfigObject
17 changes: 13 additions & 4 deletions src/main/kotlin/com/rose/gateway/config/schema/WhitelistConfig.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.whitelist.WhitelistExtension
import com.rose.gateway.shared.serialization.SurrogateBasedSerializer
import com.rose.gateway.shared.serialization.SurrogateConverter
Expand All @@ -9,30 +10,38 @@ import kotlinx.serialization.Serializable
/**
* Config options for the "whitelist extension"
*
* @property maxPlayersPerPage The maximum number of player allowed per list page
* @constructor Creates a "whitelist config" with the provided data
*
* @param enabled Whether the extension is enabled
*/
@Serializable(with = WhitelistConfigSerializer::class)
class WhitelistConfig(
enabled: Boolean
enabled: Boolean,
/**
* The maximum number of player allowed per list page
*/
@ConfigItem("The maximum number of player allowed per list page") var maxPlayersPerPage: Int
) : CommonExtensionConfig(enabled, WhitelistExtension.extensionName())

/**
* Surrogate for serialization of [WhitelistConfig]
*
* @property enabled Whether the extension is enabled
* @property maxPlayersPerPage The maximum number of player allowed per list page
* @constructor Create a "whitelist config" surrogate with the provided data
*
* @see WhitelistConfig
* @see WhitelistConfigSerializer
*/
@Serializable
data class WhitelistConfigSurrogate(val enabled: Boolean) {
data class WhitelistConfigSurrogate(val enabled: Boolean, val maxPlayersPerPage: Int) {
companion object : SurrogateConverter<WhitelistConfig, WhitelistConfigSurrogate> {
override fun fromBase(base: WhitelistConfig): WhitelistConfigSurrogate = WhitelistConfigSurrogate(base.enabled)
override fun fromBase(base: WhitelistConfig): WhitelistConfigSurrogate =
WhitelistConfigSurrogate(base.enabled, base.maxPlayersPerPage)

override fun toBase(surrogate: WhitelistConfigSurrogate): WhitelistConfig = WhitelistConfig(surrogate.enabled)
override fun toBase(surrogate: WhitelistConfigSurrogate): WhitelistConfig =
WhitelistConfig(surrogate.enabled, surrogate.maxPlayersPerPage)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/rose/gateway/discord/bot/BotContext.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.rose.gateway.discord.bot

import com.rose.gateway.config.PluginConfig
import com.rose.gateway.config.extensions.botChannels
import com.rose.gateway.config.access.botChannels
import com.rose.gateway.discord.bot.client.ClientInfo
import dev.kord.core.entity.Guild
import dev.kord.core.entity.channel.TextChannel
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/rose/gateway/discord/bot/DiscordBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.kotlindiscord.kord.extensions.ExtensibleBot
import com.kotlindiscord.kord.extensions.utils.loadModule
import com.rose.gateway.GatewayPlugin
import com.rose.gateway.config.PluginConfig
import com.rose.gateway.config.extensions.botToken
import com.rose.gateway.config.access.botToken
import com.rose.gateway.discord.bot.presence.BotPresence
import com.rose.gateway.minecraft.logging.Logger
import com.rose.gateway.shared.concurrency.PluginCoroutineScope
Expand Down
Loading

0 comments on commit 914ecf6

Please sign in to comment.