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
940 B
Nim
Raw Normal View History

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))