2022-02-06 02:58:55 +02:00
try :
2023-03-22 21:59:50 +02:00
from discord import Activity , ActivityType , ApplicationContext , Bot , Intents
2023-01-17 16:05:39 +02:00
from requests import get
2022-02-06 02:58:55 +02:00
except Exception as exp :
2023-03-22 21:59:50 +02:00
print (
f " Dependencies not installed. Make sure to run ' pip install -r requirements.txt ' before first start "
)
2023-01-17 16:05:39 +02:00
exit ( )
2022-02-06 02:58:55 +02:00
2023-05-07 17:39:48 +03:00
from os import getpid , path
2023-03-22 21:59:50 +02:00
2022-02-05 02:31:32 +02:00
from functions import *
2023-01-17 16:05:39 +02:00
pid = getpid ( )
2023-05-07 17:39:48 +03:00
version = 2.3
2022-02-14 19:07:31 +02:00
2023-03-22 21:59:50 +02:00
if (
2023-05-07 17:39:48 +03:00
not path . exists ( " config.json " )
or loadJson ( " config.json " ) [ " owner " ] == " SET-OWNER-ID "
2023-03-22 21:59:50 +02:00
or loadJson ( " config.json " ) [ " bot_token " ] == " SET-BOT-TOKEN "
) :
print (
f " Bot is not correctly configured. \n Make sure you ' ve set up owner id and bot token in ' config.json ' \n Learn more here: https://git.end-play.xyz/profitroll/YusarinBot "
)
2023-01-17 16:05:39 +02:00
exit ( )
2022-02-07 03:06:01 +02:00
if loadJson ( " config.json " ) [ " check_for_updates " ] :
2023-03-22 22:26:05 +02:00
appendLog ( f " Currently using YusarinBot v { str ( version ) } " )
2022-02-07 03:06:01 +02:00
try :
2023-03-22 22:26:05 +02:00
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 :
2023-03-22 21:59:50 +02:00
appendLog (
2023-03-22 22:26:05 +02:00
f " YusarinBot version { releases [ 0 ] [ ' tag_name ' ] } is available. Download new version here: { releases [ 0 ] [ ' html_url ' ] } "
2023-03-22 21:59:50 +02:00
)
2022-02-07 03:06:01 +02:00
except Exception as exp :
2023-03-22 21:59:50 +02:00
appendLog (
f " Could not get YusarinBot cloud version due to { exp } . Currently using { str ( version ) } "
)
2022-02-05 02:31:32 +02:00
2022-05-09 00:09:19 +03:00
intents = Intents ( ) . all ( )
2023-01-17 16:05:39 +02:00
client = Bot ( intents = intents )
2022-02-05 02:31:32 +02:00
2023-01-17 16:50:47 +02:00
from cogs . cogCategory import CogCategory
from cogs . cogChannel import CogChannel
from cogs . cogLocale import CogLocale
from cogs . cogUtility import CogUtility
2023-03-22 21:59:50 +02:00
2023-01-17 16:50:47 +02:00
@client.slash_command ( name = " help " , description = " Get information about this server " )
async def help ( ctx : ApplicationContext ) :
await ctx . respond ( embed = getHelpMessage ( ctx , version ) )
2023-03-22 21:59:50 +02:00
2022-02-05 02:31:32 +02:00
@client.event
async def on_ready ( ) :
2022-02-07 03:06:01 +02:00
appendLog ( f " Logged in as { client . user } " )
2023-03-22 21:59:50 +02:00
2022-02-05 02:31:32 +02:00
config = loadJson ( " config.json " )
2023-03-22 21:59:50 +02:00
await client . change_presence (
activity = Activity ( type = ActivityType . listening , name = config [ " bot_activity " ] )
)
2022-02-07 03:06:01 +02:00
await clearTrash ( client )
2022-02-05 02:31:32 +02:00
2023-03-22 21:59:50 +02:00
2023-01-17 16:50:47 +02:00
client . add_cog ( CogCategory ( client ) )
client . add_cog ( CogChannel ( client ) )
client . add_cog ( CogLocale ( client ) )
client . add_cog ( CogUtility ( client ) )
2022-02-05 02:31:32 +02:00
2022-05-09 00:09:19 +03:00
appendLog ( f " Trying to log in... " )
2023-03-22 21:59:50 +02:00
client . run ( loadJson ( " config.json " ) [ " bot_token " ] )