mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-08 05:11:12 +00:00
some fix on Manager functions.
This commit is contained in:
@@ -8,7 +8,6 @@ import net.dv8tion.jda.api.entities.Activity
|
||||
import net.dv8tion.jda.api.entities.Guild
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel
|
||||
import net.dv8tion.jda.api.events.guild.GuildJoinEvent
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter
|
||||
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder
|
||||
@@ -17,7 +16,6 @@ import space.mori.chzzk_bot.common.utils.IData
|
||||
import space.mori.chzzk_bot.common.utils.IStreamInfo
|
||||
import space.mori.chzzk_bot.chatbot.discord.commands.*
|
||||
import space.mori.chzzk_bot.common.models.User
|
||||
import space.mori.chzzk_bot.common.services.ManagerService
|
||||
import java.time.Instant
|
||||
|
||||
val dotenv = dotenv {
|
||||
@@ -62,9 +60,6 @@ class Discord: ListenerAdapter() {
|
||||
|
||||
private val commands = listOf(
|
||||
PingCommand,
|
||||
AddManagerCommand,
|
||||
ListManagerCommand,
|
||||
RemoveManagerCommand,
|
||||
)
|
||||
|
||||
override fun onSlashCommandInteraction(event: SlashCommandInteractionEvent) {
|
||||
@@ -74,10 +69,6 @@ class Discord: ListenerAdapter() {
|
||||
handler?.run(event, bot)
|
||||
}
|
||||
|
||||
override fun onGuildMemberRemove(event: GuildMemberRemoveEvent) {
|
||||
event.member?.let { ManagerService.deleteManager(event.guild.idLong, it.idLong) }
|
||||
}
|
||||
|
||||
override fun onGuildJoin(event: GuildJoinEvent) {
|
||||
commandUpdate(event.guild)
|
||||
}
|
||||
|
@@ -1,47 +0,0 @@
|
||||
package space.mori.chzzk_bot.chatbot.discord.commands
|
||||
|
||||
import net.dv8tion.jda.api.JDA
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
|
||||
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.OptionData
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.chatbot.discord.CommandInterface
|
||||
import space.mori.chzzk_bot.common.services.ManagerService
|
||||
import space.mori.chzzk_bot.common.services.UserService
|
||||
|
||||
object AddManagerCommand : CommandInterface {
|
||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||
override val name: String = "addmanager"
|
||||
override val command = Commands.slash(name, "매니저를 추가합니다.")
|
||||
.addOptions(OptionData(OptionType.USER, "user", "추가할 유저를 선택하세요.", true))
|
||||
|
||||
override fun run(event: SlashCommandInteractionEvent, bot: JDA) {
|
||||
val manager = event.getOption("user")?.asUser
|
||||
|
||||
if(manager == null) {
|
||||
event.hook.sendMessage("유저는 필수사항입니다.").queue()
|
||||
return
|
||||
}
|
||||
if(manager.idLong == event.user.idLong) {
|
||||
event.hook.sendMessage("자신은 매니저로 설정할 수 없습니다.").queue()
|
||||
return
|
||||
}
|
||||
|
||||
val user = UserService.getUser(event.user.idLong)
|
||||
if(user == null) {
|
||||
event.hook.sendMessage("치지직 계정을 찾을 수 없습니다.").queue()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
ManagerService.saveManager(user, manager.idLong, manager.effectiveName)
|
||||
if(user.liveAlertGuild == null)
|
||||
UserService.updateLiveAlert(user, event.guild!!.idLong, event.channelIdLong, "")
|
||||
event.hook.sendMessage("등록이 완료되었습니다. ${manager.effectiveName}").queue()
|
||||
} catch (e: Exception) {
|
||||
event.hook.sendMessage("에러가 발생했습니다.").queue()
|
||||
logger.debug(e.stackTraceToString())
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
package space.mori.chzzk_bot.chatbot.discord.commands
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder
|
||||
import net.dv8tion.jda.api.JDA
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
|
||||
import net.dv8tion.jda.api.interactions.commands.build.Commands
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.chatbot.discord.CommandInterface
|
||||
import space.mori.chzzk_bot.common.services.ManagerService
|
||||
import space.mori.chzzk_bot.common.services.UserService
|
||||
|
||||
object ListManagerCommand : CommandInterface {
|
||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||
override val name: String = "listmanager"
|
||||
override val command = Commands.slash(name, "매니저 목록을 확인합니다.")
|
||||
|
||||
override fun run(event: SlashCommandInteractionEvent, bot: JDA) {
|
||||
try {
|
||||
val managers = event.guild?.idLong?.let { ManagerService.getAllUsers(it) }
|
||||
|
||||
if(managers == null) {
|
||||
event.channel.sendMessage("여기에서는 사용할 수 없습니다.")
|
||||
return
|
||||
}
|
||||
|
||||
val user = UserService.getUserWithGuildId(event.guild!!.idLong)
|
||||
|
||||
val embed = EmbedBuilder()
|
||||
embed.setTitle("${user!!.username} 매니저 목록")
|
||||
embed.setDescription("매니저 목록입니다.")
|
||||
|
||||
var idx = 1
|
||||
|
||||
managers.forEach {
|
||||
embed.addField("${idx++}", it.lastUserName ?: it.managerId.toString(), true)
|
||||
}
|
||||
|
||||
event.channel.sendMessageEmbeds(embed.build()).queue()
|
||||
} catch (e: Exception) {
|
||||
event.hook.sendMessage("에러가 발생했습니다.").queue()
|
||||
logger.debug(e.stackTraceToString())
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
package space.mori.chzzk_bot.chatbot.discord.commands
|
||||
|
||||
import net.dv8tion.jda.api.JDA
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
|
||||
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.OptionData
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.chatbot.discord.CommandInterface
|
||||
import space.mori.chzzk_bot.common.services.ManagerService
|
||||
import space.mori.chzzk_bot.common.services.UserService
|
||||
|
||||
object RemoveManagerCommand : CommandInterface {
|
||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||
override val name: String = "removemanager"
|
||||
override val command = Commands.slash(name, "매니저를 삭제합니다.")
|
||||
.addOptions(OptionData(OptionType.USER, "user", "삭제할 유저를 선택하세요.", true))
|
||||
|
||||
override fun run(event: SlashCommandInteractionEvent, bot: JDA) {
|
||||
val manager = event.getOption("user")?.asUser
|
||||
|
||||
if(manager == null) {
|
||||
event.hook.sendMessage("유저는 필수사항입니다.").queue()
|
||||
return
|
||||
}
|
||||
if(manager.idLong == event.user.idLong) {
|
||||
event.hook.sendMessage("자신은 매니저로 설정할 수 없습니다.").queue()
|
||||
return
|
||||
}
|
||||
|
||||
val user = UserService.getUser(event.user.idLong)
|
||||
if(user == null) {
|
||||
event.hook.sendMessage("치지직 계정을 찾을 수 없습니다.").queue()
|
||||
return
|
||||
}
|
||||
|
||||
if(ManagerService.getUser(user.liveAlertGuild ?: 0L, manager.idLong) == null) {
|
||||
event.hook.sendMessage("${manager.name}은 매니저가 아닙니다.")
|
||||
}
|
||||
|
||||
try {
|
||||
ManagerService.deleteManager(user, manager.idLong)
|
||||
event.hook.sendMessage("삭제가 완료되었습니다. ${manager.effectiveName}").queue()
|
||||
} catch (e: Exception) {
|
||||
event.hook.sendMessage("에러가 발생했습니다.").queue()
|
||||
logger.debug(e.stackTraceToString())
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user