YusarinBot/yusarin.py

75 lines
2.2 KiB
Python

try:
from discord import Activity, ActivityType, ApplicationContext, Bot, Intents
from requests import get
except Exception as exp:
print(
f"Dependencies not installed. Make sure to run 'pip install -r requirements.txt' before first start"
)
exit()
from os import getpid
from functions import *
pid = getpid()
version = 2.0
if (
loadJson("config.json")["owner"] == "SET-OWNER-ID"
or loadJson("config.json")["bot_token"] == "SET-BOT-TOKEN"
):
print(
f"Bot is not correctly configured.\nMake sure you've set up owner id and bot token in 'config.json'\nLearn more here: https://git.end-play.xyz/profitroll/YusarinBot"
)
exit()
if loadJson("config.json")["check_for_updates"]:
appendLog(f"Currently using YusarinBot v{str(version)}")
try:
releases = get(
"https://git.end-play.xyz/api/v1/repos/profitroll/YusarinBot/releases?draft=false&pre-release=false&page=1&limit=1"
).json()
if float(releases[0]["tag_name"].replace("v", "")) > version:
appendLog(
f"YusarinBot version {releases[0]['tag_name']} is available. Download new version here: {releases[0]['html_url']}"
)
except Exception as exp:
appendLog(
f"Could not get YusarinBot cloud version due to {exp}. Currently using {str(version)}"
)
intents = Intents().all()
client = Bot(intents=intents)
from cogs.cogCategory import CogCategory
from cogs.cogChannel import CogChannel
from cogs.cogLocale import CogLocale
from cogs.cogUtility import CogUtility
@client.slash_command(name="help", description="Get information about this server")
async def help(ctx: ApplicationContext):
await ctx.respond(embed=getHelpMessage(ctx, version))
@client.event
async def on_ready():
appendLog(f"Logged in as {client.user}")
config = loadJson("config.json")
await client.change_presence(
activity=Activity(type=ActivityType.listening, name=config["bot_activity"])
)
await clearTrash(client)
client.add_cog(CogCategory(client))
client.add_cog(CogChannel(client))
client.add_cog(CogLocale(client))
client.add_cog(CogUtility(client))
appendLog(f"Trying to log in...")
client.run(loadJson("config.json")["bot_token"])