This repository has been archived on 2023-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
nimcord/src/cache.nim

29 lines
925 B
Nim
Raw Normal View History

2020-06-18 03:37:21 +00:00
import sequtils, message, member, channel, guild, discordobject, nimcordutils, 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))