Right... I cannot have global variables - scratch that idea

This commit is contained in:
Jeremy Zhang 2017-03-24 00:02:15 -07:00
parent d3e04fec5f
commit d48af50178

View File

@ -5,8 +5,7 @@ import json
from cachetools import cached, TTLCache from cachetools import cached, TTLCache
_DISCORD_API_BASE = "https://discordapp.com/api/v6" _DISCORD_API_BASE = "https://discordapp.com/api/v6"
get_widget_cache = TTLCache(200, 300) cache = TTLCache(200, 300)
guild_list_cache = TTLCache(1, 300) # Pop the list if new guilds are added
def json_or_text(response): def json_or_text(response):
text = response.text text = response.text
@ -140,7 +139,7 @@ class DiscordREST:
# User # User
##################### #####################
@cached(guild_list_cache) @cached(cache)
def get_all_guilds(self): def get_all_guilds(self):
_endpoint = "/users/@me/guilds" _endpoint = "/users/@me/guilds"
params = {} params = {}
@ -163,7 +162,7 @@ class DiscordREST:
# Widget Handler # Widget Handler
##################### #####################
@cached(get_widget_cache) @cached(cache)
def get_widget(self, guild_id): def get_widget(self, guild_id):
_endpoint = _DISCORD_API_BASE + "/servers/{guild_id}/widget.json".format(guild_id=guild_id) _endpoint = _DISCORD_API_BASE + "/servers/{guild_id}/widget.json".format(guild_id=guild_id)
embed = self.get_guild_embed(guild_id) embed = self.get_guild_embed(guild_id)