Create message create event.
This commit is contained in:
parent
5bdf6dc134
commit
44aee846b1
|
@ -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) =
|
||||||
|
|
|
@ -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)]]()
|
||||||
|
|
Reference in New Issue