Skip to content

Commit

Permalink
コードのクリーンアップ
Browse files Browse the repository at this point in the history
  • Loading branch information
kosugikun committed Jul 9, 2023
1 parent fd86636 commit 8d96051
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/cosgy/textToSpeak/Listener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Listener(private val bot: Bot) : ListenerAdapter() {
val botMember = event.guild.selfMember
val settings = bot.settingsManager.getSettings(event.guild)
if (event.channelLeft != null) {
if (settings!!.isJoinAndLeaveRead() && Objects.requireNonNull(event.guild.selfMember.voiceState)?.channel === event.channelLeft && event.channelLeft!!.members.size > 1) {
if (settings.isJoinAndLeaveRead() && Objects.requireNonNull(event.guild.selfMember.voiceState)?.channel === event.channelLeft && event.channelLeft!!.members.size > 1) {
val file: String? = try {
bot.voiceCreation.createVoice(
event.guild,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/cosgy/textToSpeak/audio/PlayerManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PlayerManager(val bot: Bot) : DefaultAudioPlayerManager() {
val handler: AudioHandler?
if (guild.audioManager.sendingHandler == null) {
val player = createPlayer()
player.volume = bot.settingsManager.getSettings(guild)!!.volume
player.volume = bot.settingsManager.getSettings(guild).volume
handler = AudioHandler(guild, player)
player.addListener(handler)
guild.audioManager.sendingHandler = handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GuildSettings(private val bot: Bot) : AdminCommand() {
}
val settings = bot.settingsManager.getSettings(event.guild!!)
var text = "null"
if (settings!!.getTextChannel(event.guild) != null) {
if (settings.getTextChannel(event.guild) != null) {
text = settings.getTextChannel(event.guild)!!.name
}
val builder = EmbedBuilder()
Expand All @@ -59,7 +59,7 @@ class GuildSettings(private val bot: Bot) : AdminCommand() {
override fun execute(event: CommandEvent) {
val settings = bot.settingsManager.getSettings(event.guild)
var text = "null"
if (settings!!.getTextChannel(event.guild) != null) {
if (settings.getTextChannel(event.guild) != null) {
text = settings.getTextChannel(event.guild)!!.name
}
val builder = EmbedBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class JLReadCmd(private val bot: Bot) : AdminCommand() {
return
}
val settings = bot.settingsManager.getSettings(event.guild!!)
if (settings!!.isJoinAndLeaveRead()) {
if (settings.isJoinAndLeaveRead()) {
settings.setJoinAndLeaveRead(false)
event.reply("ボイスチャンネルにユーザーが参加、退出した際の読み上げを無効にしました。").queue()
} else {
Expand All @@ -47,7 +47,7 @@ class JLReadCmd(private val bot: Bot) : AdminCommand() {

override fun execute(event: CommandEvent) {
val settings = bot.settingsManager.getSettings(event.guild)
if (settings!!.isJoinAndLeaveRead()) {
if (settings.isJoinAndLeaveRead()) {
settings.setJoinAndLeaveRead(false)
event.reply("ボイスチャンネルにユーザーが参加、退出した際の読み上げを無効にしました。")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SetReadNameCmd(private val bot: Bot) : AdminCommand() {
return
}
val settings = bot.settingsManager.getSettings(event.guild!!)
if (settings!!.isReadName()) {
if (settings.isReadName()) {
settings.setReadName(false)
event.reply("ユーザー名の読み上げを無効にしました。").queue()
} else {
Expand All @@ -47,7 +47,7 @@ class SetReadNameCmd(private val bot: Bot) : AdminCommand() {

override fun execute(event: CommandEvent) {
val settings = bot.settingsManager.getSettings(event.guild)
if (settings!!.isReadName()) {
if (settings.isReadName()) {
settings.setReadName(false)
event.reply("ユーザー名の読み上げを無効にしました。")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class AddWordCmd(private val bot: Bot) : SlashCommand() {

companion object {
private val SUCCESS_COLOR = Color(0, 163, 129)

//private val ERROR_COLOR = Color.RED
//private const val INVALID_ARGS_MESSAGE = "コマンドが無効です。単語と読み方の2つを入力して実行して下さい。"
//private const val USAGE_MESSAGE = "使用方法: /addword <単語> <読み方>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class AboutCommand(private val color: Color, private val description: String, va
"ステータス", """${jda.guilds.size} サーバー
|1シャード""".trimMargin(), true
)
builder.addField("ユーザー", """${jda.users.size} ユニーク
builder.addField(
"ユーザー", """${jda.users.size} ユニーク
|${jda.guilds.stream().mapToInt { g: Guild -> g.members.size }.sum()} 合計""".trimMargin(), true
)
builder.addField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MessageListener(private val bot: Bot) : ListenerAdapter() {
if (isBot) return
val guild = event.guild
val textChannel = event.guildChannel.asTextChannel()
var settingText = bot.settingsManager.getSettings(event.guild)!!.getTextChannel(event.guild)
var settingText = bot.settingsManager.getSettings(event.guild).getTextChannel(event.guild)
if (!guild.audioManager.isConnected) {
return
}
Expand All @@ -64,7 +64,7 @@ class MessageListener(private val bot: Bot) : ListenerAdapter() {
// URLを置き換え
msg = msg.replace("(http://|https://)[\\w.\\-/:#?=&;%~+]+".toRegex(), "ゆーあーるえる")
if (textChannel === settingText) {
if (bot.settingsManager.getSettings(guild)!!.isReadName()) {
if (bot.settingsManager.getSettings(guild).isReadName()) {
msg = author.name + " " + msg
}
val vc = bot.voiceCreation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class UserSettingsManager {
}

fun getSettings(userId: Long): UserSettings {
return settings.computeIfAbsent(userId) { _ : Long -> createDefaultSettings(userId) }
return settings.computeIfAbsent(userId) { _: Long -> createDefaultSettings(userId) }
}

private fun createDefaultSettings(userId: Long): UserSettings {
Expand Down

0 comments on commit 8d96051

Please sign in to comment.