-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbot.py
80 lines (61 loc) · 2.34 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
# coding: utf-8
"""
GitBot - the developer toolkit for Discord
~~~~~~~~~~~~~~~~~~~
A developer toolkit for the Discord era, with a focus on sleek design and powerful features.
:copyright: (c) 2020-present statch
:license: CC BY-NC-ND 4.0, see LICENSE for more details.
"""
import discord
from os import getenv
from dotenv import load_dotenv
from discord.ext import commands
from lib.structs.discord.context import GitBotContext
from lib.structs.discord.bot import GitBot
# all the configuration is handled inside the class, there is no real need to pass anything here
bot = GitBot()
async def do_cog_op(ctx: GitBotContext, cog: str, op: str) -> None:
if (cog := cog.lower()) == 'all':
done: int = 0
try:
for ext in bot.extensions:
getattr(bot, f'{op}_extension')(str(ext))
done += 1
except commands.ExtensionError as e:
await ctx.error(f'**Exception during batch-{op}ing:**\n```{e}```')
else:
await ctx.success(f'All extensions **successfully {op}ed.** ({done})')
else:
try:
getattr(bot, f'{op}_extension')(cog)
except commands.ExtensionError as e:
await ctx.error(f'**Exception while {op}ing** `{cog}`**:**\n```{e}```')
else:
await ctx.success(f'**Successfully {op}ed** `{cog}`.')
@bot.command(name='reload', hidden=True)
@commands.is_owner()
async def reload_command(ctx: GitBotContext, cog: str) -> None:
await do_cog_op(ctx, cog, 'reload')
@bot.command(name='load', hidden=True)
@commands.is_owner()
async def load_command(ctx: GitBotContext, cog: str) -> None:
await do_cog_op(ctx, cog, 'load')
@bot.command(name='unload', hidden=True)
@commands.is_owner()
async def unload_command(ctx: GitBotContext, cog: str) -> None:
await do_cog_op(ctx, cog, 'unload')
@bot.check
async def global_check(ctx: GitBotContext) -> bool:
if not isinstance(ctx.channel, discord.DMChannel) and ctx.guild.unavailable:
return False
if ctx.author.id in bot.user_id_blacklist:
return False
return True
@bot.before_invoke
async def before_invoke(ctx: GitBotContext):
if str(ctx.command) not in bot.mgr.env.no_typing_commands:
await ctx.channel.typing()
# ctx.gh overwrites will be handled here
if __name__ == '__main__':
load_dotenv()
bot.run(getenv('BOT_TOKEN'))