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.
2020-05-31 05:09:30 +00:00
|
|
|
import eventhandler, json, tables, hashes, message
|
2020-05-30 04:59:23 +00:00
|
|
|
|
|
|
|
proc readyEvent(json: JsonNode) =
|
|
|
|
let readyEvent = ReadyEvent(readyPayload: json, name: $EventType.evtReady)
|
|
|
|
dispatchEvent(readyEvent)
|
|
|
|
|
2020-05-31 05:09:30 +00:00
|
|
|
proc messageCreateEvent(json: JsonNode) =
|
|
|
|
let msg = newMessage(json)
|
|
|
|
let messageCreateEvnt = MessageCreateEvent(message: msg)
|
|
|
|
dispatchEvent(messageCreateEvnt)
|
|
|
|
|
2020-05-30 04:59:23 +00:00
|
|
|
let internalEventTable: Table[string, proc(json: JsonNode) {.nimcall.}] = {
|
2020-05-31 05:09:30 +00:00
|
|
|
"READY": readyEvent,
|
|
|
|
"MESSAGE_CREATE": messageCreateEvent
|
2020-05-30 04:59:23 +00:00
|
|
|
}.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
|