Create message create event.

This commit is contained in:
SeanOMik 2020-05-31 00:09:30 -05:00
parent 5bdf6dc134
commit 44aee846b1
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
2 changed files with 12 additions and 3 deletions

View File

@ -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) =

View File

@ -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)]]()