mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 21:01:14 +00:00
add WebSocket timers
- EventDispatcher, TimerEvent add.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package space.mori.chzzk_bot.common.events
|
||||
|
||||
interface Event
|
||||
|
||||
interface EventHandler<E: Event> {
|
||||
suspend fun handle(event: E)
|
||||
}
|
||||
|
||||
object EventDispatcher {
|
||||
private val handlers = mutableMapOf<Class<out Event>, MutableList<EventHandler<out Event>>>()
|
||||
|
||||
fun <E : Event> register(eventClass: Class<E>, handler: EventHandler<E>) {
|
||||
handlers.computeIfAbsent(eventClass) { mutableListOf() }.add(handler)
|
||||
}
|
||||
|
||||
suspend fun <E : Event> dispatch(event: E) {
|
||||
handlers[event::class.java]?.forEach { (it as EventHandler<E>).handle(event) }
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package space.mori.chzzk_bot.common.events
|
||||
|
||||
enum class TimerType {
|
||||
UPTIME, TIMER, REMOVE
|
||||
}
|
||||
|
||||
class TimerEvent(
|
||||
val uid: String,
|
||||
val type: TimerType,
|
||||
val time: String?
|
||||
): Event
|
Reference in New Issue
Block a user