Skip to content

Commit c97e9b4

Browse files
committed
enhance output
1 parent 2edb6d9 commit c97e9b4

File tree

1 file changed

+75
-16
lines changed

1 file changed

+75
-16
lines changed

redbot/core/core_commands.py

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,7 @@ async def slash_enablecog(self, ctx: commands.Context, *cog_names: str):
21032103
to_add_user = []
21042104

21052105
successful_cogs = set()
2106+
force_cogs = set()
21062107
# Fetch a list of command names to enable
21072108
for name, com in self.bot.tree._disabled_global_commands.items():
21082109
if com.extras.get("red_force_enable", False):
@@ -2124,18 +2125,42 @@ async def slash_enablecog(self, ctx: commands.Context, *cog_names: str):
21242125
elif com_type is discord.AppCommandType.user:
21252126
to_add_user.append(name)
21262127
successful_cogs.add(cog_name)
2127-
failed_cogs = set(cog_names) - successful_cogs
2128+
# Detect commands skipped because they are force-enabled
2129+
force_commands = []
2130+
for name, com in self.bot.tree._global_commands.items():
2131+
if com.extras.get("red_force_enable", False):
2132+
for cog_name in cog_names:
2133+
if self._is_submodule(cog_name, com.module):
2134+
force_cogs.add(cog_name)
2135+
force_commands.append(name)
2136+
for key, com in self.bot.tree._context_menus.items():
2137+
if com.extras.get("red_force_enable", False):
2138+
for cog_name in cog_names:
2139+
if self._is_submodule(cog_name, com.module):
2140+
name, guild_id, com_type = key
2141+
force_cogs.add(cog_name)
2142+
force_commands.append(name)
2143+
failed_cogs = set(cog_names) - successful_cogs - force_cogs
21282144

21292145
# Check that we are going to enable at least one command, for user feedback
21302146
if not (to_add_slash or to_add_message or to_add_user):
2131-
await ctx.send(
2132-
_(
2133-
"Couldn't find any disabled commands from {cog_names}. Use `{prefix}slash list` to see all cogs with application commands"
2134-
).format(
2135-
cog_names=humanize_list([inline(name) for name in failed_cogs]),
2136-
prefix=ctx.clean_prefix,
2147+
if force_commands:
2148+
await ctx.send(
2149+
_(
2150+
"The following commands have been set as required for the cog "
2151+
"to function by the author, and cannot be enabled or disabled: "
2152+
"{commands}. The cog must be unloaded to remove them."
2153+
).format(commands=humanize_list([inline(n) for n in force_commands]))
2154+
)
2155+
else:
2156+
await ctx.send(
2157+
_(
2158+
"Couldn't find any disabled commands from {cog_names}. Use `{prefix}slash list` to see all cogs with application commands"
2159+
).format(
2160+
cog_names=humanize_list([inline(name) for name in failed_cogs]),
2161+
prefix=ctx.clean_prefix,
2162+
)
21372163
)
2138-
)
21392164
return
21402165

21412166
SLASH_CAP = 100
@@ -2203,6 +2228,13 @@ async def slash_enablecog(self, ctx: commands.Context, *cog_names: str):
22032228
cog_names=humanize_list([inline(name) for name in failed_cogs]),
22042229
prefix=ctx.clean_prefix,
22052230
)
2231+
if force_commands:
2232+
output += "\n\n"
2233+
output += _(
2234+
"The following commands have been set as required for the cog "
2235+
"to function by the author, and cannot be enabled or disabled: "
2236+
"{commands}. The cog must be unloaded to remove them."
2237+
).format(commands=humanize_list([inline(n) for n in force_commands]))
22062238
for page in pagify(output):
22072239
await ctx.send(page)
22082240

@@ -2219,8 +2251,14 @@ async def slash_disablecog(self, ctx: commands.Context, *cog_names: str):
22192251
"""
22202252
removed = []
22212253
removed_cogs = set()
2254+
force_cogs = set()
2255+
force_commands = []
22222256
for name, com in self.bot.tree._global_commands.items():
22232257
if com.extras.get("red_force_enable", False):
2258+
for cog_name in cog_names:
2259+
if self._is_submodule(cog_name, com.module):
2260+
force_cogs.add(cog_name)
2261+
force_commands.append(name)
22242262
continue
22252263
for cog_name in cog_names:
22262264
if self._is_submodule(cog_name, com.module):
@@ -2229,24 +2267,38 @@ async def slash_disablecog(self, ctx: commands.Context, *cog_names: str):
22292267
removed_cogs.add(cog_name)
22302268
for key, com in self.bot.tree._context_menus.items():
22312269
if com.extras.get("red_force_enable", False):
2270+
for cog_name in cog_names:
2271+
if self._is_submodule(cog_name, com.module):
2272+
name, guild_id, com_type = key
2273+
force_cogs.add(cog_name)
2274+
force_commands.append(name)
22322275
continue
22332276
for cog_name in cog_names:
22342277
if self._is_submodule(cog_name, com.module):
22352278
name, guild_id, com_type = key
22362279
await self.bot.disable_app_command(name, discord.AppCommandType(com_type))
22372280
removed.append(name)
22382281
removed_cogs.add(cog_name)
2239-
failed_cogs = set(cog_names) - removed_cogs
2282+
failed_cogs = set(cog_names) - removed_cogs - force_cogs
22402283

22412284
if not removed:
2242-
await ctx.send(
2243-
_(
2244-
"Couldn't find any enabled commands from {cog_names}. Use `{prefix}slash list` to see all cogs with application commands."
2245-
).format(
2246-
cog_names=humanize_list([inline(name) for name in failed_cogs]),
2247-
prefix=ctx.clean_prefix,
2285+
if force_commands:
2286+
await ctx.send(
2287+
_(
2288+
"The following commands have been set as required for the cog "
2289+
"to function by the author, and cannot be disabled: "
2290+
"{commands}. The cog must be unloaded to remove them."
2291+
).format(commands=humanize_list([inline(n) for n in force_commands]))
2292+
)
2293+
else:
2294+
await ctx.send(
2295+
_(
2296+
"Couldn't find any enabled commands from {cog_names}. Use `{prefix}slash list` to see all cogs with application commands."
2297+
).format(
2298+
cog_names=humanize_list([inline(name) for name in failed_cogs]),
2299+
prefix=ctx.clean_prefix,
2300+
)
22482301
)
2249-
)
22502302
return
22512303

22522304
await self.bot.tree.red_check_enabled()
@@ -2266,6 +2318,13 @@ async def slash_disablecog(self, ctx: commands.Context, *cog_names: str):
22662318
cog_names=humanize_list([inline(name) for name in failed_cogs]),
22672319
prefix=ctx.clean_prefix,
22682320
)
2321+
if force_commands:
2322+
output += "\n\n"
2323+
output += _(
2324+
"The following commands have been set as required for the cog "
2325+
"to function by the author, and cannot be disabled: "
2326+
"{commands}. The cog must be unloaded to remove them."
2327+
).format(commands=humanize_list([inline(n) for n in force_commands]))
22692328
for page in pagify(output):
22702329
await ctx.send(page)
22712330

0 commit comments

Comments
 (0)