Add a getGuild proc and most some things around.

This commit is contained in:
SeanOMik 2020-06-18 21:24:15 -05:00
parent deb19c8842
commit a665d00030
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
1 changed files with 20 additions and 16 deletions

View File

@ -6,24 +6,28 @@ type Cache* = ref object
channels*: seq[Channel]
guilds*: seq[Guild]
proc getMessageChannel*(msg: Message, cache: Cache): Channel =
for index, channel in cache.channels:
if (channel.id == msg.channelID):
return channel
return nil
proc getChannelGuild*(channel: Channel, cache: Cache): Guild =
for index, guild in cache.guilds:
if (guild.id == channel.guildID):
return guild
return nil
proc getChannel*(cache: Cache, id: snowflake): Channel =
for index, channel in cache.channels:
if (channel.id == id):
return channel
return newChannel(sendRequest(endpoint("/channels/" & $id), HttpGet,
defaultHeaders(), id, RateLimitBucketType.channel))
return newChannel(sendRequest(endpoint("/channels/" & $id), HttpGet, defaultHeaders(),
id, RateLimitBucketType.channel))
proc getMessageChannel*(msg: Message, cache: Cache): Channel =
## Get a message's channel object.
##
## If for some reason the channel is not in cache, it gets requested via the
## Discord REST API.
return cache.getChannel(msg.channelID)
proc getGuild*(cache: Cache, id: snowflake): Guild =
for index, guild in cache.guilds:
if (guild.id == id):
return guild
return newGuild(sendRequest(endpoint("/guild/" & $id), HttpGet, defaultHeaders(),
id, RateLimitBucketType.guild))
proc getChannelGuild*(channel: Channel, cache: Cache): Guild =
return cache.getGuild(channel.guildID)