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) = proc readyEvent(json: JsonNode) =
let readyEvent = ReadyEvent(readyPayload: json, name: $EventType.evtReady) let readyEvent = ReadyEvent(readyPayload: json, name: $EventType.evtReady)
dispatchEvent(readyEvent) 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.}] = { let internalEventTable: Table[string, proc(json: JsonNode) {.nimcall.}] = {
"READY": readyEvent "READY": readyEvent,
"MESSAGE_CREATE": messageCreateEvent
}.toTable }.toTable
proc handleDiscordEvent*(json: JsonNode, eventName: string) = proc handleDiscordEvent*(json: JsonNode, eventName: string) =

View File

@ -1,13 +1,16 @@
import tables, hashes, json import tables, hashes, json, message
type type
EventType* = enum EventType* = enum
evtReady = "READY" evtReady = "READY"
evtMessageCreate = "MESSAGE_CREATE"
BaseEvent* = object of RootObj BaseEvent* = object of RootObj
name*: string name*: string
ReadyEvent* = object of BaseEvent ReadyEvent* = object of BaseEvent
readyPayload*: JsonNode readyPayload*: JsonNode
MessageCreateEvent* = object of BaseEvent
message*: Message
# Table storing all the event listeners # Table storing all the event listeners
let eventListeners = newTable[string, seq[proc(event: BaseEvent)]]() let eventListeners = newTable[string, seq[proc(event: BaseEvent)]]()