Utilize SlashCommand fields for validation
This commit is contained in:
parent
c260b93530
commit
334b578ae6
1 changed files with 11 additions and 6 deletions
|
@ -3,7 +3,6 @@ import asyncio
|
||||||
import logging
|
import logging
|
||||||
import platform
|
import platform
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from typing import get_type_hints
|
|
||||||
|
|
||||||
import git
|
import git
|
||||||
import psutil
|
import psutil
|
||||||
|
@ -115,17 +114,23 @@ class BotutilCog(Scale):
|
||||||
lambda x: x.resolved_name == command.resolved_name,
|
lambda x: x.resolved_name == command.resolved_name,
|
||||||
current_commands[module],
|
current_commands[module],
|
||||||
)
|
)
|
||||||
old_args = get_type_hints(old_command)
|
|
||||||
new_args = get_type_hints(command)
|
# Extract useful info
|
||||||
|
old_args = old_command.options
|
||||||
|
old_arg_names = [x.name for x in old_args]
|
||||||
|
new_args = command.options
|
||||||
|
new_arg_names = [x.name for x in new_args]
|
||||||
|
|
||||||
|
# Check if number arguments have changed
|
||||||
if len(old_args) != len(new_args):
|
if len(old_args) != len(new_args):
|
||||||
self.bot.reload_extension(module)
|
self.bot.reload_extension(module)
|
||||||
reloaded.append(module)
|
reloaded.append(module)
|
||||||
elif any(x not in old_args for x in new_args) or any(
|
elif any(x not in old_arg_names for x in new_arg_names) or any(
|
||||||
x not in new_args for x in old_args
|
x not in new_arg_names for x in old_arg_names
|
||||||
):
|
):
|
||||||
self.bot.reload_extension(module)
|
self.bot.reload_extension(module)
|
||||||
reloaded.append(module)
|
reloaded.append(module)
|
||||||
elif any(new_args[x] != y for x, y in old_args):
|
elif any(new_args[idx].type != x.type for idx, x in enumerate(old_args)):
|
||||||
self.bot.reload_extension(module)
|
self.bot.reload_extension(module)
|
||||||
reloaded.append(module)
|
reloaded.append(module)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue