mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 03:38:53 -05:00
Stop doing multi word, more hassle than it's worth and its pretty much
indeterminant. Added better recognition and delete all old multi
word aliases
This commit is contained in:
parent
08c861ef02
commit
f03b44d57a
@ -24,6 +24,11 @@ class Alias:
|
||||
|
||||
Example: !alias add test flip @Twentysix"""
|
||||
server = ctx.message.server
|
||||
if len(command.split(" ")) != 1:
|
||||
await self.bot.say("I can't safely do multi-word aliases because"
|
||||
" of the fact that I allow arguments to"
|
||||
" aliases. It sucks, I know, deal with it.")
|
||||
return
|
||||
if self.part_of_existing_command(command, server.id):
|
||||
await self.bot.say('I can\'t safely add an alias that starts with '
|
||||
'an existing command or alias. Sry <3')
|
||||
@ -102,32 +107,32 @@ class Alias:
|
||||
prefix = self.get_prefix(msg)
|
||||
|
||||
if prefix and server.id in self.aliases:
|
||||
for alias in self.aliases[server.id]:
|
||||
if msg[len(prefix):].startswith(alias):
|
||||
new_command = self.aliases[server.id][alias]
|
||||
args = message.content[len(prefix+alias):]
|
||||
message.content = prefix + new_command + args
|
||||
await self.bot.process_commands(message)
|
||||
if self.first_word(msg[len(prefix):]) in self.aliases[server.id]:
|
||||
alias = self.first_word(msg[len(prefix):])
|
||||
new_command = self.aliases[server.id][alias]
|
||||
args = message.content[len(prefix + alias):]
|
||||
message.content = prefix + new_command + args
|
||||
await self.bot.process_commands(message)
|
||||
|
||||
def part_of_existing_command(self, alias, server):
|
||||
'''Command or alias'''
|
||||
for command in self.bot.commands:
|
||||
if alias.lower() == command:
|
||||
return True
|
||||
if server not in self.aliases:
|
||||
return False
|
||||
for curr_alias in self.aliases[server]:
|
||||
if alias.split(" ")[0] == curr_alias \
|
||||
and alias != curr_alias:
|
||||
return True
|
||||
return False
|
||||
|
||||
def remove_old(self):
|
||||
for sid in self.aliases:
|
||||
to_delete = []
|
||||
for aliasname, alias in self.aliases[sid].items():
|
||||
if aliasname != self.first_word(aliasname):
|
||||
to_delete.append(aliasname)
|
||||
continue
|
||||
prefix = self.get_prefix(alias)
|
||||
if prefix is not None:
|
||||
self.aliases[sid][aliasname] = alias[len(prefix):]
|
||||
for alias in to_delete:
|
||||
del self.aliases[sid][alias]
|
||||
fileIO("data/alias/aliases.json", "save", self.aliases)
|
||||
|
||||
def first_word(self, msg):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user