From 76b1797bee6a9a020049a85295556355d1b6e747 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Sat, 20 Jun 2020 23:05:51 -0500 Subject: [PATCH] Finish channelCreateEvent --- src/eventdispatcher.nim | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/eventdispatcher.nim b/src/eventdispatcher.nim index 215e898..ab84bc7 100644 --- a/src/eventdispatcher.nim +++ b/src/eventdispatcher.nim @@ -21,11 +21,17 @@ proc readyEvent(discordClient: DiscordClient, json: JsonNode) = proc channelCreateEvent(discordClient: DiscordClient, json: JsonNode) = let chnl = newChannel(json) - let channelCreateEvnt = ChannelCreateEvent(client: discordClient, channel: chnl, name: $EventType.evtChannelCreate) + let channelCreateEvent = ChannelCreateEvent(client: discordClient, channel: chnl, name: $EventType.evtChannelCreate) + + # Add the channel to its guild's `channels` field + if (chnl.guildID != 0): + discordClient.cache.cacheGuildChannel(chnl.guildID, chnl) + discordClient.cache.channels.add(chnl) + dispatchEvent(channelCreateEvent) -proc channelUpdateEvent(discordClient: DiscordClient, json: JsonNode) = -proc channelDeleteEvent(discordClient: DiscordClient, json: JsonNode) = +#proc channelUpdateEvent(discordClient: DiscordClient, json: JsonNode) = +#proc channelDeleteEvent(discordClient: DiscordClient, json: JsonNode) = proc messageCreateEvent(discordClient: DiscordClient, json: JsonNode) = let msg = newMessage(json) @@ -44,7 +50,8 @@ proc guildCreateEvent(discordClient: DiscordClient, json: JsonNode) = let internalEventTable: Table[string, proc(discordClient: DiscordClient, json: JsonNode) {.nimcall.}] = { "READY": readyEvent, "MESSAGE_CREATE": messageCreateEvent, - "GUILD_CREATE": guildCreateEvent + "GUILD_CREATE": guildCreateEvent, + "CHANNEL_CREATE": channelCreateEvent }.toTable proc handleDiscordEvent*(discordClient: DiscordClient, json: JsonNode, eventName: string) {.async.} =