2018-08-05 22:20:37 +00:00
|
|
|
from discord.ext import commands
|
2018-08-12 19:00:04 +00:00
|
|
|
|
2018-08-21 20:36:51 +00:00
|
|
|
from geoffrey.BotErrors import *
|
|
|
|
from geoffrey.DiscordHelperFunctions import *
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
|
|
|
class Add_Commands:
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
Commands for adding things to Geoffrey.
|
|
|
|
*You must use ?register before using any of these commands!*
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
|
|
|
|
2018-08-05 22:20:37 +00:00
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
@commands.command(pass_context=True)
|
2018-08-11 16:20:40 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-08-05 22:20:37 +00:00
|
|
|
async def register(self, ctx):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-13 16:25:40 +00:00
|
|
|
Registers your Discord and Minecraft account with the the database
|
2018-08-05 22:20:37 +00:00
|
|
|
You must do this before adding entries to the database.
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
try:
|
2018-08-30 16:46:20 +00:00
|
|
|
player_name = get_nickname(ctx.message.author, self.bot.special_users)
|
2018-08-30 16:34:19 +00:00
|
|
|
self.bot.bot_commands.register(player_name, ctx.message.author.id)
|
2018-09-13 21:02:52 +00:00
|
|
|
await ctx.send('{}, you have been added to the database. Use ?help to see all the commands this bot can do.'
|
|
|
|
.format(ctx.message.author.mention))
|
2018-08-05 22:20:37 +00:00
|
|
|
except AttributeError:
|
|
|
|
raise NotOnServerError
|
|
|
|
except PlayerInDBError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, you are already in the database. Ding dong.'.format(ctx.message.author.mention))
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
@commands.command(pass_context=True)
|
2018-08-11 16:20:40 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-08-05 22:20:37 +00:00
|
|
|
async def add_base(self, ctx, x_pos: int, z_pos: int, *args):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-15 17:57:57 +00:00
|
|
|
Adds your base to the database. The base name is optional if this is your first base
|
2018-08-05 22:20:37 +00:00
|
|
|
?add_base [X Coordinate] [Z Coordinate] [Base Name]
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
name = get_name(args)
|
|
|
|
|
|
|
|
try:
|
2018-08-30 16:34:19 +00:00
|
|
|
base = self.bot.bot_commands.add_base(x_pos, z_pos, base_name=name, discord_uuid=ctx.message.author.id)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-05 22:20:37 +00:00
|
|
|
'{}, your base has been added to the database: \n\n{}'.format(ctx.message.author.mention, base))
|
|
|
|
except LocationInitError:
|
|
|
|
raise commands.UserInputError
|
|
|
|
except EntryNameNotUniqueError:
|
|
|
|
if name is None:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, you already have one base in the database, you need to specify a base'
|
2018-09-13 16:25:40 +00:00
|
|
|
' name'.format(ctx.message.author.mention))
|
2018-08-05 22:20:37 +00:00
|
|
|
else:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-11 23:02:50 +00:00
|
|
|
'{}, a base called **{}** already exists. You need to specify a different name.'.format(
|
|
|
|
ctx.message.author.mention, name))
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
@commands.command(pass_context=True)
|
2018-08-11 16:20:40 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-08-05 22:20:37 +00:00
|
|
|
async def add_shop(self, ctx, x_pos: int, z_pos: int, *args):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-15 17:57:57 +00:00
|
|
|
Adds your shop to the database. The name is optional if this is your first shop
|
2018-08-05 22:20:37 +00:00
|
|
|
?add_shop [X Coordinate] [Z Coordinate] [Shop Name]
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
name = get_name(args)
|
|
|
|
|
|
|
|
try:
|
2018-08-30 16:34:19 +00:00
|
|
|
shop = self.bot.bot_commands.add_shop(x_pos, z_pos, shop_name=name, discord_uuid=ctx.message.author.id)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-05 22:20:37 +00:00
|
|
|
'{}, your shop has been added to the database: \n\n{}'.format(ctx.message.author.mention, shop))
|
|
|
|
except LocationInitError:
|
|
|
|
raise commands.UserInputError
|
|
|
|
except EntryNameNotUniqueError:
|
|
|
|
if name is None:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-11 23:02:50 +00:00
|
|
|
'{}, you already have one shop in the database, you need to specify a shop name'.format(
|
|
|
|
ctx.message.author.mention))
|
2018-08-05 22:20:37 +00:00
|
|
|
else:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-11 23:02:50 +00:00
|
|
|
'{}, a shop called **{}** already exists. You need to specify a different name.'.format(
|
|
|
|
ctx.message.author.mention, name))
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
@commands.command(pass_context=True)
|
2018-08-11 16:20:40 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-09-13 17:06:37 +00:00
|
|
|
async def add_tunnel(self, ctx, tunnel_direction: str, tunnel_number: int, *args):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-13 16:25:40 +00:00
|
|
|
Adds your tunnel to the database. If you only have one location, you do not need to specify a location name
|
|
|
|
|
2018-09-13 17:06:37 +00:00
|
|
|
Directions: North South East West
|
2018-09-12 21:29:28 +00:00
|
|
|
?tunnel [Tunnel Direction] [Tunnel Number] [Location Name]
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
loc_name = get_name(args)
|
|
|
|
try:
|
2018-09-13 17:06:37 +00:00
|
|
|
self.bot.bot_commands.add_tunnel(tunnel_direction, tunnel_number, discord_uuid=ctx.message.author.id,
|
2018-09-13 16:25:40 +00:00
|
|
|
location_name=loc_name)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, your tunnel has been added to the database'.format(ctx.message.author.mention))
|
2018-08-05 22:20:37 +00:00
|
|
|
except LocationLookUpError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, you do not have a location called **{}**.'.format(
|
2018-08-05 22:20:37 +00:00
|
|
|
ctx.message.author.mention, loc_name))
|
2018-09-13 18:28:18 +00:00
|
|
|
except NoLocationsInDatabase:
|
|
|
|
await ctx.send('{}, you do not have a location in the database.'.format(
|
|
|
|
ctx.message.author.mention, loc_name))
|
2018-08-05 22:20:37 +00:00
|
|
|
except LocationHasTunnelError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, **{}** already has a tunnel.'.format(ctx.message.author.mention, loc_name))
|
2018-08-05 22:20:37 +00:00
|
|
|
except TunnelInitError:
|
2018-09-13 17:06:37 +00:00
|
|
|
await ctx.send('{}, invalid tunnel direction.'.format(ctx.message.author.mention))
|
2018-08-05 22:20:37 +00:00
|
|
|
except EntryNameNotUniqueError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, you have more than one location, you need to specify a location.'
|
2018-09-13 16:25:40 +00:00
|
|
|
.format(ctx.message.author.mention))
|
2018-08-05 22:20:37 +00:00
|
|
|
except InvalidTunnelError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-09-13 17:06:37 +00:00
|
|
|
'{}, **{}** is an invalid tunnel direction.'.format(ctx.message.author.mention, tunnel_direction))
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
@commands.command(pass_context=True)
|
2018-08-11 16:20:40 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-08-05 22:20:37 +00:00
|
|
|
async def add_item(self, ctx, item_name: str, quantity: int, diamond_price: int, *args):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-13 16:25:40 +00:00
|
|
|
Adds an item to a shop's inventory. If you have one shop, the shop name is not required
|
|
|
|
|
2018-09-13 20:31:54 +00:00
|
|
|
Quantity for Diamond Price. eg. 32 Dirt for 1D. If the item name has spaces in wrap in in quotes eg "Silk Touch"
|
2018-09-12 21:11:56 +00:00
|
|
|
?add_item [Item Name] [Quantity] [Price] [Shop name]
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
shop_name = get_name(args)
|
|
|
|
try:
|
2018-08-30 16:34:19 +00:00
|
|
|
self.bot.bot_commands.add_item(item_name, quantity, diamond_price, shop_name=shop_name,
|
2018-09-13 16:25:40 +00:00
|
|
|
discord_uuid=ctx.message.author.id)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-11 23:02:50 +00:00
|
|
|
'{}, **{}** has been added to the inventory of your shop.'.format(ctx.message.author.mention,
|
|
|
|
item_name))
|
2018-09-13 16:25:40 +00:00
|
|
|
except NoLocationsInDatabase:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, you don\'t have any shops in the database.'.format(ctx.message.author.mention))
|
2018-09-20 14:20:30 +00:00
|
|
|
except EntryNameNotUniqueError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, you have more than one shop in the database, please specify a shop name.'
|
2018-09-13 16:25:40 +00:00
|
|
|
.format(ctx.message.author.mention))
|
2018-08-05 22:20:37 +00:00
|
|
|
except LocationLookUpError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-05 22:20:37 +00:00
|
|
|
'{}, you don\'t have any shops named **{}** in the database.'.format(ctx.message.author.mention,
|
|
|
|
shop_name))
|
|
|
|
|
|
|
|
|
|
|
|
def setup(bot):
|
2018-08-11 23:02:50 +00:00
|
|
|
bot.add_cog(Add_Commands(bot))
|