Jason R. Coombs avatar Jason R. Coombs committed dc6352e

Allow commands to remember their aliases

Comments (0)

Files changed (2)

pmxbot/commands.py

 		def mk_entries():
 			for handler in sorted(_handler_registry,
 					key=operator.attrgetter('name')):
-				if handler.type_ == 'command':
-					aliases = sorted(
-						x.name
-						for x in _handler_registry
-						if x.type_ == 'alias' and x.func == handler.func
-					)
-					res = "!%s" % handler.name
-					if aliases:
-						res += " (%s)" % ', '.join(aliases)
-					yield res
+				if handler.type_ != 'command':
+					continue
+				res = "!%s" % handler.name
+				if handler.aliases:
+					res += " (%s)" % ', '.join(
+						alias.name for alias in handler.aliases)
+				yield res
 		o = io.StringIO(u" ".join(mk_entries()))
 		more = o.read(160)
 		while more:
 
 def command(name, aliases=[], doc=None):
 	def deco(func):
-		_handler_registry.append(CommandHandler(
+		ch = CommandHandler(
 			name=name.lower(),
 			func=func,
-			doc=doc))
-		for a in aliases:
-			_handler_registry.append(AliasHandler(
-				name=a,
+			doc=doc,
+			aliases=[],
+		)
+		_handler_registry.append(ch)
+		for alias in aliases:
+			ah = AliasHandler(
+				name=alias,
 				func=func,
-				doc=doc))
+				doc=doc)
+			ch.aliases.append(ah)
+			_handler_registry.append(ah)
+
 		_handler_registry.sort()
 		return func
 	return deco
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.