forked from Zerbaib/CleanDiscordBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
149 lines (126 loc) · 5.17 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import os
import platform
import aiohttp
import disnake
from disnake.ext import commands
from datetime import datetime
from utils.sql_manager import *
from utils.logger import *
from utils.json_manager import json_save, json_load
from utils.load_environement import load_enviroment_lang, load_enviroment_token
from utils.load_lang import main_lang
from data.var import *
from auto.creator import Creator
from auto.configurator import Configurator
get_next_log_file()
initDB()
lang = main_lang
printInfo("Starting")
Creator.config_folder()
Creator.data_files()
Creator.badword_file()
printInfo("Created files done")
printLog("Configuration step")
Configurator.env_file(lang)
printLog("Reload lang")
lang = main_lang
printLog("lang Reloaded")
printInfo("Config files done")
if not os.path.exists(configFilePath):
with open(configFilePath, 'w'):
prefix = input(lang.get("QUESTION_PREFIX"))
logID = int(input(lang.get("QUESTION_LOG_CHANNEL_ID")))
pollID = int(input(lang.get("QUESTION_POLL_CHANNEL_ID")))
joinID = int(input(lang.get("QUESTION_WELCOME_CHANNEL_ID")))
leaveID = int(input(lang.get("QUESTION_LEAVE_CHANNEL_ID")))
voiceID = int(input(lang.get("QUESTION_VOICE_CHANNEL_ID")))
ownerID = int(input(lang.get("QUESTION_OWNER_ID")))
muteID = int(input(lang.get("QUESTION_MUTE_ROLE_ID")))
rank1 = int(input(lang.get("QUESTION_XP_ROLE_10_ID")))
rank2 = int(input(lang.get("QUESTION_XP_ROLE_25_ID")))
rank3 = int(input(lang.get("QUESTION_XP_ROLE_50_ID")))
config_data = {
"PREFIX": prefix,
"LOG_ID": logID,
"POLL_ID": pollID,
"JOIN_ID": joinID,
"LEAVE_ID": leaveID,
"AUTO_VOICE_ID": voiceID,
"YOUR_ID": ownerID,
"MUTE_ROLE_ID": muteID,
"del_time": 3,
"level_roles": {
"10": rank1,
"25": rank2,
"50": rank3
}
}
json_save(configFilePath, config_data)
pass
try:
config = json_load(configFilePath)
except Exception as e:
print(lang.get("ERROR_CONFIG_LOAD").format(e))
exit(1)
prefix = config["PREFIX"]
botLang = load_enviroment_lang()
bot = commands.Bot(
command_prefix=prefix,
intents=disnake.Intents.all(),
case_insensitive=True
)
bot.remove_command('help')
@bot.event
async def on_ready():
if bot.user.discriminator == 0:
botName = bot.user.name
else:
botName = bot.user.name + "#" + bot.user.discriminator
async with aiohttp.ClientSession() as session:
async with session.get(onlineVersion) as response:
if response.status == 200:
botRepoVersion = await response.text()
else:
botRepoVersion = "Unknown"
with open(localVersionFilePath, 'r') as version_file:
botVersion = version_file.read().strip()
if botVersion != botRepoVersion:
print('='*multiplicator)
printWarn(lang.get("HEADER_OUTDATED_LN1"))
printWarn(lang.get("HEADER_OUTDATED_LN2"))
printWarn(lang.get("HEADER_OUTDATED_LN3"))
print('='*multiplicator)
printInfo(lang.get("HEADER_LN1").format(reset=reset))
printInfo(lang.get("HEADER_LN2").format(botName=botName, botId=bot.user.id, reset=reset, blue=blue))
printInfo(lang.get("HEADER_LN3").format(amount=len(bot.guilds), reset=reset, blue=blue))
printInfo(lang.get("HEADER_LN4").format(language=botLang, reset=reset, blue=blue))
printInfo(lang.get("HEADER_LN5").format(prefix=prefix, reset=reset, blue=blue))
printInfo(lang.get("HEADER_LN6").format(owner=bot.get_user(config["YOUR_ID"]), reset=reset, blue=blue))
printInfo(lang.get("HEADER_LN7").format(gitBranch=gitBranch, reset=reset, blue=blue))
printInfo(lang.get("HEADER_LN8").format(botVersion=botVersion, reset=reset, blue=blue))
printInfo(lang.get("HEADER_LN9").format(botRepoVersion=botRepoVersion, reset=reset, blue=blue))
printInfo(lang.get("HEADER_LN10").format(apiVersion=disnake.__version__, reset=reset, blue=blue))
printInfo(lang.get("HEADER_LN11").format(platformSystem=platform.system(), platformVersion=platform.release(), osName=os.name, reset=reset, blue=blue))
printInfo(lang.get("HEADER_LN12").format(pythonVersion=platform.python_version(), reset=reset, blue=blue))
printInfo(lang.get("HEADER_LN13").format(timeNow=datetime.utcnow().strftime("%d-%m-%Y %H:%M:%S"), reset=reset, blue=blue))
print('='*multiplicator)
return
for element in os.listdir(cogsFolder):
try:
element_dir = f"{cogsFolder}{element}"
if os.path.isdir(element_dir):
for filename in os.listdir(element_dir):
if filename.endswith('.py'):
cog_name = filename[:-3]
try:
bot.load_extension(f'cogs.{element}.{cog_name}')
except Exception as e:
printError(lang.get("ERROR_COG_LOADING").format(cogName=cog_name, e=e))
except Exception as e:
printError(lang.get("ERROR_ELEMENTS_LOADING").format(element, e))
exit(1)
try:
bot.run(load_enviroment_token())
except Exception as e:
print(lang.get("ERROR_BOT_RUN"))
exit(1)