Skip to content

Commit

Permalink
ユーザー設定の保存処理の不具合を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
kosugikun committed Apr 3, 2023
1 parent 40a8606 commit 3e65672
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 80 deletions.
32 changes: 16 additions & 16 deletions src/main/java/dev/cosgy/textToSpeak/BotConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ 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) {
0
}
if (ownerId <= 0) {
prompt.alert(Prompt.Level.ERROR, CONTEXT, """
無効なユーザーIDです!終了します。
無効なユーザーIDです!終了します。
設定ファイルの場所: ${path!!.toAbsolutePath()}
""".trimIndent())
設定ファイルの場所: ${path!!.toAbsolutePath()}
""".trimIndent())
exitProcess(0)
} else {
write = true
Expand All @@ -131,26 +131,26 @@ 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)
}

// if we get through the whole config, it's good to go
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())
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/dev/cosgy/textToSpeak/audio/VoiceCreation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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 に設定しました。")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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 に設定しました。")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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("有効な声データを選択して下さい。")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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) {
Expand All @@ -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 + "に設定しました。")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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 + "に設定しました。")
}
}
20 changes: 10 additions & 10 deletions src/main/java/dev/cosgy/textToSpeak/commands/general/SettingsCmd.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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())
}
}
2 changes: 1 addition & 1 deletion src/main/java/dev/cosgy/textToSpeak/entities/Prompt.kt
Original file line number Diff line number Diff line change
@@ -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. /
Expand Down
65 changes: 40 additions & 25 deletions src/main/java/dev/cosgy/textToSpeak/settings/UserSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
var voiceQualityFmSetting: Float
get() = voiceQualityFm
set(value) {
voiceQualityFm = value
manager.saveSetting(userId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/cosgy/textToSpeak/utils/OtherUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3e65672

Please sign in to comment.