diff --git a/dropbot/bot.py b/dropbot/bot.py index 734a01d..06bc4b5 100644 --- a/dropbot/bot.py +++ b/dropbot/bot.py @@ -300,8 +300,37 @@ class DropBot(ClientXMPP): route_names = ' -> '.join(['{} ({})'.format(x['name'], round(x['security'], 2)) for x in [self.map.node[y] for y in route]]) return '{} jumps from {} to {}\n{}'.format( - len(route), + len(route)-1, self.map.get_system_name(source_system), self.map.get_system_name(dest_system), route_names - ) \ No newline at end of file + ) + + def cmd_addjb(self, args, msg): + if len(args) != 2: + return '!addjb ' + source, dest = args + + source_systems = self.map.get_systems(source) + dest_systems = self.map.get_systems(dest) + + if len(source_systems) > 1: + if len(source_systems) > 10: + return 'More than 10 systems match {}, please provide a more complete name'.format(source) + return 'Did you mean: {}?'.format(', '.join([self.map.get_system_name(x) for x in source_systems])) + elif len(source_systems) == 0: + return 'No systems found matching {}'.format(source) + else: + source_system = source_systems[0] + + if len(dest_systems) > 1: + if len(dest_systems) > 10: + return 'More than 10 systems match {}, please provide a more complete name'.format(source) + return 'Did you mean: {}?'.format(', '.join([self.map.get_system_name(x) for x in dest_systems])) + elif len(dest_systems) == 0: + return 'No systems found matching {}'.format(dest) + else: + dest_system = dest_systems[0] + + self.map.add_jumpbridge(source_system, dest_system) + return "Done" \ No newline at end of file diff --git a/dropbot/map.py b/dropbot/map.py index 64d0324..0a7cb05 100644 --- a/dropbot/map.py +++ b/dropbot/map.py @@ -86,7 +86,10 @@ class Map(networkx.Graph): for destination_data, destination_range in self.neighbors_jump(source_id, max_jump): if destination_data['security'] < 0.5: self.add_edge(source_id, destination_data['system_id'], weight=destination_range, link_type='jump') - + + def add_jumpbridge(self, source_id, destination_id): + self.add_edge(source_id, destination_id, weight=1, link_type='bridge') + def to_json(self): """Dump map data to a Node Link JSON output""" return dumps(node_link_data(self)) @@ -119,7 +122,7 @@ class Map(networkx.Graph): # TODO: add EVE routing options (highsec/lowsec/fastest) - g = networkx.Graph(data=[(u, v) for u, v, d in self.edges_iter(data=True) if d['link_type'] == 'gate']) + g = networkx.Graph(data=[(u, v) for u, v, d in self.edges_iter(data=True) if d['link_type'] == 'gate' or d['link_type'] == 'bridge']) return networkx.astar_path(self, source, destination) def route_jump(self, source, destination, range=None, hull=None, ship_class=None):