This repository has been archived on 2023-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
nimcord/src/eventdispatcher.nim

16 lines
587 B
Nim
Raw Normal View History

2020-05-30 04:59:23 +00:00
import eventhandler, json, tables, hashes
proc readyEvent(json: JsonNode) =
let readyEvent = ReadyEvent(readyPayload: json, name: $EventType.evtReady)
dispatchEvent(readyEvent)
let internalEventTable: Table[string, proc(json: JsonNode) {.nimcall.}] = {
"READY": readyEvent
}.toTable
proc handleDiscordEvent*(json: JsonNode, eventName: string) =
if (internalEventTable.hasKey(eventName)):
let eventProc:proc(json: JsonNode) = internalEventTable[eventName]
eventProc(json)
else:
echo "Failed to find event: ", eventName