29 lines
940 B
Nim
29 lines
940 B
Nim
|
import sequtils, message, member, channel, guild, discordobject, nimcordutils, clientobjects, httpcore
|
||
|
|
||
|
type Cache* = ref object
|
||
|
members*: seq[GuildMember]
|
||
|
messages*: seq[Message]
|
||
|
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))
|