diff --git a/src/main/java/dev/cosgy/textToSpeak/BotConfig.kt b/src/main/java/dev/cosgy/textToSpeak/BotConfig.kt index 5bc22c6..f3bc5b1 100644 --- a/src/main/java/dev/cosgy/textToSpeak/BotConfig.kt +++ b/src/main/java/dev/cosgy/textToSpeak/BotConfig.kt @@ -107,10 +107,10 @@ class BotConfig(private val prompt: Prompt) { if (ownerId <= 0) { ownerId = try { prompt.prompt(""" - 所有者のユーザーIDが設定されていない、または有効なIDではありません。 - BOTの所有者のユーザーIDを入力してください。 - 所有者のユーザーID: - """.trimIndent())!!.toLong() + 所有者のユーザーIDが設定されていない、または有効なIDではありません。 + BOTの所有者のユーザーIDを入力してください。 + 所有者のユーザーID: + """.trimIndent())!!.toLong() } catch (ex: NumberFormatException) { 0 } catch (ex: NullPointerException) { @@ -118,10 +118,10 @@ class BotConfig(private val prompt: Prompt) { } if (ownerId <= 0) { prompt.alert(Prompt.Level.ERROR, CONTEXT, """ - 無効なユーザーIDです!終了します。 + 無効なユーザーIDです!終了します。 - 設定ファイルの場所: ${path!!.toAbsolutePath()} - """.trimIndent()) + 設定ファイルの場所: ${path!!.toAbsolutePath()} + """.trimIndent()) exitProcess(0) } else { write = true @@ -131,9 +131,9 @@ class BotConfig(private val prompt: Prompt) { val original = OtherUtil.loadResource(this, "/reference.conf") val mod: String = original?.substring(original.indexOf(START_TOKEN) + START_TOKEN.length, original.indexOf(END_TOKEN))?.replace("BOT_TOKEN_HERE", token!!)?.replace("Botトークンをここに貼り付け", token!!)?.replace("0 // OWNER ID", ownerId.toString())?.replace("所有者IDをここに貼り付け", ownerId.toString())?.trim { it <= ' ' } ?: """ - token = $token - owner = $ownerId - """.trimIndent() + token = $token + owner = $ownerId + """.trimIndent() FileUtils.writeStringToFile(path!!.toFile(), mod, StandardCharsets.UTF_8) } @@ -141,16 +141,16 @@ class BotConfig(private val prompt: Prompt) { isValid = true } catch (ex: ConfigException) { prompt.alert(Prompt.Level.ERROR, CONTEXT, """ - $ex: ${ex.message} + $ex: ${ex.message} - 設定ファイルの場所: ${path!!.toAbsolutePath()} - """.trimIndent()) + 設定ファイルの場所: ${path!!.toAbsolutePath()} + """.trimIndent()) } catch (ex: IOException) { prompt.alert(Prompt.Level.ERROR, CONTEXT, """ - $ex: ${ex.message} + $ex: ${ex.message} - 設定ファイルの場所: ${path!!.toAbsolutePath()} - """.trimIndent()) + 設定ファイルの場所: ${path!!.toAbsolutePath()} + """.trimIndent()) } } diff --git a/src/main/java/dev/cosgy/textToSpeak/audio/VoiceCreation.kt b/src/main/java/dev/cosgy/textToSpeak/audio/VoiceCreation.kt index 7dc4f93..ce53e62 100644 --- a/src/main/java/dev/cosgy/textToSpeak/audio/VoiceCreation.kt +++ b/src/main/java/dev/cosgy/textToSpeak/audio/VoiceCreation.kt @@ -129,17 +129,17 @@ class VoiceCreation( // 各種設定の値を保持するためのフィール command.add("-x") command.add(dictionary) command.add("-m") - command.add(getVoiceFilePath(settings!!.voice)) + command.add(getVoiceFilePath(settings!!.voiceSetting)) command.add("-ow") command.add(fileName) command.add("-r") - command.add(settings.speed.toString()) + command.add(settings.speedSetting.toString()) command.add("-jf") - command.add(settings.intonation.toString()) + command.add(settings.intonationSetting.toString()) command.add("-a") - command.add(settings.voiceQualityA.toString()) + command.add(settings.voiceQualityASetting.toString()) command.add("-fm") - command.add(settings.voiceQualityFm.toString()) + command.add(settings.voiceQualityFmSetting.toString()) command.add(tmpFilePath) return command.toTypedArray() } diff --git a/src/main/java/dev/cosgy/textToSpeak/commands/general/SetIntonationCmd.kt b/src/main/java/dev/cosgy/textToSpeak/commands/general/SetIntonationCmd.kt index 2fe5e04..ec3f9e2 100644 --- a/src/main/java/dev/cosgy/textToSpeak/commands/general/SetIntonationCmd.kt +++ b/src/main/java/dev/cosgy/textToSpeak/commands/general/SetIntonationCmd.kt @@ -42,7 +42,7 @@ class SetIntonationCmd(private val bot: Bot) : SlashCommand() { } val settings = bot.userSettingsManager.getSettings(event.user.idLong) - settings.setIntonation(bd.toFloat()) + settings.intonationSetting = bd.toFloat() event.reply("F0系列内変動の重みを$bd に設定しました。").queue() } @@ -64,7 +64,7 @@ class SetIntonationCmd(private val bot: Bot) : SlashCommand() { } val settings = bot.userSettingsManager.getSettings(event.author.idLong) - settings.setIntonation(bd.toFloat()) + settings.intonationSetting = bd.toFloat() event.reply("F0系列内変動の重みを$bd に設定しました。") } } diff --git a/src/main/java/dev/cosgy/textToSpeak/commands/general/SetSpeedCmd.kt b/src/main/java/dev/cosgy/textToSpeak/commands/general/SetSpeedCmd.kt index b98b70d..42e2ef1 100644 --- a/src/main/java/dev/cosgy/textToSpeak/commands/general/SetSpeedCmd.kt +++ b/src/main/java/dev/cosgy/textToSpeak/commands/general/SetSpeedCmd.kt @@ -48,7 +48,7 @@ class SetSpeedCmd(private val bot: Bot) : SlashCommand() { return } val settings = bot.userSettingsManager.getSettings(event.user.idLong) - settings.setSpeed(bd.toFloat()) + settings.speedSetting = bd.toFloat() event.reply("速度を $bd に設定しました。").queue() } @@ -73,7 +73,7 @@ class SetSpeedCmd(private val bot: Bot) : SlashCommand() { return } val settings = bot.userSettingsManager.getSettings(event.author.idLong) - settings.setSpeed(bd.toFloat()) + settings.speedSetting = bd.toFloat() event.reply("速度を $bd に設定しました。") } diff --git a/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceCmd.kt b/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceCmd.kt index e17b8bb..9566752 100644 --- a/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceCmd.kt +++ b/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceCmd.kt @@ -51,11 +51,11 @@ class SetVoiceCmd(private var bot: Bot) : SlashCommand() { event.replyEmbeds(builder.build()).queue() return } - val viceName = event.getOption("name")!!.asString - if (isValidVoice(viceName)) { + val voiceName = event.getOption("name")!!.asString + if (isValidVoice(voiceName)) { val settings = bot.userSettingsManager.getSettings(event.user.idLong) - settings.setVoice(viceName) - event.reply("声データを`$viceName`に設定しました。").queue() + settings.voiceSetting = voiceName + event.reply("声データを`$voiceName`に設定しました。").queue() } else { event.reply("有効な声データを選択して下さい。").queue() } @@ -74,7 +74,7 @@ class SetVoiceCmd(private var bot: Bot) : SlashCommand() { val args = event.args if (voices.contains(args)) { val settings = bot.userSettingsManager.getSettings(event.author.idLong) - settings.setVoice(args) + settings.voiceSetting = args event.reply("声データを`$args`に設定しました。") } else { event.reply("有効な声データを選択して下さい。") diff --git a/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceQualityA.kt b/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceQualityA.kt index fc1e128..8b77766 100644 --- a/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceQualityA.kt +++ b/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceQualityA.kt @@ -58,7 +58,7 @@ class SetVoiceQualityA(private var bot: Bot) : SlashCommand() { return } val settings = bot.userSettingsManager.getSettings(event.user.idLong) - settings.setVoiceQualityA(bd!!.toFloat()) + settings.voiceQualityASetting = bd!!.toFloat() event.reply("オールパス値を" + bd + "に設定しました。").queue() } @@ -67,7 +67,6 @@ class SetVoiceQualityA(private var bot: Bot) : SlashCommand() { var result: Boolean var bd: BigDecimal? = null try { - //value = Float.parseFloat(args); bd = BigDecimal(args) result = true } catch (e: NumberFormatException) { @@ -80,13 +79,12 @@ class SetVoiceQualityA(private var bot: Bot) : SlashCommand() { val min = BigDecimal("0.0") val max = BigDecimal("1.0") - //if(!(0.1f <= value && value <= 1.0f)){ if (!(min < bd && max > bd)) { event.reply("有効な数値を設定して下さい。0.1~1.0") return } val settings = bot.userSettingsManager.getSettings(event.author.idLong) - settings.setVoiceQualityA(bd!!.toFloat()) + settings.voiceQualityASetting = bd!!.toFloat() event.reply("オールパス値を" + bd + "に設定しました。") } } \ No newline at end of file diff --git a/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceQualityFm.kt b/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceQualityFm.kt index becd218..ea56495 100644 --- a/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceQualityFm.kt +++ b/src/main/java/dev/cosgy/textToSpeak/commands/general/SetVoiceQualityFm.kt @@ -59,7 +59,7 @@ class SetVoiceQualityFm(private var bot: Bot) : SlashCommand() { return } val settings = bot.userSettingsManager.getSettings(event.user.idLong) - bd?.let { settings.setVoiceQualityFm(it.toFloat()) } + bd?.let { settings.voiceQualityFmSetting = it.toFloat() } event.reply("追加ハーフトーンを" + bd + "に設定しました。").queue() } @@ -95,7 +95,7 @@ class SetVoiceQualityFm(private var bot: Bot) : SlashCommand() { return } val settings = bot.userSettingsManager.getSettings(event.author.idLong) - bd?.let { settings.setVoiceQualityFm(it.toFloat()) } + bd?.let { settings.voiceQualityFmSetting = it.toFloat() } event.reply("追加ハーフトーンを" + bd + "に設定しました。") } } \ No newline at end of file diff --git a/src/main/java/dev/cosgy/textToSpeak/commands/general/SettingsCmd.kt b/src/main/java/dev/cosgy/textToSpeak/commands/general/SettingsCmd.kt index af05290..536b9df 100644 --- a/src/main/java/dev/cosgy/textToSpeak/commands/general/SettingsCmd.kt +++ b/src/main/java/dev/cosgy/textToSpeak/commands/general/SettingsCmd.kt @@ -35,11 +35,11 @@ class SettingsCmd(private var bot: Bot) : SlashCommand() { val builder = EmbedBuilder() .setColor(Color.orange) .setTitle(event.user.name + "の設定") - .addField("声:", settings.voice, false) - .addField("読み上げ速度:", settings.speed.toString(), false) - .addField("F0系列内変動の重み:", settings.intonation.toString(), false) - .addField("オールパス値:", settings.voiceQualityA.toString(), false) - .addField("追加ハーフトーン:", settings.voiceQualityFm.toString(), false) + .addField("声:", settings.voiceSetting, false) + .addField("読み上げ速度:", settings.speedSetting.toString(), false) + .addField("F0系列内変動の重み:", settings.intonationSetting.toString(), false) + .addField("オールパス値:", settings.voiceQualityASetting.toString(), false) + .addField("追加ハーフトーン:", settings.voiceQualityFmSetting.toString(), false) event.replyEmbeds(builder.build()).queue() } @@ -48,11 +48,11 @@ class SettingsCmd(private var bot: Bot) : SlashCommand() { val builder = EmbedBuilder() .setColor(Color.orange) .setTitle(event.author.name + "の設定") - .addField("声:", settings.voice, false) - .addField("速度:", settings.speed.toString(), false) - .addField("抑揚:", settings.intonation.toString(), false) - .addField("声質a:", settings.voiceQualityA.toString(), false) - .addField("声質fm:", settings.voiceQualityFm.toString(), false) + .addField("声:", settings.voiceSetting, false) + .addField("速度:", settings.speedSetting.toString(), false) + .addField("抑揚:", settings.intonationSetting.toString(), false) + .addField("声質a:", settings.voiceQualityASetting.toString(), false) + .addField("声質fm:", settings.voiceQualityFmSetting.toString(), false) event.reply(builder.build()) } } \ No newline at end of file diff --git a/src/main/java/dev/cosgy/textToSpeak/entities/Prompt.kt b/src/main/java/dev/cosgy/textToSpeak/entities/Prompt.kt index 3af73d1..ff7c6a8 100644 --- a/src/main/java/dev/cosgy/textToSpeak/entities/Prompt.kt +++ b/src/main/java/dev/cosgy/textToSpeak/entities/Prompt.kt @@ -1,5 +1,5 @@ ////////////////////////////////////////////////////////////////////////////////////////// -// Copyright 2023 Cosgy Dev / +// Copyright 2023 Cosgy Dev / // / // Licensed under the Apache License, Version 2.0 (the "License"); / // you may not use this file except in compliance with the License. / diff --git a/src/main/java/dev/cosgy/textToSpeak/settings/UserSettings.kt b/src/main/java/dev/cosgy/textToSpeak/settings/UserSettings.kt index 7580db4..9626744 100644 --- a/src/main/java/dev/cosgy/textToSpeak/settings/UserSettings.kt +++ b/src/main/java/dev/cosgy/textToSpeak/settings/UserSettings.kt @@ -15,32 +15,47 @@ ////////////////////////////////////////////////////////////////////////////////////////// package dev.cosgy.textToSpeak.settings -class UserSettings(private val manager: UserSettingsManager, // getter - private val userId: Long, var voice: String, var speed: Float, var intonation: Float, var voiceQualityA: Float, var voiceQualityFm: Float) { +class UserSettings( + private val manager: UserSettingsManager, + private val userId: Long, + private var voice: String, + private var speed: Float, + private var intonation: Float, + private var voiceQualityA: Float, + private var voiceQualityFm: Float +) { + var voiceSetting: String + get() = voice + set(value) { + voice = value + manager.saveSetting(userId) + } - fun setVoice(voice: String) { - this.voice = voice - manager.saveSetting(userId) - } + var speedSetting: Float + get() = speed + set(value) { + speed = value + manager.saveSetting(userId) + } - fun setSpeed(speed:Float){ - this.speed = speed - manager.saveSetting(userId) - } + var intonationSetting: Float + get() = intonation + set(value) { + intonation = value + manager.saveSetting(userId) + } - fun setIntonation(intonation: Float){ - this.intonation = intonation - manager.saveSetting(userId) - } + var voiceQualityASetting: Float + get() = voiceQualityA + set(value) { + voiceQualityA = value + manager.saveSetting(userId) + } - fun setVoiceQualityA(voiceQualityA: Float){ - this.voiceQualityA = voiceQualityA - manager.saveSetting(userId) - } - - fun setVoiceQualityFm(voiceQualityFm: Float){ - this.voiceQualityFm = voiceQualityFm - manager.saveSetting(userId) - } - -} \ No newline at end of file + var voiceQualityFmSetting: Float + get() = voiceQualityFm + set(value) { + voiceQualityFm = value + manager.saveSetting(userId) + } +} diff --git a/src/main/java/dev/cosgy/textToSpeak/settings/UserSettingsManager.kt b/src/main/java/dev/cosgy/textToSpeak/settings/UserSettingsManager.kt index 5e0ee0a..1d7526f 100644 --- a/src/main/java/dev/cosgy/textToSpeak/settings/UserSettingsManager.kt +++ b/src/main/java/dev/cosgy/textToSpeak/settings/UserSettingsManager.kt @@ -68,11 +68,11 @@ class UserSettingsManager { try { connection!!.prepareStatement(sql).use { ps -> ps.setLong(1, userId) - ps.setString(2, settings!!.voice) - ps.setFloat(3, settings.speed) - ps.setFloat(4, settings.intonation) - ps.setFloat(5, settings.voiceQualityA) - ps.setFloat(6, settings.voiceQualityFm) + ps.setString(2, settings!!.voiceSetting) + ps.setFloat(3, settings.speedSetting) + ps.setFloat(4, settings.intonationSetting) + ps.setFloat(5, settings.voiceQualityASetting) + ps.setFloat(6, settings.voiceQualityFmSetting) logger.debug(ps.toString()) ps.executeUpdate() } diff --git a/src/main/java/dev/cosgy/textToSpeak/utils/OtherUtil.kt b/src/main/java/dev/cosgy/textToSpeak/utils/OtherUtil.kt index 52e00a8..31db718 100644 --- a/src/main/java/dev/cosgy/textToSpeak/utils/OtherUtil.kt +++ b/src/main/java/dev/cosgy/textToSpeak/utils/OtherUtil.kt @@ -62,7 +62,7 @@ object OtherUtil { */ fun loadResource(clazz: Any, name: String?): String? { return try { - readString(clazz.javaClass.getResourceAsStream(name)) + name?.let { clazz.javaClass.getResourceAsStream(it)?.let { readString(it) } } } catch (ex: Exception) { null } @@ -121,8 +121,8 @@ object OtherUtil { return Activity.playing(game) } - fun makeNonEmpty(str: String?): String { - return if (str == null || str.isEmpty()) "\u200B" else str + private fun makeNonEmpty(str: String?): String { + return if (str.isNullOrEmpty()) "\u200B" else str } fun parseStatus(status: String?): OnlineStatus {