From 90dadd33712a14ebea7c34ae5e191c7fb3e80421 Mon Sep 17 00:00:00 2001 From: 5elenay <5elenay@protonmail.com> Date: Tue, 24 Aug 2021 18:50:53 +0300 Subject: [PATCH] added getter functions for cache. --- client.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/client.go b/client.go index 5363882..de8b1a8 100644 --- a/client.go +++ b/client.go @@ -182,3 +182,51 @@ func (c *Client) Auth() error { return nil } + +// Get a channel from cache by Id. +// Will return an empty channel struct if not found. +func (c *Cache) GetChannel(id string) *Channel { + for _, i := range c.Channels { + if i.Id == id { + return i + } + } + + return &Channel{} +} + +// Get a server from cache by Id. +// Will return an empty server struct if not found. +func (c *Cache) GetServer(id string) *Server { + for _, i := range c.Servers { + if i.Id == id { + return i + } + } + + return &Server{} +} + +// Get an user from cache by Id. +// Will return an empty user struct if not found. +func (c *Cache) GetUser(id string) *User { + for _, i := range c.Users { + if i.Id == id { + return i + } + } + + return &User{} +} + +// Get a member from cache by Id. +// Will return an empty member struct if not found. +func (c *Cache) GetMember(id string) *Member { + for _, i := range c.Members { + if i.Informations.UserId == id { + return i + } + } + + return &Member{} +}