mirror of
https://github.com/insertapp/mmolbbot.git
synced 2025-07-01 14:27:03 +00:00
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
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)) |