mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-09 07:18:22 +00:00
commit
da13e8b834
@ -5,6 +5,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
|
|||||||
import net.dv8tion.jda.api.interactions.commands.OptionType
|
import net.dv8tion.jda.api.interactions.commands.OptionType
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.Commands
|
import net.dv8tion.jda.api.interactions.commands.build.Commands
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import space.mori.chzzk_bot.chatbot.chzzk.ChzzkHandler
|
import space.mori.chzzk_bot.chatbot.chzzk.ChzzkHandler
|
||||||
import space.mori.chzzk_bot.chatbot.chzzk.Connector
|
import space.mori.chzzk_bot.chatbot.chzzk.Connector
|
||||||
@ -39,8 +40,15 @@ object AddCommand : CommandInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
user = manager.user
|
transaction {
|
||||||
ManagerService.updateManager(user, event.user.idLong, event.user.effectiveName)
|
user = manager.user
|
||||||
|
}
|
||||||
|
user?.let { ManagerService.updateManager(it, event.user.idLong, event.user.effectiveName) }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user == null) {
|
||||||
|
event.hook.sendMessage("에러가 발생했습니다.").queue()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val commands = CommandService.getCommands(user!!)
|
val commands = CommandService.getCommands(user!!)
|
||||||
@ -49,10 +57,10 @@ object AddCommand : CommandInterface {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val chzzkChannel = Connector.getChannel(user.token)
|
val chzzkChannel = Connector.getChannel(user!!.token)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CommandService.saveCommand(user, label, content, failContent ?: "")
|
CommandService.saveCommand(user!!, label, content, failContent ?: "")
|
||||||
try {
|
try {
|
||||||
ChzzkHandler.reloadCommand(chzzkChannel!!)
|
ChzzkHandler.reloadCommand(chzzkChannel!!)
|
||||||
} catch (_: Exception) {}
|
} catch (_: Exception) {}
|
||||||
|
@ -5,6 +5,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
|
|||||||
import net.dv8tion.jda.api.interactions.commands.OptionType
|
import net.dv8tion.jda.api.interactions.commands.OptionType
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.Commands
|
import net.dv8tion.jda.api.interactions.commands.build.Commands
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import space.mori.chzzk_bot.chatbot.chzzk.ChzzkHandler
|
import space.mori.chzzk_bot.chatbot.chzzk.ChzzkHandler
|
||||||
import space.mori.chzzk_bot.chatbot.chzzk.Connector
|
import space.mori.chzzk_bot.chatbot.chzzk.Connector
|
||||||
@ -31,14 +32,21 @@ object AlertCommand : CommandInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
user = manager.user
|
transaction {
|
||||||
ManagerService.updateManager(user, event.user.idLong, event.user.effectiveName)
|
user = manager.user
|
||||||
|
}
|
||||||
|
user?.let { ManagerService.updateManager(it, event.user.idLong, event.user.effectiveName) }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user == null) {
|
||||||
|
event.hook.sendMessage("에러가 발생했습니다.").queue()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val chzzkChannel = Connector.getChannel(user!!.token)
|
val chzzkChannel = Connector.getChannel(user!!.token)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val newUser = UserService.updateLiveAlert(user.id.value, channel?.guild?.idLong ?: 0L, channel?.idLong ?: 0L, content ?: "")
|
val newUser = UserService.updateLiveAlert(user!!.id.value, channel?.guild?.idLong ?: 0L, channel?.idLong ?: 0L, content ?: "")
|
||||||
try {
|
try {
|
||||||
ChzzkHandler.reloadUser(chzzkChannel!!, newUser)
|
ChzzkHandler.reloadUser(chzzkChannel!!, newUser)
|
||||||
} catch (_: Exception) {}
|
} catch (_: Exception) {}
|
||||||
|
@ -5,6 +5,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
|
|||||||
import net.dv8tion.jda.api.interactions.commands.OptionType
|
import net.dv8tion.jda.api.interactions.commands.OptionType
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.Commands
|
import net.dv8tion.jda.api.interactions.commands.build.Commands
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import space.mori.chzzk_bot.chatbot.chzzk.ChzzkHandler
|
import space.mori.chzzk_bot.chatbot.chzzk.ChzzkHandler
|
||||||
import space.mori.chzzk_bot.chatbot.chzzk.Connector
|
import space.mori.chzzk_bot.chatbot.chzzk.Connector
|
||||||
@ -35,14 +36,21 @@ object RemoveCommand : CommandInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
user = manager.user
|
transaction {
|
||||||
ManagerService.updateManager(user, event.user.idLong, event.user.effectiveName)
|
user = manager.user
|
||||||
|
}
|
||||||
|
user?.let { ManagerService.updateManager(it, event.user.idLong, event.user.effectiveName) }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user == null) {
|
||||||
|
event.hook.sendMessage("에러가 발생했습니다.").queue()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val chzzkChannel = Connector.getChannel(user!!.token)
|
val chzzkChannel = Connector.getChannel(user!!.token)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CommandService.removeCommand(user, label)
|
CommandService.removeCommand(user!!, label)
|
||||||
try {
|
try {
|
||||||
ChzzkHandler.reloadCommand(chzzkChannel!!)
|
ChzzkHandler.reloadCommand(chzzkChannel!!)
|
||||||
} catch (_: Exception) {}
|
} catch (_: Exception) {}
|
||||||
|
@ -5,6 +5,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
|
|||||||
import net.dv8tion.jda.api.interactions.commands.OptionType
|
import net.dv8tion.jda.api.interactions.commands.OptionType
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.Commands
|
import net.dv8tion.jda.api.interactions.commands.build.Commands
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import space.mori.chzzk_bot.chatbot.chzzk.ChzzkHandler
|
import space.mori.chzzk_bot.chatbot.chzzk.ChzzkHandler
|
||||||
import space.mori.chzzk_bot.chatbot.chzzk.Connector
|
import space.mori.chzzk_bot.chatbot.chzzk.Connector
|
||||||
@ -39,14 +40,21 @@ object UpdateCommand : CommandInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
user = manager.user
|
transaction {
|
||||||
ManagerService.updateManager(user, event.user.idLong, event.user.effectiveName)
|
user = manager.user
|
||||||
|
}
|
||||||
|
user?.let { ManagerService.updateManager(it, event.user.idLong, event.user.effectiveName) }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user == null) {
|
||||||
|
event.hook.sendMessage("에러가 발생했습니다.").queue()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val chzzkChannel = Connector.getChannel(user!!.token)
|
val chzzkChannel = Connector.getChannel(user!!.token)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CommandService.updateCommand(user, label, content, failContent ?: "")
|
CommandService.updateCommand(user!!, label, content, failContent ?: "")
|
||||||
chzzkChannel?.let { ChzzkHandler.reloadCommand(it) }
|
chzzkChannel?.let { ChzzkHandler.reloadCommand(it) }
|
||||||
event.hook.sendMessage("등록이 완료되었습니다. $label = $content").queue()
|
event.hook.sendMessage("등록이 완료되었습니다. $label = $content").queue()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package space.mori.chzzk_bot.common.services
|
package space.mori.chzzk_bot.common.services
|
||||||
|
|
||||||
|
import org.jetbrains.exposed.dao.load
|
||||||
|
import org.jetbrains.exposed.dao.with
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
import org.jetbrains.exposed.sql.and
|
import org.jetbrains.exposed.sql.and
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
@ -23,14 +25,16 @@ object ManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateManager(user: User, discordId: Long, name: String): Manager {
|
fun updateManager(user: User, discordId: Long, name: String): Manager {
|
||||||
if (user.liveAlertGuild == null)
|
return transaction {
|
||||||
throw RuntimeException("${user.username} has no liveAlertGuild")
|
if (user.liveAlertGuild == null)
|
||||||
|
throw RuntimeException("${user.username} has no liveAlertGuild")
|
||||||
|
|
||||||
val manager = getUser(user.liveAlertGuild!!, discordId) ?: throw RuntimeException("$name isn't manager.")
|
val manager = getUser(user.liveAlertGuild!!, discordId) ?: throw RuntimeException("$name isn't manager.")
|
||||||
|
|
||||||
manager.lastUserName = name
|
manager.lastUserName = name
|
||||||
|
|
||||||
return manager
|
manager
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUser(guildId: Long, discordId: Long): Manager? {
|
fun getUser(guildId: Long, discordId: Long): Manager? {
|
||||||
@ -38,19 +42,19 @@ object ManagerService {
|
|||||||
val manager = Manager.find(
|
val manager = Manager.find(
|
||||||
(Managers.discordGuildId eq guildId) and (Managers.managerId eq discordId),
|
(Managers.discordGuildId eq guildId) and (Managers.managerId eq discordId),
|
||||||
)
|
)
|
||||||
|
.with(Manager::user)
|
||||||
val result = manager.firstOrNull()
|
.firstOrNull()
|
||||||
|
manager
|
||||||
result?.eagerLoad()
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllUsers(guildId: Long): List<Manager> {
|
fun getAllUsers(guildId: Long): List<Manager> {
|
||||||
return transaction {
|
return transaction {
|
||||||
val result = Manager.find(Managers.discordGuildId eq guildId).toList()
|
val result = Manager.find(Managers.discordGuildId eq guildId)
|
||||||
|
.with(Manager::user)
|
||||||
|
.toList()
|
||||||
|
|
||||||
result.forEach { it.eagerLoad() }
|
result.forEach { it.load(Manager::user) }
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
@ -72,8 +76,4 @@ object ManagerService {
|
|||||||
managerRow
|
managerRow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Manager.eagerLoad() {
|
|
||||||
this.user
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
group = space.mori
|
group = space.mori
|
||||||
version = 1.1.1
|
version = 1.1.2
|
||||||
|
|
||||||
org.gradle.jvmargs=-Dfile.encoding=UTF-8
|
org.gradle.jvmargs=-Dfile.encoding=UTF-8
|
||||||
org.gradle.console=plain
|
org.gradle.console=plain
|
||||||
|
Loading…
x
Reference in New Issue
Block a user