mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 12:51:13 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f2b30c8b00 | ||
|
947e6d4bb3 | ||
|
43b6869100 | ||
|
ba12fd655b | ||
|
b1d69e90ef |
@@ -36,6 +36,11 @@ class MessageHandler(
|
|||||||
val user = UserService.getUser(channel.channelId)
|
val user = UserService.getUser(channel.channelId)
|
||||||
?: throw RuntimeException("User not found. it's bug? ${channel.channelName} - ${channel.channelId}")
|
?: throw RuntimeException("User not found. it's bug? ${channel.channelName} - ${channel.channelId}")
|
||||||
val commands = CommandService.getCommands(user)
|
val commands = CommandService.getCommands(user)
|
||||||
|
val manageCommands = mapOf("!명령어추가" to this::manageAddCommand, "!명령어삭제" to this::manageRemoveCommand, "!명령어수정" to this::manageUpdateCommand)
|
||||||
|
|
||||||
|
manageCommands.forEach { (commandName, command) ->
|
||||||
|
this.commands[commandName] = command
|
||||||
|
}
|
||||||
|
|
||||||
commands.map {
|
commands.map {
|
||||||
this.commands.put(it.command.lowercase()) { msg, user ->
|
this.commands.put(it.command.lowercase()) { msg, user ->
|
||||||
@@ -47,6 +52,64 @@ class MessageHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun manageAddCommand(msg: ChatMessage, user: User) {
|
||||||
|
if (msg.profile?.userRoleCode == "common_user") {
|
||||||
|
listener.sendChat("매니저만 명령어를 추가할 수 있습니다.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val parts = msg.content.split(" ", limit = 3)
|
||||||
|
if (parts.size < 3) {
|
||||||
|
listener.sendChat("명령어 추가 형식은 '!명령어추가 명령어 내용'입니다.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (commands.containsKey(parts[0])) {
|
||||||
|
listener.sendChat("${parts[1]} 명령어는 이미 있는 명령어입니다.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val command = parts[1]
|
||||||
|
val content = parts[2]
|
||||||
|
CommandService.saveCommand(user, command, content, "")
|
||||||
|
listener.sendChat("명령어 '$command' 추가되었습니다.")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun manageUpdateCommand(msg: ChatMessage, user: User) {
|
||||||
|
if (msg.profile?.userRoleCode == "common_user") {
|
||||||
|
listener.sendChat("매니저만 명령어를 추가할 수 있습니다.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val parts = msg.content.split(" ", limit = 3)
|
||||||
|
if (parts.size < 3) {
|
||||||
|
listener.sendChat("명령어 수정 형식은 '!명령어수정 명령어 내용'입니다.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!commands.containsKey(parts[0])) {
|
||||||
|
listener.sendChat("${parts[1]} 명령어는 없는 명령어입니다.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val command = parts[1]
|
||||||
|
val content = parts[2]
|
||||||
|
CommandService.updateCommand(user, command, content, "")
|
||||||
|
listener.sendChat("명령어 '$command' 수정되었습니다.")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun manageRemoveCommand(msg: ChatMessage, user: User) {
|
||||||
|
if (msg.profile?.userRoleCode == "common_user") {
|
||||||
|
listener.sendChat("매니저만 명령어를 삭제할 수 있습니다.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val parts = msg.content.split(" ", limit = 2)
|
||||||
|
if (parts.size < 2) {
|
||||||
|
listener.sendChat("명령어 삭제 형식은 '!명령어삭제 명령어'입니다.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val command = parts[1]
|
||||||
|
CommandService.removeCommand(user, command)
|
||||||
|
listener.sendChat("명령어 '$command' 삭제되었습니다.")
|
||||||
|
}
|
||||||
|
|
||||||
internal fun handle(msg: ChatMessage, user: User) {
|
internal fun handle(msg: ChatMessage, user: User) {
|
||||||
val commandKey = msg.content.split(' ')[0]
|
val commandKey = msg.content.split(' ')[0]
|
||||||
|
|
||||||
@@ -57,16 +120,6 @@ class MessageHandler(
|
|||||||
var result = chat.first
|
var result = chat.first
|
||||||
var isFail = false
|
var isFail = false
|
||||||
|
|
||||||
result = counterPattern.replace(result) {
|
|
||||||
val name = it.groupValues[1]
|
|
||||||
CounterService.updateCounterValue(name, 1, user).toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
result = personalCounterPattern.replace(result) {
|
|
||||||
val name = it.groupValues[1]
|
|
||||||
CounterService.updatePersonalCounterValue(name, msg.userId, 1, user).toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
result = dailyCounterPattern.replace(result) {
|
result = dailyCounterPattern.replace(result) {
|
||||||
val name = it.groupValues[1]
|
val name = it.groupValues[1]
|
||||||
val dailyCounter = CounterService.getDailyCounterValue(name, msg.userId, user)
|
val dailyCounter = CounterService.getDailyCounterValue(name, msg.userId, user)
|
||||||
@@ -103,8 +156,15 @@ class MessageHandler(
|
|||||||
val period = Period.between(pastDate, today)
|
val period = Period.between(pastDate, today)
|
||||||
period.days.toString()
|
period.days.toString()
|
||||||
}
|
}
|
||||||
if(isFail) {
|
|
||||||
return chat.second
|
result = counterPattern.replace(result) {
|
||||||
|
val name = it.groupValues[1]
|
||||||
|
CounterService.updateCounterValue(name, 1, user).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
result = personalCounterPattern.replace(result) {
|
||||||
|
val name = it.groupValues[1]
|
||||||
|
CounterService.updatePersonalCounterValue(name, msg.userId, 1, user).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
result = namePattern.replace(result, userName)
|
result = namePattern.replace(result, userName)
|
||||||
|
@@ -39,8 +39,8 @@ object RegisterCommand: CommandInterface {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
val user = UserService.saveUser(chzzkChannel.channelName, chzzkChannel.channelId, event.user.idLong)
|
val user = UserService.saveUser(chzzkChannel.channelName, chzzkChannel.channelId, event.user.idLong)
|
||||||
ChzzkHandler.addUser(chzzkChannel, user)
|
|
||||||
event.hook.sendMessage("등록이 완료되었습니다. `${chzzkChannel.channelId}` - `${chzzkChannel.channelName}`")
|
event.hook.sendMessage("등록이 완료되었습니다. `${chzzkChannel.channelId}` - `${chzzkChannel.channelName}`")
|
||||||
|
ChzzkHandler.addUser(chzzkChannel, user)
|
||||||
} catch(e: Exception) {
|
} catch(e: Exception) {
|
||||||
event.hook.sendMessage("에러가 발생했습니다.").queue()
|
event.hook.sendMessage("에러가 발생했습니다.").queue()
|
||||||
logger.debug(e.stackTraceToString())
|
logger.debug(e.stackTraceToString())
|
||||||
|
Reference in New Issue
Block a user