feat(commands|Custom>alias): finish alias interpretation
This commit is contained in:
parent
1681c5abf5
commit
f00f0fd4c0
7 changed files with 63 additions and 44 deletions
|
@ -61,7 +61,7 @@ two commands:
|
|||
$ make install
|
||||
|
||||
Now, switch your environment to the virtual one by run this single
|
||||
command: :bash:`source ~/tuxvenv/bin/activate`
|
||||
command: :bash:`source ~/venv/bin/activate`
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
|
|
@ -99,21 +99,6 @@ class Custom(commands.Cog, name="Custom"):
|
|||
).format(alias=alias, command=user_aliases.get(alias))
|
||||
)
|
||||
|
||||
if command in user_aliases.values():
|
||||
return await ctx.send(
|
||||
_(
|
||||
"There is already an alias for `{command}` "
|
||||
"which is `{alias}`",
|
||||
ctx,
|
||||
self.bot.config,
|
||||
).format(
|
||||
command=command,
|
||||
alias=list(user_aliases.keys())[
|
||||
list(user_aliases.values()).index(command)
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
user_aliases[alias] = command
|
||||
|
||||
await self._save_alias(ctx, user_aliases)
|
||||
|
|
|
@ -22,7 +22,7 @@ class AliasConvertor(commands.Converter):
|
|||
if command_ctx.command is None:
|
||||
raise commands.BadArgument(_("Unknown command"))
|
||||
|
||||
if alias_ctx.command is not None:
|
||||
if args[0] != args[1] and alias_ctx.command is not None:
|
||||
raise commands.BadArgument(_("Command already exists"))
|
||||
|
||||
return argument
|
||||
|
|
|
@ -17,11 +17,35 @@ msgstr ""
|
|||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
#: tuxbot/cogs/Admin/admin.py:50
|
||||
#: tuxbot/cogs/Custom/custom.py:69
|
||||
#, python-brace-format
|
||||
msgid "Locale changed to {lang} successfully"
|
||||
msgid "Locale changed for you to {lang} successfully"
|
||||
msgstr ""
|
||||
|
||||
#: tuxbot/cogs/Admin/admin.py:65
|
||||
#: tuxbot/cogs/Custom/custom.py:76
|
||||
msgid "List of available locales: "
|
||||
msgstr ""
|
||||
|
||||
#: tuxbot/cogs/Custom/custom.py:95
|
||||
#, python-brace-format
|
||||
msgid "The alias `{alias}` is already defined for the command `{command}`"
|
||||
msgstr ""
|
||||
|
||||
#: tuxbot/cogs/Custom/custom.py:123
|
||||
#, python-brace-format
|
||||
msgid "The alias `{alias}` for the command `{command}` was successfully created"
|
||||
msgstr ""
|
||||
|
||||
#: tuxbot/cogs/Custom/functions/converters.py:14
|
||||
msgid "Alias must be like `[command] | [alias]`"
|
||||
msgstr ""
|
||||
|
||||
#: tuxbot/cogs/Custom/functions/converters.py:23
|
||||
#, python-brace-format
|
||||
msgid "Unknown command"
|
||||
msgstr ""
|
||||
|
||||
#: tuxbot/cogs/Custom/functions/converters.py:26
|
||||
#, python-brace-format
|
||||
msgid "Command already exists"
|
||||
msgstr ""
|
||||
|
|
|
@ -32,11 +32,6 @@ msgstr "Liste des langues disponibles: "
|
|||
msgid "The alias `{alias}` is already defined for the command `{command}`"
|
||||
msgstr "L'alias `{alias}` est déjà défini pour la commande `{command}`"
|
||||
|
||||
#: tuxbot/cogs/Custom/custom.py:105
|
||||
#, python-brace-format
|
||||
msgid "There is already an alias for `{command}` which is `{alias}`"
|
||||
msgstr "Il existe déjà un alias pour `{command}`, qui est `{alias}`"
|
||||
|
||||
#: tuxbot/cogs/Custom/custom.py:123
|
||||
#, python-brace-format
|
||||
msgid "The alias `{alias}` for the command `{command}` was successfully created"
|
||||
|
|
|
@ -31,11 +31,6 @@ msgstr ""
|
|||
msgid "The alias `{alias}` is already defined for the command `{command}`"
|
||||
msgstr ""
|
||||
|
||||
#: tuxbot/cogs/Custom/custom.py:105
|
||||
#, python-brace-format
|
||||
msgid "There is already an alias for `{command}` which is `{alias}`"
|
||||
msgstr ""
|
||||
|
||||
#: tuxbot/cogs/Custom/custom.py:123
|
||||
#, python-brace-format
|
||||
msgid "The alias `{alias}` for the command `{command}` was successfully created"
|
||||
|
|
|
@ -104,6 +104,22 @@ class Tux(commands.AutoShardedBot):
|
|||
)
|
||||
self.session = aiohttp.ClientSession(loop=self.loop)
|
||||
|
||||
async def _is_blacklister(self, message: discord.Message) -> bool:
|
||||
"""Check for blacklists."""
|
||||
if message.author.bot:
|
||||
return True
|
||||
|
||||
if (
|
||||
search_for(self.config.Servers, message.guild.id, "blacklisted")
|
||||
or search_for(
|
||||
self.config.Channels, message.channel.id, "blacklisted"
|
||||
)
|
||||
or search_for(self.config.Users, message.author.id, "blacklisted")
|
||||
):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
async def load_packages(self):
|
||||
if packages:
|
||||
with Progress() as progress:
|
||||
|
@ -216,24 +232,28 @@ class Tux(commands.AutoShardedBot):
|
|||
return await super().get_context(message, cls=ContextPlus)
|
||||
|
||||
async def process_commands(self, message: discord.Message):
|
||||
"""Check for blacklists."""
|
||||
if message.author.bot:
|
||||
return
|
||||
|
||||
if (
|
||||
search_for(self.config.Servers, message.guild.id, "blacklisted")
|
||||
or search_for(
|
||||
self.config.Channels, message.channel.id, "blacklisted"
|
||||
)
|
||||
or search_for(self.config.Users, message.author.id, "blacklisted")
|
||||
):
|
||||
return
|
||||
|
||||
ctx: ContextPlus = await self.get_context(message)
|
||||
|
||||
if ctx is None or not ctx.valid:
|
||||
self.dispatch("message_without_command", message)
|
||||
if user_aliases := search_for(
|
||||
self.config.Users, message.author.id, "aliases"
|
||||
):
|
||||
for alias, command in user_aliases.items():
|
||||
back_content = message.content
|
||||
message.content = message.content.replace(
|
||||
alias, command, 1
|
||||
)
|
||||
|
||||
if (
|
||||
ctx := await self.get_context(message)
|
||||
) is None or not ctx.valid:
|
||||
message.content = back_content
|
||||
else:
|
||||
break
|
||||
|
||||
self.dispatch("message_without_command", message)
|
||||
|
||||
if ctx is not None and ctx.valid:
|
||||
if ctx.command in search_for(
|
||||
self.config.Servers, message.guild.id, "disabled_command", []
|
||||
):
|
||||
|
|
Loading…
Reference in a new issue