Create message create event.
This commit is contained in:
parent
5bdf6dc134
commit
44aee846b1
|
@ -1,11 +1,17 @@
|
|||
import eventhandler, json, tables, hashes
|
||||
import eventhandler, json, tables, hashes, message
|
||||
|
||||
proc readyEvent(json: JsonNode) =
|
||||
let readyEvent = ReadyEvent(readyPayload: json, name: $EventType.evtReady)
|
||||
dispatchEvent(readyEvent)
|
||||
|
||||
proc messageCreateEvent(json: JsonNode) =
|
||||
let msg = newMessage(json)
|
||||
let messageCreateEvnt = MessageCreateEvent(message: msg)
|
||||
dispatchEvent(messageCreateEvnt)
|
||||
|
||||
let internalEventTable: Table[string, proc(json: JsonNode) {.nimcall.}] = {
|
||||
"READY": readyEvent
|
||||
"READY": readyEvent,
|
||||
"MESSAGE_CREATE": messageCreateEvent
|
||||
}.toTable
|
||||
|
||||
proc handleDiscordEvent*(json: JsonNode, eventName: string) =
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
import tables, hashes, json
|
||||
import tables, hashes, json, message
|
||||
|
||||
type
|
||||
EventType* = enum
|
||||
evtReady = "READY"
|
||||
evtMessageCreate = "MESSAGE_CREATE"
|
||||
|
||||
BaseEvent* = object of RootObj
|
||||
name*: string
|
||||
ReadyEvent* = object of BaseEvent
|
||||
readyPayload*: JsonNode
|
||||
MessageCreateEvent* = object of BaseEvent
|
||||
message*: Message
|
||||
|
||||
# Table storing all the event listeners
|
||||
let eventListeners = newTable[string, seq[proc(event: BaseEvent)]]()
|
||||
|
|
Reference in New Issue