Skip to content

Commit

Permalink
Merge pull request #49 from nicholasgrose/help_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasgrose authored Dec 26, 2022
2 parents 31ffc3d + ca7caa6 commit a7fa657
Show file tree
Hide file tree
Showing 23 changed files with 281 additions and 208 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.rose.gateway.discord.bot.extensions.chat.processing

import com.rose.gateway.config.PluginConfig
import com.rose.gateway.config.extensions.primaryColor
import com.rose.gateway.minecraft.component.component
import com.rose.gateway.minecraft.component.primaryComponent
import com.rose.gateway.shared.parsing.TokenProcessor
import dev.kord.common.entity.Snowflake
import dev.kord.core.event.message.MessageCreateEvent
Expand All @@ -28,8 +29,8 @@ 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 Component.text(token.string)
val channel = additionalData.getGuild()!!.getChannelOrNull(id) ?: return token.string.component()

return Component.text("#${channel.name}", config.primaryColor())
return "#${channel.name}".primaryComponent()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.rose.gateway.discord.bot.extensions.chat.processing

import com.rose.gateway.config.PluginConfig
import com.rose.gateway.config.extensions.secondaryColor
import com.rose.gateway.minecraft.component.ColorComponent
import com.rose.gateway.minecraft.component.atMember
import com.rose.gateway.minecraft.component.component
import com.rose.gateway.minecraft.component.italic
import com.rose.gateway.minecraft.component.join
import com.rose.gateway.minecraft.component.member
import com.rose.gateway.minecraft.component.openUrlOnClick
import com.rose.gateway.minecraft.component.primaryComponent
import com.rose.gateway.minecraft.component.showTextOnHover
import com.rose.gateway.minecraft.component.tertiaryComponent
import com.rose.gateway.minecraft.component.underlined
import com.rose.gateway.shared.parsing.TextProcessor
import dev.kord.core.entity.Member
Expand Down Expand Up @@ -50,9 +52,9 @@ object DiscordMessageProcessor : KoinComponent {
*/
private fun generateNameBlock(event: MessageCreateEvent): Component {
return join(
Component.text("<"),
"<".component(),
member(event.member!!),
Component.text("> ")
"> ".component()
)
}

Expand All @@ -66,9 +68,9 @@ object DiscordMessageProcessor : KoinComponent {
val referenceComponent = componentForReferencedMessage(event) ?: return Component.empty()

return join(
ColorComponent.primary("(Replying to ").italic(),
"(Replying to ".primaryComponent().italic(),
referenceComponent,
ColorComponent.primary(") ").italic()
") ".primaryComponent().italic()
)
}

Expand Down Expand Up @@ -140,15 +142,15 @@ object DiscordMessageProcessor : KoinComponent {
if (event.message.attachments.isEmpty()) return Component.empty()

return join(
ColorComponent.primary(" (Attachments: ").italic(),
Component.join(
JoinConfiguration.separator(ColorComponent.primary(", ").italic()),
" (Attachments: ".primaryComponent().italic(),
join(
JoinConfiguration.separator(", ".primaryComponent().italic()),
event.message.attachments.mapIndexed { index, attachment ->
ColorComponent.tertiary("Attachment$index").italic().underlined()
.showTextOnHover(Component.text("Open attachment link")).openUrlOnClick(attachment.url)
"Attachment$index".tertiaryComponent().italic().underlined()
.showTextOnHover("Open attachment link".component()).openUrlOnClick(attachment.url)
}
),
ColorComponent.primary(")").italic()
")".primaryComponent().italic()
)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.rose.gateway.discord.bot.extensions.chat.processing

import com.rose.gateway.config.PluginConfig
import com.rose.gateway.config.extensions.primaryColor
import com.rose.gateway.minecraft.component.component
import com.rose.gateway.minecraft.component.primaryComponent
import com.rose.gateway.shared.parsing.TokenProcessor
import dev.kord.common.entity.Snowflake
import dev.kord.core.event.message.MessageCreateEvent
Expand Down Expand Up @@ -32,8 +33,8 @@ 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 Component.text(token.string)
val role = additionalData.getGuild()!!.getRoleOrNull(id) ?: return token.string.component()

return Component.text("@${role.name}", config.primaryColor())
return "@${role.name}".primaryComponent()
}
}
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.rose.gateway.minecraft.component.component
import com.rose.gateway.shared.parsing.TokenProcessor
import dev.kord.core.event.message.MessageCreateEvent
import guru.zoroark.lixy.LixyToken
Expand All @@ -19,6 +20,6 @@ class TextTokenProcessor : TokenProcessor<Component, MessageCreateEvent> {
override fun regexPattern(): String = ".[^<]*"

override suspend fun process(token: LixyToken, additionalData: MessageCreateEvent): Component {
return Component.text(token.string)
return token.string.component()
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.rose.gateway.discord.bot.extensions.chat.processing

import com.rose.gateway.minecraft.component.component
import com.rose.gateway.minecraft.component.openUrlOnClick
import com.rose.gateway.minecraft.component.showTextOnHover
import com.rose.gateway.minecraft.component.underlined
import com.rose.gateway.shared.parsing.TokenProcessor
import dev.kord.core.event.message.MessageCreateEvent
import guru.zoroark.lixy.LixyToken
import guru.zoroark.lixy.LixyTokenType
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.event.ClickEvent
import net.kyori.adventure.text.event.HoverEvent
import net.kyori.adventure.text.format.TextDecoration
import org.intellij.lang.annotations.Language

/**
Expand All @@ -24,9 +25,8 @@ class UrlTokenProcessor : TokenProcessor<Component, MessageCreateEvent> {
override suspend fun process(token: LixyToken, additionalData: MessageCreateEvent): Component {
val url = token.string

return Component.text(url)
.decorate(TextDecoration.UNDERLINED)
.hoverEvent(HoverEvent.showText(Component.text("Click to open url")))
.clickEvent(ClickEvent.openUrl(url))
return url.component().underlined()
.showTextOnHover("Click to open url".component())
.openUrlOnClick(url)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.rose.gateway.discord.bot.extensions.chat.processing
import com.rose.gateway.config.PluginConfig
import com.rose.gateway.config.extensions.primaryColor
import com.rose.gateway.minecraft.component.atMember
import com.rose.gateway.minecraft.component.component
import com.rose.gateway.shared.parsing.TokenProcessor
import dev.kord.common.entity.Snowflake
import dev.kord.core.event.message.MessageCreateEvent
Expand Down Expand Up @@ -33,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 Component.text(token.string)
val member = additionalData.getGuild()!!.getMemberOrNull(id) ?: return token.string.component()

return atMember(member, config.primaryColor())
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/rose/gateway/minecraft/CommandRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.rose.gateway.minecraft.commands.framework.subcommand.subcommand
import com.rose.gateway.minecraft.commands.runners.BotCommands
import com.rose.gateway.minecraft.commands.runners.ConfigCommands
import com.rose.gateway.minecraft.commands.runners.ConfigMonitoringRunner
import com.rose.gateway.minecraft.commands.runners.GeneralCommands
import com.rose.gateway.minecraft.commands.runners.DiscordCommands
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

Expand All @@ -32,7 +32,7 @@ object CommandRegistry : KoinComponent {
command("discord") {
subcommand("help") {
runner { context ->
GeneralCommands.discordHelp(context)
DiscordCommands.help(context)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.rose.gateway.minecraft.chat.processing.tokens

import com.rose.gateway.minecraft.chat.processing.tokens.result.TokenProcessingResult
import com.rose.gateway.minecraft.component.component
import com.rose.gateway.shared.parsing.TokenProcessor
import guru.zoroark.lixy.LixyToken
import guru.zoroark.lixy.LixyTokenType
import net.kyori.adventure.text.Component
import org.intellij.lang.annotations.Language

/**
Expand All @@ -25,6 +25,6 @@ class TextTokenProcessor : TokenProcessor<TokenProcessingResult, Unit> {
override suspend fun process(token: LixyToken, additionalData: Unit): TokenProcessingResult {
val text = token.string

return TokenProcessingResult(Component.text(text), text)
return TokenProcessingResult(text.component(), text)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.rose.gateway.minecraft.chat.processing.tokens

import com.rose.gateway.minecraft.chat.processing.tokens.result.TokenProcessingResult
import com.rose.gateway.minecraft.component.component
import com.rose.gateway.minecraft.component.openUrlOnClick
import com.rose.gateway.minecraft.component.showTextOnHover
import com.rose.gateway.minecraft.component.underlined
import com.rose.gateway.shared.parsing.TokenProcessor
import guru.zoroark.lixy.LixyToken
import guru.zoroark.lixy.LixyTokenType
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.event.ClickEvent
import net.kyori.adventure.text.event.HoverEvent
import net.kyori.adventure.text.format.TextDecoration
import org.intellij.lang.annotations.Language

/**
Expand All @@ -27,10 +27,9 @@ class UrlTokenProcessor : TokenProcessor<TokenProcessingResult, Unit> {

override suspend fun process(token: LixyToken, additionalData: Unit): TokenProcessingResult {
val url = token.string
val component = Component.text(url)
.decorate(TextDecoration.UNDERLINED)
.hoverEvent(HoverEvent.showText(Component.text("Click to open url")))
.clickEvent(ClickEvent.openUrl(url))
val component = url.component().underlined()
.showTextOnHover("Click to open url".component())
.openUrlOnClick(url)

return TokenProcessingResult(component, url)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.rose.gateway.config.PluginConfig
import com.rose.gateway.config.extensions.primaryColor
import com.rose.gateway.discord.bot.DiscordBot
import com.rose.gateway.discord.bot.DiscordBotConstants
import com.rose.gateway.minecraft.component.ColorComponent
import com.rose.gateway.minecraft.component.atMember
import com.rose.gateway.minecraft.component.primaryComponent
import dev.kord.common.annotation.KordExperimental
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.toSet
Expand All @@ -28,7 +28,7 @@ object MentionResult : KoinComponent {
*/
fun mention(minecraftText: String, discordText: String): TokenProcessingResult {
return TokenProcessingResult(
ColorComponent.primary(minecraftText),
minecraftText.primaryComponent(),
discordText
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.rose.gateway.minecraft.chat.processing.tokens.result

import com.rose.gateway.minecraft.component.ColorComponent
import com.rose.gateway.minecraft.component.warningComponent
import net.kyori.adventure.text.Component

/**
Expand All @@ -23,7 +23,7 @@ data class TokenProcessingResult(
*/
fun error(text: String): TokenProcessingResult {
return TokenProcessingResult(
ColorComponent.warning(text),
text.warningComponent(),
text
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.rose.gateway.minecraft.commands.runners

import com.rose.gateway.config.PluginConfig
import com.rose.gateway.config.extensions.primaryColor
import com.rose.gateway.discord.bot.BotStatus
import com.rose.gateway.discord.bot.DiscordBot
import com.rose.gateway.minecraft.commands.framework.data.context.CommandExecuteContext
import com.rose.gateway.minecraft.commands.framework.runner.NoArgs
import com.rose.gateway.minecraft.component.component
import com.rose.gateway.minecraft.component.joinSpace
import com.rose.gateway.minecraft.component.primaryComponent
import com.rose.gateway.minecraft.logging.Logger
import com.rose.gateway.shared.concurrency.PluginCoroutineScope
import kotlinx.coroutines.launch
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.JoinConfiguration
import org.bukkit.command.CommandSender
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
Expand Down Expand Up @@ -68,11 +68,10 @@ object BotCommands : KoinComponent {
fun botStatus(context: CommandExecuteContext<NoArgs>): Boolean {
val status = bot.botStatus
context.bukkit.sender.sendMessage(
Component.join(
JoinConfiguration.separator(Component.text(" ")),
Component.text("Bot Status:", config.primaryColor()),
Component.text(status.status),
Component.text(if (status.reason.isEmpty()) "" else "(${status.reason})")
joinSpace(
"Bot Status:".primaryComponent(),
status.status.component(),
(if (status.reason.isEmpty()) "" else "(${status.reason})").component()
)
)

Expand Down
Loading

0 comments on commit a7fa657

Please sign in to comment.