-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
153 lines (123 loc) · 4.63 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
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
150
151
152
153
import os
import discord
from discord.ext import commands, tasks
from core import settings
from core.permissions import bot_perms
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix=".", intents=intents)
cmdlist = []
def refresh_cogs():
cmdlist.clear()
# Saving all cogs names to array {listcmd}
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
cmdlist.append(filename[:-3])
refresh_cogs()
activecmd = cmdlist.copy()
for filename in activecmd:
bot.load_extension(f"cogs.{filename}")
@bot.event
async def on_ready():
print(f"{bot.user.name} has got ALIVE!")
change_status.start() # Changes her status
@tasks.loop(minutes=3)
async def change_status():
await bot.change_presence(activity=discord.Game(next(bot_perms.cycle_bot_status)))
@bot.command(aliases=["f5"])
async def refresh(ctx, extension=""):
if await bot.is_owner(ctx.author):
refresh_cogs()
await ctx.send(f"system refreshed ({len(cmdlist)} cogs)")
@bot.command()
async def load(ctx, extension=""):
if await bot.is_owner(ctx.author):
if len(cmdlist) == len(activecmd):
await ctx.send("There is nothing new to load!")
return
if extension == "all":
for filename in cmdlist:
try:
bot.load_extension(f"cogs.{filename}")
except:
# reload in this case
print(f"EXCEPTION : Extension {filename} already loaded")
await ctx.send(f"All extensions loaded! [total : {len(cmdlist)}].")
elif extension not in cmdlist:
await ctx.send(
"That is not a valid extension, all available extensions are: "
)
for e in cmdlist:
await ctx.send(f"`{e}\n`")
elif extension in activecmd:
bot.unload_extension(f"cogs.{extension}")
bot.load_extension(f"cogs.{extension}")
await ctx.send(f"Extension `{extension}` reloaded.")
else:
bot.load_extension(f"cogs.{extension}")
activecmd.append(extension)
await ctx.send(f"Extension `{extension}` loaded.")
@bot.command()
async def unload(ctx, extension=""):
if await bot.is_owner(ctx.author):
global activecmd
count = len(activecmd)
if count < 1:
await ctx.send(f"There is nothing to unload!")
return
if extension == "all":
for filename in activecmd:
try:
bot.unload_extension(f"cogs.{filename}")
except:
print(
f"EXCEPTION : Extension {filename} not even loaded yet to unload"
)
activecmd = []
await ctx.send(f"{count} extensions unloaded.")
elif extension not in activecmd:
await ctx.send(
"I don't see that extension loaded yet, all active extensions are: "
)
for e in activecmd:
await ctx.send(f"`{e}\n`")
else:
bot.unload_extension(f"cogs.{extension}")
activecmd.remove(extension)
await ctx.send(f"Extension `{extension}` unloaded.")
@bot.command()
async def reload(ctx, extension=""):
if await bot.is_owner(ctx.author):
if extension == "all":
for filename in activecmd:
try:
bot.unload_extension(f"cogs.{filename}")
except:
print(
f"EXCEPTION : Extension {filename} not even loaded yet to unload"
)
bot.load_extension(f"cogs.{filename}")
await ctx.send(f"{len(activecmd)} extensions reloaded.")
elif extension not in activecmd:
await ctx.send(
"I don't see that extension loaded yet, all active extensions are: "
)
for e in activecmd:
await ctx.send(f"```{e}\n```")
else:
bot.unload_extension(f"cogs.{extension}")
bot.load_extension(f"cogs.{extension}")
await ctx.send(f"Extension `{extension}` reloaded.")
# def check(author):
# def inner_check(message):
# return message.author == author
# return inner_check
# # Error handling
# @bot.event
# async def on_error(ctx, error):
# if isinstance(error, commands.MissingPermissions):
# await ctx.send('Missing permisions ..')
# elif isinstance(error, commands.MissingRole):
# await ctx.send('Missing roles ..')
if __name__ == "__main__":
bot.run(os.getenv("DISCORD_TOKEN"))