-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
146 lines (112 loc) · 4.03 KB
/
main.py
File metadata and controls
146 lines (112 loc) · 4.03 KB
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
import fluxer
import yaml
import os
import argparse
import err
def load_config():
with open("config.yaml") as cfg:
container = yaml.safe_load(cfg)
return container
config = load_config()
bot = fluxer.Bot(command_prefix=config["prefix"], intents=fluxer.Intents.default())
@bot.command()
async def load(ctx, cog: str = None):
try:
if not ctx.author.id == config["owner"]:
raise err.InsufficientPermissions
cog_list = [
f"{folder}.{cog.replace('.py', '')}"
for folder in config["plugin_folders"]
for cog in os.listdir(folder)
if "pycache" not in cog
]
if not cog:
await ctx.reply(f"Available cogs: `{', '.join(cog_list)}`")
return
if cog not in cog_list:
raise err.InvalidCog
await bot.load_extension(cog)
await ctx.reply(f"`{cog}` loaded.")
except err.InsufficientPermissions:
await ctx.reply("You have insufficient permissions to run this command.")
except err.InvalidCog:
await ctx.reply(
f"This is not a valid cog.\nAvailable cogs: `{', '.join(cog_list)}`"
)
@bot.command()
async def unload(ctx, cog: str = None):
try:
if not ctx.author.id == config["owner"]:
raise err.InsufficientPermissions
cog_list = [
f"{folder}.{cog.replace('.py', '')}"
for folder in config["plugin_folders"]
for cog in os.listdir(folder)
if "pycache" not in cog
]
if not cog:
await ctx.reply(f"Available cogs: `{', '.join(cog_list)}`")
return
if cog not in cog_list:
raise err.InvalidCog
await bot.unload_extension(cog)
await ctx.reply(f"`{cog}` unloaded.")
except err.InsufficientPermissions:
await ctx.reply("You have insufficient permissions to run this command.")
except err.InvalidCog:
await ctx.reply(
f"This is not a valid cog.\nAvailable cogs: `{', '.join(cog_list)}`"
)
@bot.command()
async def reload(ctx, cog: str = None):
try:
if not ctx.author.id == config["owner"]:
raise err.InsufficientPermissions
cog_list = [
f"{folder}.{cog.replace('.py', '')}"
for folder in config["plugin_folders"]
for cog in os.listdir(folder)
if "pycache" not in cog
]
if not cog:
await ctx.reply(f"Available cogs: `{', '.join(cog_list)}`")
return
if cog not in cog_list:
raise err.InvalidCog
await bot.reload_extension(cog)
await ctx.reply(f"`{cog}` reloaded.")
except err.InsufficientPermissions:
await ctx.reply("You have insufficient permissions to run this command.")
except err.InvalidCog:
await ctx.reply(
f"This is not a valid cog.\nAvailable cogs: `{', '.join(cog_list)}`"
)
@bot.event
async def on_ready():
for folder in config["plugin_folders"]:
for cog in os.listdir(folder):
if "pycache" not in cog:
await bot.load_extension(f"{folder}.{cog.replace('.py', '')}")
print(f"Jerbot is ready to rumble!\nLogged in as {bot.user.username}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Jerbot - A modular bot for Fluxer",
)
parser.add_argument(
"-t",
"--token",
default="default",
help="Name of a token to use for this instance of the bot. Define this in config.yaml",
)
args = parser.parse_args()
bot.run(config["token"])
def load_plugin_config(plugin: str):
plugin_config = {}
for config_file in os.listdir("server_configs"):
if "sample.yaml" not in config_file:
with open(f"server_configs/{config_file}") as cfg:
server_id = int(config_file.split(".")[0])
config = yaml.safe_load(cfg)
if plugin in config:
plugin_config[server_id] = config[plugin]
return plugin_config