fixed issue with ?register function. Also cleaned up code a bit

doc_update
Joey Hines 2018-08-30 11:46:20 -05:00
parent 6748f01208
commit 2111bf8c8e
7 changed files with 21 additions and 19 deletions

View File

@ -78,4 +78,3 @@ class Config:
def get_config(config_path): def get_config(config_path):
return Config(config_path) return Config(config_path)

View File

@ -93,7 +93,8 @@ class DatabaseInterface:
def find_location_around(self, session, x_pos, z_pos, radius, dimension): def find_location_around(self, session, x_pos, z_pos, radius, dimension):
dimension_obj = Dimension.str_to_dimension(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) & (Location.z > z_pos - radius - 1) & (Location.dimension == dimension_obj)
return list_to_string(self.database.query_by_filter(session, Location, expr)) return list_to_string(self.database.query_by_filter(session, Location, expr))

View File

@ -90,7 +90,6 @@ class TunnelDirection(enum.Enum):
South = "south" South = "south"
West = "west" West = "west"
def str_to_tunnel_dir(arg): def str_to_tunnel_dir(arg):
arg = arg.lower() arg = arg.lower()

View File

@ -10,14 +10,14 @@ def get_name(args):
return name return name
def get_nickname(discord_user, bot_config): def get_nickname(discord_user, special_users):
if discord_user.nick is None: if discord_user.nick is None:
name = discord_user.display_name name = discord_user.display_name
else: else:
name = discord_user.nick name = discord_user.nick
if name in bot_config.special_name_list: if name in special_users:
return bot_config.special_name_list[name] return special_users[name]
else: else:
return name return name

View File

@ -43,6 +43,7 @@ class GeoffreyBot(commands.Bot):
super().__init__(command_prefix=config.prefix, description=description, pm_help=True, case_insensitive=True) super().__init__(command_prefix=config.prefix, description=description, pm_help=True, case_insensitive=True)
self.error_users = config.error_users self.error_users = config.error_users
self.admin_users = config.bot_mod self.admin_users = config.bot_mod
self.special_users = config.special_name_list
self.bot_commands = Commands(config) self.bot_commands = Commands(config)
for extension in extensions: for extension in extensions:
@ -109,9 +110,8 @@ class GeoffreyBot(commands.Bot):
logger.error("Geoffrey encountered unhandled exception: %s", error) logger.error("Geoffrey encountered unhandled exception: %s", error)
error_str = bad_error_message.format(ctx.invoked_with) error_str = bad_error_message.format(ctx.invoked_with)
await self.send_message(ctx.message.channel, await self.send_message(ctx.message.channel, '{} **Error Running Command:** {}'.format(
'{} **Error Running Command:** {}'.format(ctx.message.author.mention, ctx.message.author.mention, error_str))
error_str))
async def send_error_message(self, msg): async def send_error_message(self, msg):
for user_id in self.error_users: 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__)))): def start_bot(config_path="{}/GeoffreyConfig.ini".format(path.dirname(path.abspath(__file__)))):
bot = None
try: try:
bot_config = get_config(config_path) 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: except Exception as e:
logger.info('Bot encountered the following unhandled exception %s', e) logger.info('Bot encountered the following unhandled exception %s', e)
finally: finally:
if bot is not None:
bot.loop.stop() bot.loop.stop()
logger.info("Bot shutting down...") logger.info("Bot shutting down...")

View File

@ -23,7 +23,7 @@ class Add_Commands:
""" """
try: 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) 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)) await self.bot.say('{}, you have been added to the database.'.format(ctx.message.author.mention))
except AttributeError: except AttributeError:

View File

@ -37,7 +37,8 @@ class Edit_Commands:
""" """
loc = get_name(args) loc = get_name(args)
try: 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( await self.bot.say(
'{}, the following location has been updated: \n\n{}'.format(ctx.message.author.mention, loc_str)) '{}, the following location has been updated: \n\n{}'.format(ctx.message.author.mention, loc_str))