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
|
|
|
|
|
|
|
|
|
|
|
class Search_Commands:
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
Commands to find stuff.
|
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-19 16:37:59 +00:00
|
|
|
async def find(self, ctx, *args):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-13 16:25:40 +00:00
|
|
|
Finds all the locations matching the search term
|
2018-08-05 22:20:37 +00:00
|
|
|
?find [Search]
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
search = get_name(args)
|
|
|
|
try:
|
|
|
|
|
|
|
|
if search is None:
|
|
|
|
raise commands.UserInputError
|
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
result = self.bot.bot_commands.find(search)
|
2018-08-05 22:20:37 +00:00
|
|
|
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-19 16:37:59 +00:00
|
|
|
'{}, The following entries match **{}**:\n{}'.format(ctx.message.author.mention, search, result))
|
2018-08-05 22:20:37 +00:00
|
|
|
except LocationLookUpError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-19 16:37:59 +00:00
|
|
|
'{}, no matches to **{}** were found in the database.'.format(ctx.message.author.mention, search))
|
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 tunnel(self, ctx, player: str):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-13 16:25:40 +00:00
|
|
|
Finds all the tunnels a player owns
|
2018-08-05 22:20:37 +00:00
|
|
|
?tunnel [Player]
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
try:
|
2018-08-30 16:34:19 +00:00
|
|
|
result = self.bot.bot_commands.tunnel(player)
|
2018-08-05 22:20:37 +00:00
|
|
|
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-19 16:37:59 +00:00
|
|
|
'{}, **{}** owns the following tunnels: \n{}'.format(ctx.message.author.mention, player, result))
|
2018-08-05 22:20:37 +00:00
|
|
|
except LocationLookUpError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, no tunnels for **{}** were found in the database.'
|
2018-09-13 16:25:40 +00:00
|
|
|
.format(ctx.message.author.mention, player))
|
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-19 16:37:59 +00:00
|
|
|
async def find_around(self, ctx, x_pos: int, z_pos: int, *args):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
Finds all the locations around a certain point.
|
2018-09-13 16:25:40 +00:00
|
|
|
The radius defaults to 200 blocks if no value is given
|
|
|
|
|
|
|
|
Default dimension is the overworld
|
2018-08-18 17:01:59 +00:00
|
|
|
?find_around [X Coordinate] [Z Coordinate] [Radius] [Optional Flags]
|
2018-08-05 22:20:37 +00:00
|
|
|
|
2018-08-18 17:01:59 +00:00
|
|
|
Optional Flags:
|
|
|
|
-d [dimension]
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
radius = 200
|
|
|
|
dimension = 'Overworld'
|
|
|
|
|
|
|
|
try:
|
|
|
|
if len(args) > 0:
|
|
|
|
if args[0] == '-d':
|
|
|
|
dimension = args[1]
|
|
|
|
if len(args) > 1:
|
|
|
|
radius = int(args[2])
|
|
|
|
else:
|
|
|
|
radius = int(args[0])
|
|
|
|
|
|
|
|
if len(args) > 1:
|
|
|
|
if args[1] == '-d':
|
|
|
|
dimension = args[2]
|
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
base_string = self.bot.bot_commands.find_around(x_pos, z_pos, radius, dimension)
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
if len(base_string) != 0:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, the following locations(s) within **{}** blocks of that point: \n {}'.format(
|
2018-08-05 22:20:37 +00:00
|
|
|
ctx.message.author.mention, radius, base_string))
|
|
|
|
else:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, there are no locations within {} blocks of that point'
|
2018-09-13 16:25:40 +00:00
|
|
|
.format(ctx.message.author.mention, radius))
|
2018-08-05 22:20:37 +00:00
|
|
|
except ValueError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-19 16:37:59 +00:00
|
|
|
'{}, invalid radius, the radius must be a whole number.'.format(ctx.message.author.mention,
|
|
|
|
radius))
|
2018-08-05 22:20:37 +00:00
|
|
|
except InvalidDimError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, {} is an invalid dimension.'.format(ctx.message.author.mention, dimension))
|
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 selling(self, ctx, item_name: str):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
Lists all the shops selling an item
|
2018-08-18 17:01:59 +00:00
|
|
|
?selling [item]
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
try:
|
2018-08-30 16:34:19 +00:00
|
|
|
result = self.bot.bot_commands.selling(item_name)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(
|
2018-08-19 16:37:59 +00:00
|
|
|
'{}, the following shops sell **{}**: \n{}'.format(ctx.message.author.mention, item_name, result))
|
2018-08-05 22:20:37 +00:00
|
|
|
except ItemNotFound:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, no shop sells **{}**.'.format(ctx.message.author.mention, item_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-19 16:37:59 +00:00
|
|
|
async def info(self, ctx, *args):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
Displays info about a location.
|
2018-09-13 16:25:40 +00:00
|
|
|
If the location is a shop, it displays the shop's inventory
|
2018-08-18 17:01:59 +00:00
|
|
|
?info [Location Name]
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
loc = get_name(args)
|
|
|
|
try:
|
|
|
|
|
|
|
|
if loc is None:
|
|
|
|
raise commands.UserInputError
|
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
info_str = self.bot.bot_commands.info(loc)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send(info_str)
|
2018-08-05 22:20:37 +00:00
|
|
|
except IndexError:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, no locations in the database match **{}**.'.format(ctx.message.author.mention, loc))
|
2018-08-05 22:20:37 +00:00
|
|
|
|
2018-08-10 23:03:30 +00:00
|
|
|
@commands.command(pass_context=True)
|
2018-08-11 16:20:40 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-08-10 23:03:30 +00:00
|
|
|
async def me(self, ctx):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-10 23:03:30 +00:00
|
|
|
Displays all your locations in the database
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-10 23:03:30 +00:00
|
|
|
try:
|
2018-08-30 16:34:19 +00:00
|
|
|
loc_str = self.bot.bot_commands.me(discord_uuid=ctx.message.author.id)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, here are your locations in the database: \n {}'.format(ctx.message.author.mention,
|
2018-09-13 16:25:40 +00:00
|
|
|
loc_str))
|
2018-08-10 23:03:30 +00:00
|
|
|
except PlayerNotFound:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, you don\'t have any locations in the database.'.format(ctx.message.author.mention))
|
2018-08-10 23:03:30 +00:00
|
|
|
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
def setup(bot):
|
|
|
|
bot.add_cog(Search_Commands(bot))
|