From 905c606cd54a37d2eb3217b4eb94bddb65504a0f Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 26 May 2018 09:58:04 -0500 Subject: [PATCH] added str_to_tunnel_dir to enum TunnelDirection --- MCInfoBot.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/MCInfoBot.py b/MCInfoBot.py index e633555..49b5181 100644 --- a/MCInfoBot.py +++ b/MCInfoBot.py @@ -42,6 +42,19 @@ class TunnelDirection(enum.Enum): South = 'red' West = 'yellow' + def str_to_tunnel_dir(arg): + arg = arg.lower() + if arg == TunnelDirection.North.value: + return TunnelDirection.North + elif arg == TunnelDirection.East.value: + return TunnelDirection.East + elif arg == TunnelDirection.South.value: + return TunnelDirection.South + elif arg == TunnelDirection.West.value: + return TunnelDirection.West + else: + raise ValueError + class Player(SQL_Base): __tablename__ = 'Players' @@ -74,7 +87,7 @@ class Location(SQL_Base): self.owner = owner if len(args) > 0: - self.direction = strToTunnelDirection(args[0]) + self.direction = TunnelDirection.str_to_tunnel_direction(args[0]) self.tunnelNumber = int(args[1]) except (ValueError, IndexError): @@ -88,7 +101,8 @@ class Location(SQL_Base): def __str__(self): if self.direction is not None: - return "Name: {}, Position: {}, Tunnel: {}".format(self.name, self.pos_to_str(), self.nether_tunnel_addr_to_str()) + return "Name: {}, Position: {}, Tunnel: {}".format(self.name, self.pos_to_str(), + self.nether_tunnel_addr_to_str()) else: return "Name: {}, Position: {}".format(self.name, self.pos_to_str()) @@ -98,21 +112,6 @@ SQL_Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) session = Session() - -def strToTunnelDirection(arg): - arg = arg.lower() - if (arg == TunnelDirection.North.value): - return TunnelDirection.North - elif (arg == TunnelDirection.East.value): - return TunnelDirection.East - elif (arg == TunnelDirection.South.value): - return TunnelDirection.South - elif (arg == TunnelDirection.West.value): - return TunnelDirection.West - else: - raise ValueError - - # Bot Commands ****************************************************************** @bot.event async def on_ready():