Add a getGuild proc and most some things around.
This commit is contained in:
parent
deb19c8842
commit
a665d00030
|
@ -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)
|
Reference in New Issue