-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcommandcontrol.py
More file actions
118 lines (96 loc) · 3.47 KB
/
commandcontrol.py
File metadata and controls
118 lines (96 loc) · 3.47 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
"""
Commands which allow control over what commands are allowed to be run
The cog in the file is named:
CommandControl
This file contains 2 commands:
.command disable
.command enable
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Self
from core import auxiliary, cogs
from discord.ext import commands
if TYPE_CHECKING:
import bot
async def setup(bot: bot.TechSupportBot) -> None:
"""Loading the Command Control plugin into the bot
Args:
bot (bot.TechSupportBot): The bot object to register the cogs to
"""
await bot.add_cog(CommandControl(bot=bot))
class CommandControl(cogs.BaseCog):
"""
The class that holds the command control commands
"""
@commands.check(auxiliary.bot_admin_check_context)
@commands.group(
name="command",
brief="Executes a commands bot command",
description="Executes a commands bot command",
)
async def command_group(self: Self, ctx: commands.Context) -> None:
"""The bare .command command. This does nothing but generate the help message
Args:
ctx (commands.Context): The context in which the command was run in
"""
return
@auxiliary.with_typing
@command_group.command(
name="enable", description="Enables a command by name", usage="[command-name]"
)
async def enable_command(
self: Self, ctx: commands.Context, *, command_name: str
) -> None:
"""Enables a command by name.
This is a command and should be accessed via Discord.
Args:
ctx (commands.Context): the context object for the message
command_name (str): the name of the command
"""
command_ = ctx.bot.get_command(command_name)
if not command_:
await auxiliary.send_deny_embed(
message=f"No such command: `{command_name}`", channel=ctx.channel
)
return
if command_.enabled:
await auxiliary.send_deny_embed(
message=f"Command `{command_name}` is already enabled!",
channel=ctx.channel,
)
return
command_.enabled = True
await auxiliary.send_confirm_embed(
message=f"Successfully enabled command: `{command_name}`",
channel=ctx.channel,
)
@auxiliary.with_typing
@command_group.command(
name="disable", description="Disables a command by name", usage="[command-name]"
)
async def disable_command(
self: Self, ctx: commands.Context, *, command_name: str
) -> None:
"""Disables a command by name.
This is a command and should be accessed via Discord.
Args:
ctx (commands.Context): the context object for the message
command_name (str): the name of the command
"""
command_ = ctx.bot.get_command(command_name)
if not command_:
await auxiliary.send_deny_embed(
message=f"No such command: `{command_name}`", channel=ctx.channel
)
return
if not command_.enabled:
await auxiliary.send_deny_embed(
message=f"Command: `{command_name}` is already disabled!",
channel=ctx.channel,
)
return
command_.enabled = False
await auxiliary.send_confirm_embed(
message=f"Successfully disabled command: `{command_name}`",
channel=ctx.channel,
)