-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
101 lines (85 loc) · 3.78 KB
/
bot.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
import discord
import os
import fade
import json
from discord.ext import commands
from dotenv import load_dotenv
from colorama import Fore as F
# please note that this damn god forbidden load .env function can only work with properly set up libraries
# if you try to do it otherwise and not like it says in README then it´s your fault and you can fuck with that on your own
# note aswell that i am not planning to fix it becouse it´s your own fault if you dont set up you´r enviroment right and dont know what you are doing
os.environ.clear()
load_dotenv()
# Get token from environment variables
token = os.getenv('TOKEN')
# Define default configuration dictionary
default_config: dict = {
"debug": False,
"command_prefix": ">"
}
# Set path to the primary configuration file
primary_config_file_path: str = "./cfg/config.json"
# Initialize configuration dictionary with default settings
config: dict = default_config
# If user-defined configuration file exists, merge it with default configuration
if os.path.exists(primary_config_file_path):
with open(primary_config_file_path, "r") as config_file:
user_config = json.load(config_file)
config.update(user_config)
else:
print(f"'{primary_config_file_path}' is not found. Using default configuration.")
# Assign extracted configuration values to separate variables
debug: bool = config.get("debug")
cfg_prefix: str = config.get("command_prefix")
# bot intialization
class Bot(commands.Bot):
def __init__(self, command_prefix, self_bot):
super().__init__(
command_prefix=command_prefix,
self_bot=self_bot
)
# Initialization tasks performed after instantiation
self.banner()
self.cogs_folder = "cogs"
self.remove_command("help")
self.debug = debug
async def setup_hook(self):
# Perform initialization tasks required during cog loading
cog_files = [f[:-3] for f in os.listdir(self.cogs_folder) if f.endswith(".py")]
for cog_file in cog_files:
cog_path = f"{self.cogs_folder}.{cog_file}"
try:
await self.load_extension(cog_path)
print(f"{F.GREEN}[+]{F.LIGHTWHITE_EX} Loaded {cog_file}")
except Exception as e:
print(f"{F.RED}[-]{F.LIGHTWHITE_EX} Failed to load {cog_file}.\n Error: {F.RED}{e}{F.RESET}")
exit()
print(f"{F.YELLOW}[?]{F.LIGHTWHITE_EX} Connecting...")
def banner(self):
"""Print a fancy banner."""
print(fade.purplepink("""
_____ ____ ____ __
/ ___/____ __ __/ / /__ __________ / __ )____ / /_
\__ \/ __ \/ / / / / / _ \/ ___/ ___/ / __ / __ \/ __/
___/ / /_/ / /_/ / / / __(__ |__ ) / /_/ / /_/ / /_
/____/\____/\__,_/_/_/\___/____/____/ /_____/\____/\__/
made by N0Soull
"""))
# on ready message
async def on_ready(self):
# Callback executed upon successful connection to Discord server
# sets standart presense (status: idle activity: listenting)
await self.change_presence(
status=discord.Status.idle,
activity=discord.Activity(
type=discord.ActivityType.watching, #activity types: playing, watching, streaming, listening, custom, competing
name="N0Soul go insane"
),
afk=True # AFK mode: ON/OFF for discord to better catch and force the notifications
)
print(f"{F.LIGHTMAGENTA_EX}(*){F.LIGHTWHITE_EX} rpc set to: {F.LIGHTMAGENTA_EX}Start")
if self.debug:
print("PRESENSE CHANGED: \nDefeault presense")
# Instantiate client object and run the bot
client = Bot(command_prefix=cfg_prefix, self_bot=True)
client.run(token)