Commands args now use converters
parent
14508a6466
commit
d499af25c7
49
MCInfoBot.py
49
MCInfoBot.py
|
@ -63,17 +63,18 @@ class Location(SQL_Base):
|
||||||
direction = Column(Enum(TunnelDirection))
|
direction = Column(Enum(TunnelDirection))
|
||||||
owner = Column(String, ForeignKey('Players.in_game_name'))
|
owner = Column(String, ForeignKey('Players.in_game_name'))
|
||||||
|
|
||||||
def __init__(self, args, owner):
|
def __init__(self, name, x, y, z, owner, args):
|
||||||
try:
|
try:
|
||||||
self.name = args[0]
|
self.name = name
|
||||||
self.x = int(args[1])
|
self.x = x
|
||||||
self.y = int(args[2])
|
self.y = y
|
||||||
self.z = int(args[3])
|
self.z = z
|
||||||
self.owner = owner
|
self.owner = owner
|
||||||
|
|
||||||
if len(args) >= 5:
|
if len(args) > 0:
|
||||||
self.tunnelNumber = int(args[5])
|
self.direction = strToTunnelDirection(args[0])
|
||||||
self.direction = strToTunnelDirection(args[4])
|
self.tunnelNumber = int(args[1])
|
||||||
|
|
||||||
except (ValueError, IndexError):
|
except (ValueError, IndexError):
|
||||||
raise LocationInitError
|
raise LocationInitError
|
||||||
|
|
||||||
|
@ -111,8 +112,6 @@ def strToTunnelDirection(arg):
|
||||||
|
|
||||||
|
|
||||||
# Bot Commands ******************************************************************
|
# Bot Commands ******************************************************************
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print('GeoffreyBot')
|
print('GeoffreyBot')
|
||||||
|
@ -134,12 +133,14 @@ async def on_command_error(error, ctx):
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def test():
|
async def test():
|
||||||
'''Check if the bot is alive.'''
|
'''
|
||||||
|
Checks if the bot is alive.
|
||||||
|
'''
|
||||||
await bot.say('I\'m here you ding dong')
|
await bot.say('I\'m here you ding dong')
|
||||||
|
|
||||||
|
|
||||||
@bot.command(pass_context=True)
|
@bot.command(pass_context=True)
|
||||||
async def addbase(ctx, *args, ):
|
async def addbase(ctx, name: str, x_pos: int, y_pos: int, z_pos: int, * args):
|
||||||
'''
|
'''
|
||||||
Add your base to the database.
|
Add your base to the database.
|
||||||
The tunnel address is optional.
|
The tunnel address is optional.
|
||||||
|
@ -147,7 +148,7 @@ async def addbase(ctx, *args, ):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
owner = Player(str(ctx.message.author.nick))
|
owner = Player(str(ctx.message.author.nick))
|
||||||
base = Location(args, owner.in_game_name)
|
base = Location(name, x_pos, y_pos, z_pos, owner.in_game_name, args)
|
||||||
|
|
||||||
session.add(owner)
|
session.add(owner)
|
||||||
session.add(base)
|
session.add(base)
|
||||||
|
@ -157,19 +158,23 @@ async def addbase(ctx, *args, ):
|
||||||
|
|
||||||
|
|
||||||
@bot.command(pass_context=True)
|
@bot.command(pass_context=True)
|
||||||
async def findbase(ctx, *args):
|
async def findbase(ctx, name: str):
|
||||||
'''Allows you to find a base in the database.
|
'''
|
||||||
|
Allows you to find a base in the database.
|
||||||
?findbase [Player name]
|
?findbase [Player name]
|
||||||
'''
|
'''
|
||||||
search_key = args[0]
|
|
||||||
baseList = session.query(Location).filter_by(owner=search_key).all()
|
|
||||||
|
|
||||||
if baseList is not None:
|
base_list = session.query(Location).filter_by(owner=name).all()
|
||||||
await bot.say('{}, {} has {} base(s):'.format(ctx.message.author.mention, args[0], len(baseList)))
|
|
||||||
for base in baseList:
|
if base_list is not None:
|
||||||
await bot.say(base)
|
base_string = ''
|
||||||
|
|
||||||
|
for base in base_list:
|
||||||
|
base_string = '{} \n{}'.format(base_string, base)
|
||||||
|
|
||||||
|
await bot.say('{}, {} has {} base(s): \n {}'.format(ctx.message.author.mention, name, len(base_list), base_string))
|
||||||
else:
|
else:
|
||||||
await bot.say('{}, {} is not in the database'.format(ctx.message.author.mention, args[0]))
|
await bot.say('{}, {} is not in the database'.format(ctx.message.author.mention, name))
|
||||||
|
|
||||||
# Bot Startup ******************************************************************
|
# Bot Startup ******************************************************************
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue