mirror of
https://github.com/insertapp/mmolbbot.git
synced 2025-07-01 14:27:03 +00:00
feat: leauge data
This commit is contained in:
parent
c3f1832ac3
commit
038122f6ed
2 changed files with 42 additions and 0 deletions
1
bot.py
1
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')
|
||||
|
|
41
cogs/league.py
Normal file
41
cogs/league.py
Normal file
|
@ -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))
|
Loading…
Reference in a new issue