fixed issue with ?register function. Also cleaned up code a bit
parent
6748f01208
commit
2111bf8c8e
|
@ -78,4 +78,3 @@ class Config:
|
||||||
|
|
||||||
def get_config(config_path):
|
def get_config(config_path):
|
||||||
return Config(config_path)
|
return Config(config_path)
|
||||||
|
|
||||||
|
|
|
@ -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))
|
||||||
|
|
|
@ -59,7 +59,7 @@ class GeoffreyDatabase:
|
||||||
filter_value = self.combine_filter(args)
|
filter_value = self.combine_filter(args)
|
||||||
return session.query(obj_type).filter(filter_value).limit(limit).all()
|
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)
|
filter_value = self.combine_filter(args)
|
||||||
entry = session.query(obj_type).filter(filter_value)
|
entry = session.query(obj_type).filter(filter_value)
|
||||||
|
@ -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()
|
||||||
|
|
||||||
|
@ -210,7 +209,7 @@ class Location(SQL_Base):
|
||||||
raise LocationInitError
|
raise LocationInitError
|
||||||
|
|
||||||
def dynmap_link(self, bot_config):
|
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)
|
format(bot_config.dynmap_url, bot_config.world_name, self.x, self.z)
|
||||||
|
|
||||||
def pos_to_str(self):
|
def pos_to_str(self):
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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...")
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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))
|
||||||
|
|
Loading…
Reference in New Issue