diff --git a/bot.py b/bot.py index 19a4774..85a9294 100644 --- a/bot.py +++ b/bot.py @@ -57,6 +57,7 @@ async def on_ready(): await cur.execute("DELETE from liveupdate WHERE serverid = ?", (serverid,)) await cur.execute("DELETE from spotlightsubscriptions WHERE serverid = ?", (serverid,)) await db.commit() + bot.load_extension('cogs.league') #Must load first as it contains autofill code referenced in team bot.load_extension('cogs.team') #Must load first as it contains autofill code bot.load_extension('cogs.liveupdate') bot.load_extension('cogs.error') diff --git a/cogs/league.py b/cogs/league.py new file mode 100644 index 0000000..013f61d --- /dev/null +++ b/cogs/league.py @@ -0,0 +1,41 @@ +import hashlib +import json +from pathlib import Path +from datetime import datetime, timedelta, timezone +import requests +import asyncio +import nextcord +import aiosqlite as sqlite3 +from nextcord.ext import commands, application_checks, tasks +from nextcord import TextInputStyle, IntegrationType + +leagues_dict = {} +leagues_list = [] +def get_all_leagues(): + data = requests.get("https://freecashe.ws/api/leagues").json() + leagues_dict.clear() + leagues_list.clear() + for index in data["items"]: + leagues_list.append(f"{index["name"]}") + leagues_dict.update({f"{index["name"]}": index["league_id"]}) + print(leagues_dict) + print(leagues_list) + +class league(commands.Cog): + def __init__(self, bot: commands.Bot): + self.bot = bot + self.updateleagues.start() + + def cog_unload(self): + self.updateleagues.cancel() + + @tasks.loop(hours=24) #Unless there is some sort of story event this most likely won't frequently change + async def updateleagues(self): + print("Updating leagues autocomplete") + loop = asyncio.get_event_loop() + await loop.run_in_executor(None, get_all_leagues) + self.bot.leagues_list = leagues_list + self.bot.leagues_dict = leagues_dict + +def setup(bot: commands.Bot): + bot.add_cog(league(bot)) \ No newline at end of file