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:
Will Tekulve 2016-04-14 01:12:13 -04:00
parent 08c861ef02
commit f03b44d57a

View File

@ -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,10 +107,10 @@ 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):
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):]
args = message.content[len(prefix + alias):]
message.content = prefix + new_command + args
await self.bot.process_commands(message)
@ -114,20 +119,20 @@ class 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):