diff --git a/geoffrey/BotConfig.py b/geoffrey/BotConfig.py index 647b175..f65cda9 100644 --- a/geoffrey/BotConfig.py +++ b/geoffrey/BotConfig.py @@ -78,4 +78,3 @@ class Config: def get_config(config_path): return Config(config_path) - diff --git a/geoffrey/DatabaseInterface.py b/geoffrey/DatabaseInterface.py index 2fdc42a..553ec13 100644 --- a/geoffrey/DatabaseInterface.py +++ b/geoffrey/DatabaseInterface.py @@ -4,7 +4,7 @@ from geoffrey.DatabaseModels import * class DatabaseInterface: def __init__(self, bot_config, debug=False): - self.database = GeoffreyDatabase(bot_config, debug) + self.database = GeoffreyDatabase(bot_config, debug) def add_base(self, session, owner, name, x_pos, z_pos, dimension=None): base = Base(name, x_pos, z_pos, owner, dimension) @@ -93,7 +93,8 @@ class DatabaseInterface: def find_location_around(self, session, x_pos, z_pos, radius, dimension): dimension_obj = Dimension.str_to_dimension(dimension) - expr = (Location.x < x_pos + radius + 1) & (Location.x > x_pos - radius - 1) & (Location.z < z_pos + radius + 1) \ + expr = (Location.x < x_pos + radius + 1) & (Location.x > x_pos - radius - 1) & \ + (Location.z < z_pos + radius + 1) \ & (Location.z > z_pos - radius - 1) & (Location.dimension == dimension_obj) return list_to_string(self.database.query_by_filter(session, Location, expr)) diff --git a/geoffrey/DatabaseModels.py b/geoffrey/DatabaseModels.py index 4efa9e6..6d00f73 100644 --- a/geoffrey/DatabaseModels.py +++ b/geoffrey/DatabaseModels.py @@ -59,7 +59,7 @@ class GeoffreyDatabase: filter_value = self.combine_filter(args) return session.query(obj_type).filter(filter_value).limit(limit).all() - def delete_entry(self, session, obj_type, * args): + def delete_entry(self, session, obj_type, *args): filter_value = self.combine_filter(args) entry = session.query(obj_type).filter(filter_value) @@ -77,7 +77,7 @@ class GeoffreyDatabase: s = '' for obj in obj_list: - s = s + '\n' + obj.id + s = s + '\n' + obj.id return s def combine_filter(self, filter_value): @@ -90,7 +90,6 @@ class TunnelDirection(enum.Enum): South = "south" West = "west" - def str_to_tunnel_dir(arg): arg = arg.lower() @@ -181,7 +180,7 @@ class Location(SQL_Base): x = Column(Integer) z = Column(Integer) - tunnel = relationship("Tunnel", uselist=False, cascade="all, delete-orphan") + tunnel = relationship("Tunnel", uselist=False, cascade="all, delete-orphan") dimension = Column(Enum(Dimension)) owner_id = Column(Integer, ForeignKey('geoffrey_players.id', ondelete='CASCADE')) @@ -210,7 +209,7 @@ class Location(SQL_Base): raise LocationInitError def dynmap_link(self, bot_config): - return '<{}/?worldname={}&mapname=surface&zoom=4&x={}&y=65&z={}>'.\ + return '<{}/?worldname={}&mapname=surface&zoom=4&x={}&y=65&z={}>'. \ format(bot_config.dynmap_url, bot_config.world_name, self.x, self.z) def pos_to_str(self): @@ -222,7 +221,7 @@ class Location(SQL_Base): def info_str(self): return "**{}** @ {}, Owner: **{}**, Type: **{}**".format(self.name, self.pos_to_str(), self.owner.name, - self.type) + self.type) def full_str(self, bot_config): return self.__str__() + '\n' + self.dynmap_link(bot_config) @@ -294,4 +293,4 @@ class ItemListing(SQL_Base): return '**{}** **{}** for **{}D**'.format(self.amount, self.name, self.price) def __str__(self): - return '**{}**, selling {}'.format(self.shop.name, self.listing_str()) \ No newline at end of file + return '**{}**, selling {}'.format(self.shop.name, self.listing_str()) diff --git a/geoffrey/DiscordHelperFunctions.py b/geoffrey/DiscordHelperFunctions.py index b9f161e..d13883e 100644 --- a/geoffrey/DiscordHelperFunctions.py +++ b/geoffrey/DiscordHelperFunctions.py @@ -10,14 +10,14 @@ def get_name(args): return name -def get_nickname(discord_user, bot_config): +def get_nickname(discord_user, special_users): if discord_user.nick is None: name = discord_user.display_name else: name = discord_user.nick - if name in bot_config.special_name_list: - return bot_config.special_name_list[name] + if name in special_users: + return special_users[name] else: return name diff --git a/geoffrey/bot.py b/geoffrey/bot.py index 6e376bb..6939faf 100644 --- a/geoffrey/bot.py +++ b/geoffrey/bot.py @@ -43,6 +43,7 @@ class GeoffreyBot(commands.Bot): super().__init__(command_prefix=config.prefix, description=description, pm_help=True, case_insensitive=True) self.error_users = config.error_users self.admin_users = config.bot_mod + self.special_users = config.special_name_list self.bot_commands = Commands(config) for extension in extensions: @@ -109,9 +110,8 @@ class GeoffreyBot(commands.Bot): logger.error("Geoffrey encountered unhandled exception: %s", error) error_str = bad_error_message.format(ctx.invoked_with) - await self.send_message(ctx.message.channel, - '{} **Error Running Command:** {}'.format(ctx.message.author.mention, - error_str)) + await self.send_message(ctx.message.channel, '{} **Error Running Command:** {}'.format( + ctx.message.author.mention, error_str)) async def send_error_message(self, msg): for user_id in self.error_users: @@ -170,6 +170,7 @@ def setup_logging(config): def start_bot(config_path="{}/GeoffreyConfig.ini".format(path.dirname(path.abspath(__file__)))): + bot = None try: bot_config = get_config(config_path) @@ -185,5 +186,6 @@ def start_bot(config_path="{}/GeoffreyConfig.ini".format(path.dirname(path.abspa except Exception as e: logger.info('Bot encountered the following unhandled exception %s', e) finally: - bot.loop.stop() + if bot is not None: + bot.loop.stop() logger.info("Bot shutting down...") diff --git a/geoffrey/cogs/Add_Commands.py b/geoffrey/cogs/Add_Commands.py index c2a5dce..c155473 100644 --- a/geoffrey/cogs/Add_Commands.py +++ b/geoffrey/cogs/Add_Commands.py @@ -23,7 +23,7 @@ class Add_Commands: """ try: - player_name = get_nickname(ctx.message.author, bot_config) + player_name = get_nickname(ctx.message.author, self.bot.special_users) self.bot.bot_commands.register(player_name, ctx.message.author.id) await self.bot.say('{}, you have been added to the database.'.format(ctx.message.author.mention)) except AttributeError: diff --git a/geoffrey/cogs/Edit_Commands.py b/geoffrey/cogs/Edit_Commands.py index d819644..757767d 100644 --- a/geoffrey/cogs/Edit_Commands.py +++ b/geoffrey/cogs/Edit_Commands.py @@ -37,7 +37,8 @@ class Edit_Commands: """ loc = get_name(args) try: - loc_str = self.bot.bot_commands.edit_tunnel(tunnel_color, tunnel_number, loc, discord_uuid=ctx.message.author.id) + loc_str = self.bot.bot_commands.edit_tunnel(tunnel_color, tunnel_number, loc, + discord_uuid=ctx.message.author.id) await self.bot.say( '{}, the following location has been updated: \n\n{}'.format(ctx.message.author.mention, loc_str))