From 44aee846b1785031f09bb7ed2bdbf1e62b07c2fe Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Sun, 31 May 2020 00:09:30 -0500 Subject: [PATCH] Create message create event. --- src/eventdispatcher.nim | 10 ++++++++-- src/eventhandler.nim | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/eventdispatcher.nim b/src/eventdispatcher.nim index eda742b..e78fbdf 100644 --- a/src/eventdispatcher.nim +++ b/src/eventdispatcher.nim @@ -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) = diff --git a/src/eventhandler.nim b/src/eventhandler.nim index 659e2fc..f4ed93b 100644 --- a/src/eventhandler.nim +++ b/src/eventhandler.nim @@ -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)]]()