Skip to content

Commit

Permalink
feat: Ignore Type (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuahp authored Nov 5, 2023
1 parent 70447a4 commit adb83e4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
13 changes: 6 additions & 7 deletions src/main/kotlin/com/jaoafa/vcspeaker/commands/AliasCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import com.jaoafa.vcspeaker.stores.AliasStore
import com.jaoafa.vcspeaker.stores.AliasType
import com.jaoafa.vcspeaker.tools.discord.DiscordExtensions.authorOf
import com.jaoafa.vcspeaker.tools.discord.DiscordExtensions.errorColor
import com.jaoafa.vcspeaker.tools.discord.SlashCommandExtensions.publicSlashCommand
import com.jaoafa.vcspeaker.tools.discord.SlashCommandExtensions.publicSubCommand
import com.jaoafa.vcspeaker.tools.discord.DiscordExtensions.respondEmbed
import com.jaoafa.vcspeaker.tools.discord.DiscordExtensions.successColor
import com.jaoafa.vcspeaker.tools.discord.Options
import com.jaoafa.vcspeaker.tools.discord.SlashCommandExtensions.publicSlashCommand
import com.jaoafa.vcspeaker.tools.discord.SlashCommandExtensions.publicSubCommand
import com.kotlindiscord.kord.extensions.commands.application.slash.converters.impl.optionalStringChoice
import com.kotlindiscord.kord.extensions.commands.application.slash.converters.impl.stringChoice
import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalString
Expand Down Expand Up @@ -196,12 +196,11 @@ class AliasCommand : Extension() {
page {
authorOf(user)

for (alias in chunkedAliases) {
val (_, _, type, from, to) = alias
title = ":information_source: Aliases"

field("${type.emoji} ${type.displayName}", false) {
"${if (type == AliasType.Regex) "`$from`" else from}$to"
}
description = chunkedAliases.joinToString("\n") { (_, userId, type, from, to) ->
val fromDisplay = if (type == AliasType.Regex) "`$from`" else from
"${type.emoji} ${type.displayName} | 「$fromDisplay$to」 | <@${userId}>"
}

successColor()
Expand Down
37 changes: 28 additions & 9 deletions src/main/kotlin/com/jaoafa/vcspeaker/commands/IgnoreCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.jaoafa.vcspeaker.commands

import com.jaoafa.vcspeaker.stores.IgnoreData
import com.jaoafa.vcspeaker.stores.IgnoreStore
import com.jaoafa.vcspeaker.stores.IgnoreType
import com.jaoafa.vcspeaker.tools.discord.DiscordExtensions.authorOf
import com.jaoafa.vcspeaker.tools.discord.DiscordExtensions.errorColor
import com.jaoafa.vcspeaker.tools.discord.SlashCommandExtensions.publicSlashCommand
import com.jaoafa.vcspeaker.tools.discord.SlashCommandExtensions.publicSubCommand
import com.jaoafa.vcspeaker.tools.discord.DiscordExtensions.respondEmbed
import com.jaoafa.vcspeaker.tools.discord.DiscordExtensions.successColor
import com.jaoafa.vcspeaker.tools.discord.Options
import com.jaoafa.vcspeaker.tools.discord.SlashCommandExtensions.publicSlashCommand
import com.jaoafa.vcspeaker.tools.discord.SlashCommandExtensions.publicSubCommand
import com.kotlindiscord.kord.extensions.commands.application.slash.converters.impl.stringChoice
import com.kotlindiscord.kord.extensions.commands.converters.impl.string
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.types.respondingPaginator
Expand All @@ -19,6 +21,13 @@ class IgnoreCommand : Extension() {
override val name = this::class.simpleName!!

inner class CreateOptions : Options() {
val type by stringChoice {
name = "type"
description = "無視判定の種類"
for (ignoreType in IgnoreType.entries)
choice(ignoreType.displayName, ignoreType.name)
}

val text by string {
name = "text"
description = "無視する文字列"
Expand All @@ -45,15 +54,18 @@ class IgnoreCommand : Extension() {
publicSlashCommand("ignore", "無視機能を設定します。") {
publicSubCommand("create", "無視する文字列を作成します。", ::CreateOptions) {
action {
val type = IgnoreType.valueOf(arguments.type)
val text = arguments.text
val duplicateExists = IgnoreStore.find(guild!!.id, text) != null

if (!duplicateExists)
IgnoreStore.create(IgnoreData(guild!!.id, user.id, text))
IgnoreStore.create(IgnoreData(guild!!.id, user.id, type, text))

val typeText = if (type == IgnoreType.Contains) "を含む" else "と一致する"

respondEmbed(
":face_with_symbols_over_mouth: Ignore Created",
"今後「$textを含むメッセージは読み上げられません"
"今後「$text${typeText}メッセージは読み上げられません"
) {
authorOf(user)
successColor()
Expand All @@ -69,17 +81,22 @@ class IgnoreCommand : Extension() {
if (target != null) {
IgnoreStore.remove(target)

val typeText = if (target.type == IgnoreType.Contains) "が含まれて" else "と一致して"

respondEmbed(
":wastebasket: Ignore Deleted",
"$textが含まれていても読み上げます"
"$text${typeText}いても読み上げます"
) {
authorOf(user)
successColor()
}
} else {
respondEmbed(
":question: Ignore Not Found",
"$text」を含むメッセージは無視されていません。"
"""
$text」に一致する設定が見つかりませんでした。
`/ignore list` で一覧を確認できます。
""".trimIndent()
)
}
}
Expand All @@ -92,7 +109,7 @@ class IgnoreCommand : Extension() {
if (ignores.isEmpty()) {
respondEmbed(
":grey_question: Ignores Not Found",
"無視機能が設定されていないようです。`/ignore create` で作成してみましょう!"
"設定されていないようです。`/ignore create` で作成してみましょう!"
) {
authorOf(user)
errorColor()
Expand All @@ -105,8 +122,10 @@ class IgnoreCommand : Extension() {
page {
authorOf(user)

description = chunkedIgnores.joinToString("\n") {
"${it.text}」<@${it.userId}>"
title = ":information_source: Ignores"

description = chunkedIgnores.joinToString("\n") { (_, userId, type, text) ->
"${type.emoji} ${type.displayName} | 「$text」 | <@${userId}>"
}

successColor()
Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/com/jaoafa/vcspeaker/stores/IgnoreStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json

@Serializable
enum class IgnoreType(
val displayName: String,
val emoji: String
) {
Exact("完全一致", ":asterisk:"),
Contains("部分一致", ":record_button:")
}

@Serializable
data class IgnoreData(
val guildId: Snowflake,
val userId: Snowflake,
val type: IgnoreType,
val text: String
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jaoafa.vcspeaker.voicetext

import com.jaoafa.vcspeaker.stores.IgnoreStore
import com.jaoafa.vcspeaker.stores.IgnoreType
import com.jaoafa.vcspeaker.tools.Emoji.replaceEmojiToName
import com.jaoafa.vcspeaker.voicetext.api.Emotion
import com.jaoafa.vcspeaker.voicetext.api.Speaker
Expand Down Expand Up @@ -57,6 +58,9 @@ object TextProcessor {

private fun shouldIgnore(text: String, guildId: Snowflake) =
IgnoreStore.filter(guildId).any {
text.contains(it.text)
when (it.type) {
IgnoreType.Exact -> text == it.text
IgnoreType.Contains -> text.contains(it.text)
}
}
}

0 comments on commit adb83e4

Please sign in to comment.