From c7edbf0f2c4c31e499a610ca89be283700ca14b4 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Wed, 27 Aug 2014 08:56:03 +0100 Subject: [PATCH] Expanded the help command. --- dropbot/bot.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/dropbot/bot.py b/dropbot/bot.py index e9943b7..a566d9a 100644 --- a/dropbot/bot.py +++ b/dropbot/bot.py @@ -173,11 +173,26 @@ class DropBot(ClientXMPP): # Commands def cmd_help(self, args, msg): - return "Commands: {}".format( - ', '.join([self.cmd_prefix + x[4:] for x in dir(self) if x[:4] == 'cmd_' and x not in self.hidden_commands]), - ) + if len(args) == 0: + return "Commands: {}".format( + ', '.join([self.cmd_prefix + x[4:] for x in dir(self) if x[:4] == 'cmd_' and x not in self.hidden_commands]), + ) + cmd = args[0] + if hasattr(self, 'cmd_%s' % cmd): + if getattr(self, 'cmd_%s' % cmd).__doc__ is not None: + return '{}{}: {}'.format( + self.cmd_prefix, + cmd, + getattr(self, 'cmd_%s' % cmd).__doc__ + ) + else: + return 'This command has no documentation' + else: + return 'Unknown command' + def cmd_bestprice(self, args, msg): + """Returns the best price for an item out of the current known market hub systems""" item = ' '.join(args) res = self._item_picker(item) if isinstance(res, basestring): @@ -204,6 +219,7 @@ class DropBot(ClientXMPP): ) def cmd_price(self, args, msg): + """Returns the price of an item in a particular system""" if len(args) < 2: return '!price ' item = ' '.join(args[1:]) @@ -258,6 +274,7 @@ class DropBot(ClientXMPP): return choice(imgs) def cmd_kos(self, args, msg): + """Checks the CVA KOS list for a name""" arg = ' '.join(args) resp = requests.get(self.kos_url, params={ 'c': 'json', @@ -287,6 +304,7 @@ class DropBot(ClientXMPP): return '\n'.join(results) def cmd_range(self, args, msg): + """Returns a count of the number of systems in jump range from a source system""" if len(args) == 0 or len(args) > 2: return '!range ' @@ -317,6 +335,7 @@ class DropBot(ClientXMPP): return '{} systems in JDC5 {} range of {}:\n'.format(len(systems), ship_class, self.map.get_system_name(system_id)) + '\n'.join(['{} - {}'.format(x, y) for x, y in res.items()]) def cmd_route(self, args, msg): + """Shows the shortest route between two sytems""" if len(args) != 2: return '!route ' source, dest = args @@ -339,6 +358,7 @@ class DropBot(ClientXMPP): ) def cmd_addjb(self, args, msg): + """Adds a jumpbridge to the internal map for routing purposes""" if len(args) != 2: return '!addjb ' source, dest = args @@ -354,6 +374,7 @@ class DropBot(ClientXMPP): return "Done" def cmd_mapstats(self, args, msg): + """Gives the current overview of the internal map""" return '{} systems, {} gate jumps, {} jump bridges'.format( len(self.map.nodes()), len([u for u, v, d in self.map.edges_iter(data=True) if d['link_type'] == 'gate']), @@ -361,6 +382,7 @@ class DropBot(ClientXMPP): ) def cmd_hit(self, args, msg): + """Details what class and JDC level is required to jump between two systems""" if len(args) != 2: return '!hit ' source, dest = args @@ -401,6 +423,7 @@ class DropBot(ClientXMPP): ) def cmd_jump(self, args, msg): + """Calculates the shortest jump route between two systems""" if len(args) < 2: return '!jump ( )' elif len(args) == 2: @@ -453,6 +476,7 @@ class DropBot(ClientXMPP): return 'No route found' def cmd_id(self, args, msg): + """Provides an overview of a character's activity in-game""" if len(args) == 0: return '!id ' char_name = ' '.join(args)