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):
return Config(config_path)

View File

@ -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))

View File

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

View File

@ -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

View File

@ -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:
if bot is not None:
bot.loop.stop()
logger.info("Bot shutting down...")

View File

@ -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:

View File

@ -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))