mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-09 15:28:21 +00:00
commit
fdd8eeda23
@ -263,13 +263,13 @@ class MessageHandler(
|
|||||||
|
|
||||||
SongConfigService.updateSession(user, session, password)
|
SongConfigService.updateSession(user, session, password)
|
||||||
|
|
||||||
bot.getUserById(user.token)?.let { it ->
|
|
||||||
val channel = it.openPrivateChannel()
|
|
||||||
channel.onSuccess { privateChannel ->
|
|
||||||
privateChannel.sendMessage("여기로 접속해주세요! https://nabot,mori.space/songlist/${session}.\n인증번호는 ||$password|| 입니다.").queue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
bot.retrieveUserById(user.discord).queue { discordUser ->
|
||||||
|
discordUser?.openPrivateChannel()?.queue { channel ->
|
||||||
|
channel.sendMessage("여기로 접속해주세요! https://nabot,mori.space/songlist/${session}.\n인증번호는 ||$password|| 입니다.")
|
||||||
|
.queue()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun handle(msg: ChatMessage, user: User) {
|
internal fun handle(msg: ChatMessage, user: User) {
|
||||||
|
@ -8,11 +8,13 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.channels.ClosedReceiveChannelException
|
import kotlinx.coroutines.channels.ClosedReceiveChannelException
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import org.koin.java.KoinJavaComponent.inject
|
import org.koin.java.KoinJavaComponent.inject
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import space.mori.chzzk_bot.common.events.*
|
import space.mori.chzzk_bot.common.events.*
|
||||||
import space.mori.chzzk_bot.common.services.SongConfigService
|
import space.mori.chzzk_bot.common.services.SongConfigService
|
||||||
import space.mori.chzzk_bot.common.services.SongListService
|
import space.mori.chzzk_bot.common.services.SongListService
|
||||||
|
import space.mori.chzzk_bot.common.services.UserService
|
||||||
import space.mori.chzzk_bot.common.utils.getYoutubeVideo
|
import space.mori.chzzk_bot.common.utils.getYoutubeVideo
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue
|
import java.util.concurrent.ConcurrentLinkedQueue
|
||||||
@ -20,7 +22,7 @@ import java.util.concurrent.ConcurrentLinkedQueue
|
|||||||
fun Routing.wsSongListRoutes() {
|
fun Routing.wsSongListRoutes() {
|
||||||
val sessions = ConcurrentHashMap<String, ConcurrentLinkedQueue<WebSocketServerSession>>()
|
val sessions = ConcurrentHashMap<String, ConcurrentLinkedQueue<WebSocketServerSession>>()
|
||||||
val status = ConcurrentHashMap<String, SongType>()
|
val status = ConcurrentHashMap<String, SongType>()
|
||||||
val logger = LoggerFactory.getLogger(this.javaClass.name)
|
val logger = LoggerFactory.getLogger("WSSongListRoutes")
|
||||||
|
|
||||||
val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
|
val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
|
||||||
|
|
||||||
@ -68,7 +70,7 @@ fun Routing.wsSongListRoutes() {
|
|||||||
for (frame in incoming) {
|
for (frame in incoming) {
|
||||||
when(frame) {
|
when(frame) {
|
||||||
is Frame.Text -> {
|
is Frame.Text -> {
|
||||||
val data = receiveDeserialized<SongRequest>()
|
val data = frame.readText().let { Json.decodeFromString<SongRequest>(it) }
|
||||||
|
|
||||||
if(data.maxQueue != null && data.maxQueue > 0) SongConfigService.updateQueueLimit(user, data.maxQueue)
|
if(data.maxQueue != null && data.maxQueue > 0) SongConfigService.updateQueueLimit(user, data.maxQueue)
|
||||||
if(data.maxUserLimit != null && data.maxUserLimit > 0) SongConfigService.updatePersonalLimit(user, data.maxUserLimit)
|
if(data.maxUserLimit != null && data.maxUserLimit > 0) SongConfigService.updatePersonalLimit(user, data.maxUserLimit)
|
||||||
@ -76,18 +78,20 @@ fun Routing.wsSongListRoutes() {
|
|||||||
|
|
||||||
if(data.url != null) {
|
if(data.url != null) {
|
||||||
val youtubeVideo = getYoutubeVideo(data.url)
|
val youtubeVideo = getYoutubeVideo(data.url)
|
||||||
|
if(youtubeVideo != null) {
|
||||||
dispatcher.post(
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
SongEvent(
|
SongListService.saveSong(user, user.token, data.url, youtubeVideo.name, youtubeVideo.author, youtubeVideo.length, user.username)
|
||||||
|
dispatcher.post(SongEvent(
|
||||||
user.token,
|
user.token,
|
||||||
SongType.ADD,
|
SongType.ADD,
|
||||||
user.token,
|
user.token,
|
||||||
user.username,
|
user.username,
|
||||||
youtubeVideo?.name,
|
youtubeVideo.name,
|
||||||
youtubeVideo?.author,
|
youtubeVideo.author,
|
||||||
youtubeVideo?.length
|
youtubeVideo.length
|
||||||
)
|
))
|
||||||
)
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(data.remove != null && data.remove > 0) {
|
if(data.remove != null && data.remove > 0) {
|
||||||
val songs = SongListService.getSong(user)
|
val songs = SongListService.getSong(user)
|
||||||
@ -125,15 +129,21 @@ fun Routing.wsSongListRoutes() {
|
|||||||
dispatcher.subscribe(SongEvent::class) {
|
dispatcher.subscribe(SongEvent::class) {
|
||||||
logger.debug("SongEvent: {} / {} {}", it.uid, it.type, it.name)
|
logger.debug("SongEvent: {} / {} {}", it.uid, it.type, it.name)
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
sessions[it.uid]?.forEach { ws ->
|
val user = UserService.getUser(it.uid)
|
||||||
ws.sendSerialized(SongResponse(
|
if(user != null) {
|
||||||
|
val session = SongConfigService.getConfig(user)
|
||||||
|
sessions[session.token]?.forEach { ws ->
|
||||||
|
ws.sendSerialized(
|
||||||
|
SongResponse(
|
||||||
it.type.value,
|
it.type.value,
|
||||||
it.uid,
|
it.uid,
|
||||||
it.reqUid,
|
it.reqUid,
|
||||||
it.name,
|
it.name,
|
||||||
it.author,
|
it.author,
|
||||||
it.time
|
it.time
|
||||||
))
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import java.util.concurrent.ConcurrentLinkedQueue
|
|||||||
fun Routing.wsSongRoutes() {
|
fun Routing.wsSongRoutes() {
|
||||||
val sessions = ConcurrentHashMap<String, ConcurrentLinkedQueue<WebSocketServerSession>>()
|
val sessions = ConcurrentHashMap<String, ConcurrentLinkedQueue<WebSocketServerSession>>()
|
||||||
val status = ConcurrentHashMap<String, SongType>()
|
val status = ConcurrentHashMap<String, SongType>()
|
||||||
val logger = LoggerFactory.getLogger(this.javaClass.name)
|
val logger = LoggerFactory.getLogger("WSSongRoutes")
|
||||||
|
|
||||||
fun addSession(uid: String, session: WebSocketServerSession) {
|
fun addSession(uid: String, session: WebSocketServerSession) {
|
||||||
sessions.computeIfAbsent(uid) { ConcurrentLinkedQueue() }.add(session)
|
sessions.computeIfAbsent(uid) { ConcurrentLinkedQueue() }.add(session)
|
||||||
|
@ -19,7 +19,7 @@ import java.util.concurrent.ConcurrentLinkedQueue
|
|||||||
fun Routing.wsTimerRoutes() {
|
fun Routing.wsTimerRoutes() {
|
||||||
val sessions = ConcurrentHashMap<String, ConcurrentLinkedQueue<WebSocketServerSession>>()
|
val sessions = ConcurrentHashMap<String, ConcurrentLinkedQueue<WebSocketServerSession>>()
|
||||||
val status = ConcurrentHashMap<String, TimerType>()
|
val status = ConcurrentHashMap<String, TimerType>()
|
||||||
val logger = LoggerFactory.getLogger(this.javaClass.name)
|
val logger = LoggerFactory.getLogger("WSTimerRoutes")
|
||||||
|
|
||||||
fun addSession(uid: String, session: WebSocketServerSession) {
|
fun addSession(uid: String, session: WebSocketServerSession) {
|
||||||
sessions.computeIfAbsent(uid) { ConcurrentLinkedQueue() }.add(session)
|
sessions.computeIfAbsent(uid) { ConcurrentLinkedQueue() }.add(session)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user