added event classes, working on dispatch
This commit is contained in:
parent
b29e282300
commit
c105a0c29a
|
@ -1,4 +1,4 @@
|
||||||
import eventhandler, json, tables, message, user, nimcordutils, httpClient, strformat, cache, guild, sequtils, asyncdispatch, clientobjects
|
import eventhandler, json, tables, message, emoji, user, member, role, guild, channel, nimcordutils, httpClient, strformat, cache, sequtils, asyncdispatch, clientobjects
|
||||||
|
|
||||||
proc readyEvent(discordClient: DiscordClient, json: JsonNode) =
|
proc readyEvent(discordClient: DiscordClient, json: JsonNode) =
|
||||||
var readyEvent = ReadyEvent(client: discordClient, readyPayload: json, name: $EventType.evtReady)
|
var readyEvent = ReadyEvent(client: discordClient, readyPayload: json, name: $EventType.evtReady)
|
||||||
|
@ -19,6 +19,14 @@ proc readyEvent(discordClient: DiscordClient, json: JsonNode) =
|
||||||
|
|
||||||
dispatchEvent(readyEvent)
|
dispatchEvent(readyEvent)
|
||||||
|
|
||||||
|
proc channelCreateEvent(discordClient: DiscordClient, json: JsonNode) =
|
||||||
|
let chnl = newChannel(json)
|
||||||
|
let channelCreateEvnt = ChannelCreateEvent(client: discordClient, channel: chnl, name: $EventType.evtChannelCreate)
|
||||||
|
dispatchEvent(channelCreateEvent)
|
||||||
|
|
||||||
|
proc channelUpdateEvent(discordClient: DiscordClient, json: JsonNode) =
|
||||||
|
proc channelDeleteEvent(discordClient: DiscordClient, json: JsonNode) =
|
||||||
|
|
||||||
proc messageCreateEvent(discordClient: DiscordClient, json: JsonNode) =
|
proc messageCreateEvent(discordClient: DiscordClient, json: JsonNode) =
|
||||||
let msg = newMessage(json)
|
let msg = newMessage(json)
|
||||||
let messageCreateEvnt = MessageCreateEvent(client: discordClient, message: msg, name: $EventType.evtMessageCreate)
|
let messageCreateEvnt = MessageCreateEvent(client: discordClient, message: msg, name: $EventType.evtMessageCreate)
|
||||||
|
|
|
@ -1,30 +1,155 @@
|
||||||
import tables, hashes, json, message, user, guild, clientobjects
|
import tables, hashes, json, message, emoji, user, member, role, guild, channel, clientobjects
|
||||||
|
|
||||||
type
|
type
|
||||||
EventType* = enum
|
EventType* = enum
|
||||||
## The event type.
|
## The event type.
|
||||||
evtReady = "READY"
|
evtReady = "READY"
|
||||||
evtMessageCreate = "MESSAGE_CREATE"
|
evtResumed = "RESUMED"
|
||||||
|
evtReconnect = "RECONNECT"
|
||||||
|
evtInvalidSession = "INVALID_SESSION"
|
||||||
|
evtChannelCreate = "CHANNEL_CREATE"
|
||||||
|
evtChannelUpdate = "CHANNEL_UPDATE"
|
||||||
|
evtChannelDelete = "CHANNEL_DELETE"
|
||||||
|
evtChannelPinsUpdate = "CHANNEL_PINS_UPDATE"
|
||||||
evtGuildCreate = "GUILD_CREATE"
|
evtGuildCreate = "GUILD_CREATE"
|
||||||
|
evtGuildUpdate = "GUILD_UPDATE"
|
||||||
|
evtGuildDelete = "GUILD_DELETE"
|
||||||
|
evtGuildBanAdd = "GUILD_BAN_ADD"
|
||||||
|
evtGuildBanRemove = "GUILD_BAN_REMOVE"
|
||||||
|
evtGuildEmojisUpdate = "GUILD_EMOJIS_UPDATE"
|
||||||
|
evtGuildIntegrationsUpdate = "GUILD_INTEGRATIONS_UPDATE"
|
||||||
|
evtGuildMemberAdd = "GUILD_MEMBER_ADD"
|
||||||
|
evtGuildMemberRemove = "GUILD_MEMBER_REMOVE"
|
||||||
|
evtGuildMemberUpdate = "GUILD_MEMBER_UPDATE"
|
||||||
|
evtGuildMembersChunk = "GUILD_MEMBERS_CHUNK"
|
||||||
|
evtGuildRoleCreate = "GUILD_ROLE_CREATE"
|
||||||
|
evtGuildRoleUpdate = "GUILD_ROLE_UPDATE"
|
||||||
|
evtGuildRoleDelete = "GUILD_ROLE_DELETE"
|
||||||
|
evtMessageUpdate = "MESSAGE_UPDATE"
|
||||||
|
evtMessageDelete = "MESSAGE_DELETE"
|
||||||
|
evtMessageCreate = "MESSAGE_CREATE"
|
||||||
|
evtMessageDeleteBulk = "MESSAGE_DELETE_BULK"
|
||||||
|
evtMessageReactionAdd = "MESSAGE_REACTION_ADD"
|
||||||
|
evtMessageReactionRemove = "MESSAGE_REACTION_REMOVE"
|
||||||
|
evtMessageReactionRemoveAll = "MESSAGE_REACTION_REMOVE_ALL"
|
||||||
|
evtPresenceUpdate = "PRESENCE_UPDATE"
|
||||||
|
evtTypingStart = "TYPING_START"
|
||||||
|
evtUserUpdate = "USER_UPDATE"
|
||||||
|
evtVoiceStateUpdate = "VOICE_STATE_UPDATE"
|
||||||
|
evtVoiceServerUpdate = "VOICE_SERVER_UPDATE"
|
||||||
|
evtWebhooksUpdate = "WEBHOOKS_UPDATE"
|
||||||
|
|
||||||
BaseEvent* = object of RootObj
|
BaseEvent* = object of RootObj
|
||||||
## Base event that all events inherit from.
|
## Base event that all events inherit from.
|
||||||
## It stores a reference to the DiscordClient and name of the event.
|
## It stores a reference to the DiscordClient and name of the event.
|
||||||
client*: DiscordClient
|
client*: DiscordClient
|
||||||
name*: string
|
name*: string
|
||||||
|
|
||||||
|
# Socket Events
|
||||||
|
|
||||||
ReadyEvent* = object of BaseEvent
|
ReadyEvent* = object of BaseEvent
|
||||||
## The ready event is triggered everytime the bot starts up.
|
## The ready event is triggered everytime the bot starts up.
|
||||||
## Stores the readyPayload (JSON Payload) that gets received and the bot's user.
|
## Stores the readyPayload (JSON Payload) that gets received and the bot's user.
|
||||||
readyPayload*: JsonNode
|
readyPayload*: JsonNode
|
||||||
clientUser*: User
|
clientUser*: User
|
||||||
MessageCreateEvent* = object of BaseEvent
|
|
||||||
## The Message Create event is triggered when someone sends a message.
|
# Channel Events
|
||||||
message*: Message
|
|
||||||
|
ChannelCreateEvent* = object of BaseEvent
|
||||||
|
## The Channel Create event is triggered when a new channel is created.
|
||||||
|
channel*: Channel
|
||||||
|
|
||||||
|
ChannelUpdateEvent* = object of BaseEvent
|
||||||
|
## The Channel Update event is triggered when a channel is updated.
|
||||||
|
channel*: Channel
|
||||||
|
|
||||||
|
ChannelDeleteEvent* = object of BaseEvent
|
||||||
|
## The Channel Delete event is triggered when a channel is deleted.
|
||||||
|
channel*: Channel
|
||||||
|
|
||||||
|
ChannelPinsUpdateEvent* = object of BaseEvent
|
||||||
|
## The Channel Pins Update event is triggered when a channel pin is updated.
|
||||||
|
channel*: Channel
|
||||||
|
|
||||||
|
# Guild Events
|
||||||
|
|
||||||
GuildCreateEvent* = object of BaseEvent
|
GuildCreateEvent* = object of BaseEvent
|
||||||
## The Guild Create event is triggered when the bot starts, or when
|
## The Guild Create event is triggered when the bot starts, or when
|
||||||
## it gets added to a new guild.
|
## it gets added to a new guild.
|
||||||
guild*: Guild
|
guild*: Guild
|
||||||
|
|
||||||
|
GuildUpdateEvent* = object of BaseEvent
|
||||||
|
## The Guild Update event is triggered when a guild is updated.
|
||||||
|
guild*: Guild
|
||||||
|
|
||||||
|
GuildDeleteEvent* = object of BaseEvent
|
||||||
|
## The Guild Delete event is triggered when a guild is deleted.
|
||||||
|
guild*: Guild
|
||||||
|
|
||||||
|
GuildBanAddEvent* = object of BaseEvent
|
||||||
|
## The Guild Ban Add Event is triggered when a member is banned from the guild.
|
||||||
|
guild*: Guild
|
||||||
|
guild_member*: GuildMember
|
||||||
|
|
||||||
|
GuildBanRemoveEvent* = object of BaseEvent
|
||||||
|
## The Guild Ban Remove Event is triggered when a member is unbanned from a guild.
|
||||||
|
guild*: Guild
|
||||||
|
guild_member*: GuildMember
|
||||||
|
|
||||||
|
GuildEmojisUpdateEvent* = object of BaseEvent
|
||||||
|
## The Guild Emojis Update event is triggered when a guild emote is updated.
|
||||||
|
guild*: Guild
|
||||||
|
emoji*: Emoji
|
||||||
|
|
||||||
|
#GuildIntegrationsUpdateEvent* = object of BaseEvent
|
||||||
|
|
||||||
|
GuildMemberAddEvent* = object of BaseEvent
|
||||||
|
## The Guild Member Add event is triggered when a user joins a guild.
|
||||||
|
guild*: Guild
|
||||||
|
guild_member*: GuildMember
|
||||||
|
|
||||||
|
GuildMemberRemoveEvent* = object of BaseEvent
|
||||||
|
## The Guild Member Remove event is triggered when a user leaves a guild.
|
||||||
|
guild*: Guild
|
||||||
|
guild_member*: GuildMember
|
||||||
|
|
||||||
|
GuildMemberUpdateEvent* = object of BaseEvent
|
||||||
|
## The Guild Member Update event is triggered when a member is updated.
|
||||||
|
guild*: Guild
|
||||||
|
guild_member*: GuildMember
|
||||||
|
|
||||||
|
#GuildMembersChunkEvent* = object of BaseEvent
|
||||||
|
|
||||||
|
GuildRoleCreateEvent* = object of BaseEvent
|
||||||
|
## The Guild Role Create event is triggered when a role is created.
|
||||||
|
guild*: Guild
|
||||||
|
role*: Role
|
||||||
|
|
||||||
|
GuildRoleUpdateEvent* = object of BaseEvent
|
||||||
|
## The Guild Role Update event is triggered when a role is updated.
|
||||||
|
guild*: Guild
|
||||||
|
role*: Role
|
||||||
|
|
||||||
|
GuildRoleDeleteEvent* = object of BaseEvent
|
||||||
|
## The Guild Role Delete event is triggered when a role is deleted.
|
||||||
|
guild*: Guild
|
||||||
|
role*: Role
|
||||||
|
|
||||||
|
# Message events
|
||||||
|
|
||||||
|
MessageCreateEvent* = object of BaseEvent
|
||||||
|
## The Message Create event is triggered when someone sends a message.
|
||||||
|
message*: Message
|
||||||
|
|
||||||
|
MessageUpdateEvent* = object of BaseEvent
|
||||||
|
## The Message Update event is triggered when a message is updated.
|
||||||
|
message*: Message
|
||||||
|
|
||||||
|
MessageDeleteEvent* = object of BaseEvent
|
||||||
|
## The Message Create event is triggered when a message is deleted.
|
||||||
|
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