2018-05-21 15:59:35 +00:00
|
|
|
from discord.ext import commands
|
2018-07-22 23:56:07 +00:00
|
|
|
from Commands import *
|
2018-05-29 14:04:01 +00:00
|
|
|
from BotErrors import *
|
2018-06-03 02:42:31 +00:00
|
|
|
from MinecraftAccountInfoGrabber import *
|
2018-07-15 18:27:11 +00:00
|
|
|
from itertools import zip_longest
|
2018-07-21 18:28:31 +00:00
|
|
|
from BotConfig import *
|
2018-07-23 02:51:22 +00:00
|
|
|
import threading
|
2018-07-21 18:28:31 +00:00
|
|
|
|
2018-05-21 15:59:35 +00:00
|
|
|
command_prefix = '?'
|
2018-05-25 16:32:29 +00:00
|
|
|
description = '''
|
2018-07-21 02:11:50 +00:00
|
|
|
Geoffrey started his life as an inside joke none of you will understand.
|
2018-05-26 15:07:17 +00:00
|
|
|
At some point, she was to become an airhorn bot. Now, they know where your bases/shops are.
|
2018-05-22 02:41:15 +00:00
|
|
|
|
2018-07-01 15:10:10 +00:00
|
|
|
Please respect Geoffrey, the bot is very sensitive.
|
2018-07-14 22:25:33 +00:00
|
|
|
|
|
|
|
*You must use ?register before adding entries into Geoffrey*
|
2018-05-22 02:41:15 +00:00
|
|
|
'''
|
2018-05-25 16:32:29 +00:00
|
|
|
|
2018-05-25 22:00:43 +00:00
|
|
|
bad_error_message = 'OOPSIE WOOPSIE!! Uwu We made a fucky wucky!! A wittle fucko boingo! The admins at our ' \
|
2018-06-30 15:07:56 +00:00
|
|
|
'headquarters are working VEWY HAWD to fix this! (Error in command {}: {})'
|
2018-05-25 22:00:43 +00:00
|
|
|
|
2018-05-25 16:32:29 +00:00
|
|
|
bot = commands.Bot(command_prefix=command_prefix, description=description, case_insensitive=True)
|
|
|
|
|
2018-06-23 16:08:40 +00:00
|
|
|
# Bot Commands ******************************************************************'
|
|
|
|
|
2018-06-03 02:42:31 +00:00
|
|
|
|
2018-05-21 15:59:35 +00:00
|
|
|
@bot.event
|
|
|
|
async def on_ready():
|
2018-05-25 16:32:29 +00:00
|
|
|
print('GeoffreyBot')
|
|
|
|
print('Username: ' + bot.user.name)
|
|
|
|
print('ID: ' + bot.user.id)
|
|
|
|
|
|
|
|
|
|
|
|
@bot.event
|
|
|
|
async def on_command_error(error, ctx):
|
2018-05-25 20:30:47 +00:00
|
|
|
if isinstance(error, commands.CommandNotFound):
|
2018-06-02 16:11:31 +00:00
|
|
|
error_str = 'Command not found, ding dongs like you can use ?help to see all the commands this bot can do.'
|
2018-07-29 14:29:27 +00:00
|
|
|
elif isinstance(error, commands.CommandOnCooldown):
|
|
|
|
return
|
2018-05-26 14:53:36 +00:00
|
|
|
elif isinstance(error, commands.UserInputError):
|
2018-07-28 00:02:41 +00:00
|
|
|
error_str = 'Invalid syntax for **{}** you ding dong, please read ?help {}.'\
|
2018-06-02 16:11:31 +00:00
|
|
|
.format(ctx.invoked_with, ctx.invoked_with)
|
2018-06-03 02:42:31 +00:00
|
|
|
elif isinstance(error.original, UsernameLookupFailed):
|
|
|
|
error_str = error.original.__doc__
|
2018-07-08 19:19:40 +00:00
|
|
|
elif isinstance(error.original, PlayerNotFound):
|
|
|
|
error_str = 'Make sure to use ?register first you ding dong.'
|
2018-07-21 01:50:24 +00:00
|
|
|
elif isinstance(error.original, EntryNameNotUniqueError):
|
2018-07-14 22:25:33 +00:00
|
|
|
error_str = 'An entry in the database already has that name ding dong.'
|
2018-07-22 23:56:07 +00:00
|
|
|
elif isinstance(error.original, DatabaseValueError):
|
2018-07-23 00:01:49 +00:00
|
|
|
error_str = 'Use a shorter name or a smaller value, dong ding.'
|
2018-05-25 20:30:47 +00:00
|
|
|
else:
|
2018-06-30 15:07:56 +00:00
|
|
|
error_str = bad_error_message.format(ctx.invoked_with, error)
|
2018-05-25 20:30:47 +00:00
|
|
|
|
2018-07-23 00:01:49 +00:00
|
|
|
await bot.send_message(ctx.message.channel, '{} **Error Running Command:** {}'.format(ctx.message.author.mention,
|
|
|
|
error_str))
|
2018-05-25 16:32:29 +00:00
|
|
|
|
2018-05-21 15:59:35 +00:00
|
|
|
|
2018-07-29 14:29:27 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-05-21 15:59:35 +00:00
|
|
|
@bot.command()
|
|
|
|
async def test():
|
2018-05-25 21:06:00 +00:00
|
|
|
'''
|
|
|
|
Checks if the bot is alive.
|
|
|
|
'''
|
2018-05-25 16:32:29 +00:00
|
|
|
await bot.say('I\'m here you ding dong')
|
|
|
|
|
2018-07-21 01:50:24 +00:00
|
|
|
|
2018-07-29 14:29:27 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-07-08 19:19:40 +00:00
|
|
|
@bot.command(pass_context=True)
|
|
|
|
async def register(ctx):
|
|
|
|
'''
|
2018-07-21 02:11:50 +00:00
|
|
|
Registers your Discord and Minecraft account with the the database.
|
|
|
|
You must do this before adding entries to the database.
|
2018-07-08 19:19:40 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
try:
|
2018-07-21 03:10:13 +00:00
|
|
|
player_name = get_nickname(ctx.message.author)
|
2018-07-22 23:56:07 +00:00
|
|
|
bot_commands.register(player_name, ctx.message.author.id)
|
|
|
|
await bot.say('{}, you have been added to the database.'.format(ctx.message.author.mention))
|
2018-07-21 03:10:13 +00:00
|
|
|
except AttributeError:
|
|
|
|
await bot.say('{}, run this command on 24CC whoever you are'.format(ctx.message.author.mention))
|
2018-07-08 19:19:40 +00:00
|
|
|
except LocationInitError:
|
|
|
|
raise commands.UserInputError
|
2018-07-23 01:37:06 +00:00
|
|
|
except PlayerInDB:
|
|
|
|
await bot.say('{}, you are already in the database. Ding dong.'.format(ctx.message.author.mention))
|
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
|
2018-07-29 14:29:27 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-05-21 15:59:35 +00:00
|
|
|
@bot.command(pass_context=True)
|
2018-08-01 01:16:14 +00:00
|
|
|
async def add_base(ctx, x_pos: int, z_pos: int, * args):
|
2018-05-25 16:32:29 +00:00
|
|
|
'''
|
2018-07-22 12:52:49 +00:00
|
|
|
Adds your base to the database.
|
|
|
|
The name is optional.
|
2018-08-01 01:16:14 +00:00
|
|
|
?add_base [X Coordinate] [Z Coordinate] [Base Name]
|
2018-05-25 16:32:29 +00:00
|
|
|
'''
|
2018-07-28 00:02:41 +00:00
|
|
|
|
|
|
|
name = get_name(args)
|
2018-07-22 23:56:07 +00:00
|
|
|
|
2018-05-26 14:53:36 +00:00
|
|
|
try:
|
2018-08-01 00:22:17 +00:00
|
|
|
base = bot_commands.add_base(x_pos, z_pos, base_name=name, discord_uuid=ctx.message.author.id)
|
2018-07-24 01:12:23 +00:00
|
|
|
await bot.say('{}, your base has been added to the database: \n\n{}'.format(ctx.message.author.mention, base))
|
2018-05-26 14:53:36 +00:00
|
|
|
except LocationInitError:
|
|
|
|
raise commands.UserInputError
|
2018-07-21 01:50:24 +00:00
|
|
|
except EntryNameNotUniqueError:
|
2018-07-22 23:56:07 +00:00
|
|
|
if name is None:
|
|
|
|
await bot.say('{}, you already have one base in the database, you need to specify a base'
|
|
|
|
' name'.format(ctx.message.author.mention))
|
|
|
|
else:
|
|
|
|
await bot.say('{}, a base called **{}** already exists. You need to specify a different name.'.format(
|
|
|
|
ctx.message.author.mention, name))
|
2018-07-22 01:44:43 +00:00
|
|
|
|
2018-07-21 01:50:24 +00:00
|
|
|
|
2018-07-29 14:29:27 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-06-23 17:33:02 +00:00
|
|
|
@bot.command(pass_context=True)
|
2018-08-01 01:16:14 +00:00
|
|
|
async def add_shop(ctx, x_pos: int, z_pos: int, *args):
|
2018-06-23 17:33:02 +00:00
|
|
|
'''
|
2018-07-22 12:52:49 +00:00
|
|
|
Adds your shop to the database.
|
|
|
|
The name is optional.
|
2018-08-01 01:16:14 +00:00
|
|
|
?add_shop [X Coordinate] [Z Coordinate] [Shop Name]
|
2018-06-23 17:33:02 +00:00
|
|
|
'''
|
2018-07-28 00:02:41 +00:00
|
|
|
|
|
|
|
name = get_name(args)
|
2018-06-23 17:33:02 +00:00
|
|
|
|
|
|
|
try:
|
2018-08-01 01:16:14 +00:00
|
|
|
shop = bot_commands.add_shop(x_pos, z_pos, shop_name=name, discord_uuid=ctx.message.author.id)
|
2018-07-24 01:12:23 +00:00
|
|
|
await bot.say('{}, your shop has been added to the database: \n\n{}'.format(ctx.message.author.mention, shop))
|
2018-06-23 17:33:02 +00:00
|
|
|
except LocationInitError:
|
|
|
|
raise commands.UserInputError
|
2018-07-21 01:50:24 +00:00
|
|
|
except EntryNameNotUniqueError:
|
2018-07-22 23:56:07 +00:00
|
|
|
if name is None:
|
|
|
|
await bot.say('{}, you already have one shop in the database, you need to specify a shop name'.format(
|
|
|
|
ctx.message.author.mention))
|
|
|
|
else:
|
|
|
|
await bot.say('{}, a shop called **{}** already exists. You need to specify a different name.'.format(
|
|
|
|
ctx.message.author.mention, name))
|
2018-05-25 16:32:29 +00:00
|
|
|
|
2018-07-29 14:29:27 +00:00
|
|
|
|
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-07-21 01:50:24 +00:00
|
|
|
@bot.command(pass_context=True)
|
2018-08-01 01:16:14 +00:00
|
|
|
async def add_tunnel(ctx, tunnel_color: str, tunnel_number: int, *args):
|
2018-07-21 01:50:24 +00:00
|
|
|
'''
|
2018-07-21 02:11:50 +00:00
|
|
|
Adds your tunnel to the database.
|
2018-07-23 00:26:21 +00:00
|
|
|
?tunnel [Tunnel Color] [Tunnel Number] [Location Name]
|
2018-07-21 01:50:24 +00:00
|
|
|
'''
|
|
|
|
|
2018-08-01 01:16:14 +00:00
|
|
|
loc_name = get_name(args)
|
|
|
|
try:
|
2018-08-01 00:22:17 +00:00
|
|
|
bot_commands.add_tunnel(tunnel_color, tunnel_number, discord_uuid=ctx.message.author.id, location_name=loc_name)
|
2018-07-22 23:56:07 +00:00
|
|
|
await bot.say('{}, your tunnel has been added to the database'.format(ctx.message.author.mention))
|
2018-07-21 01:50:24 +00:00
|
|
|
except LocationLookUpError:
|
2018-07-21 02:11:50 +00:00
|
|
|
await bot.say('{}, you do not have a location called **{}**.'.format(
|
2018-08-01 00:22:17 +00:00
|
|
|
ctx.message.author.mention, loc_name))
|
2018-07-29 13:59:11 +00:00
|
|
|
except LocationHasTunnelError:
|
2018-08-01 00:22:17 +00:00
|
|
|
await bot.say('{}, **{}** already has a tunnel.'.format(ctx.message.author.mention, loc_name))
|
2018-07-23 00:26:21 +00:00
|
|
|
except TunnelInitError:
|
|
|
|
await bot.say('{}, invalid tunnel color.'.format(ctx.message.author.mention))
|
2018-08-01 01:44:06 +00:00
|
|
|
except EntryNameNotUniqueError:
|
|
|
|
await bot.say('{}, you have more than one location, you need to specify a location.'
|
|
|
|
.format(ctx.message.author.mention))
|
2018-07-23 00:26:21 +00:00
|
|
|
except InvalidTunnelError:
|
2018-08-01 01:16:14 +00:00
|
|
|
await bot.say('{}, **{}** is an invalid tunnel color.'.format(ctx.message.author.mention, tunnel_color))
|
2018-07-21 01:50:24 +00:00
|
|
|
|
|
|
|
|
2018-07-29 14:29:27 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-05-25 16:32:29 +00:00
|
|
|
@bot.command(pass_context=True)
|
2018-07-23 00:26:21 +00:00
|
|
|
async def find(ctx, * args):
|
2018-05-25 21:06:00 +00:00
|
|
|
'''
|
2018-07-21 04:44:41 +00:00
|
|
|
Finds all the locations and tunnels matching the search term
|
|
|
|
?find [Search]
|
2018-05-25 16:32:29 +00:00
|
|
|
'''
|
2018-08-01 01:16:14 +00:00
|
|
|
search = get_name(args)
|
2018-06-30 15:07:56 +00:00
|
|
|
try:
|
2018-07-28 00:02:41 +00:00
|
|
|
|
|
|
|
if search is None:
|
|
|
|
raise commands.UserInputError
|
|
|
|
|
2018-07-22 23:56:07 +00:00
|
|
|
result = bot_commands.find(search)
|
2018-05-25 21:51:15 +00:00
|
|
|
|
2018-07-21 14:18:01 +00:00
|
|
|
await bot.say('{}, The following entries match **{}**:\n{}'.format(ctx.message.author.mention, search, result))
|
|
|
|
except LocationLookUpError:
|
2018-07-29 15:50:24 +00:00
|
|
|
await bot.say('{}, no matches to **{}** were found in the database.'.format(ctx.message.author.mention, search))
|
2018-05-25 16:32:29 +00:00
|
|
|
|
2018-07-29 14:29:27 +00:00
|
|
|
|
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-07-24 01:12:23 +00:00
|
|
|
@bot.command(pass_context=True)
|
|
|
|
async def tunnel(ctx, player: str):
|
|
|
|
'''
|
|
|
|
Finds all the tunnels a player owns.
|
|
|
|
?tunnel [Player]
|
|
|
|
'''
|
|
|
|
try:
|
|
|
|
result = bot_commands.tunnel(player)
|
|
|
|
|
|
|
|
await bot.say('{}, **{}** owns the following tunnels: \n{}'.format(ctx.message.author.mention, player, result))
|
|
|
|
except LocationLookUpError:
|
2018-07-29 15:50:24 +00:00
|
|
|
await bot.say('{}, no tunnels for the player **{}** were found in the database/'
|
2018-07-24 01:12:23 +00:00
|
|
|
.format(ctx.message.author.mention, player))
|
|
|
|
|
2018-07-29 14:29:27 +00:00
|
|
|
|
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-05-25 21:33:18 +00:00
|
|
|
@bot.command(pass_context=True)
|
2018-07-21 20:08:26 +00:00
|
|
|
async def delete(ctx, * args):
|
2018-05-25 21:33:18 +00:00
|
|
|
'''
|
2018-06-23 21:51:00 +00:00
|
|
|
Deletes a location from the database.
|
|
|
|
?delete [Location name]
|
2018-05-25 21:33:18 +00:00
|
|
|
'''
|
2018-08-01 01:16:14 +00:00
|
|
|
loc = get_name(args)
|
2018-05-29 14:04:01 +00:00
|
|
|
try:
|
2018-07-28 00:02:41 +00:00
|
|
|
if loc is None:
|
|
|
|
raise commands.UserInputError
|
|
|
|
|
2018-07-29 13:59:11 +00:00
|
|
|
bot_commands.delete(loc, discord_uuid=ctx.message.author.id)
|
|
|
|
await bot.say('{}, your location named **{}** has been deleted.'.format(ctx.message.author.mention, loc))
|
2018-06-30 15:07:56 +00:00
|
|
|
except (DeleteEntryError, PlayerNotFound):
|
2018-07-29 13:59:11 +00:00
|
|
|
await bot.say('{}, you do not have a location named **{}**.'.format(ctx.message.author.mention, loc))
|
2018-05-25 21:33:18 +00:00
|
|
|
|
2018-06-02 17:40:55 +00:00
|
|
|
|
2018-05-26 14:26:24 +00:00
|
|
|
@bot.command(pass_context=True)
|
2018-07-29 14:29:27 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-08-01 01:16:14 +00:00
|
|
|
async def find_around(ctx, x_pos: int, z_pos: int, * args):
|
2018-05-26 14:50:14 +00:00
|
|
|
'''
|
2018-07-21 02:11:50 +00:00
|
|
|
Finds all the locations around a certain point.
|
|
|
|
The radius defaults to 200 blocks if no value is given.
|
|
|
|
Default dimension is overworld.
|
2018-07-15 18:27:11 +00:00
|
|
|
|
2018-08-01 01:16:14 +00:00
|
|
|
?find_around [X Coordinate] [Z Coordinate] [Radius] [Optional Flags]
|
2018-07-15 18:27:11 +00:00
|
|
|
|
|
|
|
Optional Flags:
|
|
|
|
-d [dimension]
|
2018-05-26 14:50:14 +00:00
|
|
|
'''
|
2018-07-15 18:27:11 +00:00
|
|
|
|
2018-07-21 18:49:10 +00:00
|
|
|
try:
|
2018-07-22 23:56:07 +00:00
|
|
|
radius = 200
|
|
|
|
dimension = 'Overworld'
|
|
|
|
|
2018-07-21 18:49:10 +00:00
|
|
|
if len(args) > 0:
|
|
|
|
if args[0] == '-d':
|
|
|
|
dimension = args[1]
|
|
|
|
else:
|
|
|
|
radius = int(args[0])
|
2018-07-15 15:56:56 +00:00
|
|
|
|
2018-07-21 18:49:10 +00:00
|
|
|
if len(args) > 1:
|
|
|
|
if args[1] == '-d':
|
|
|
|
dimension = args[2]
|
2018-07-15 18:27:11 +00:00
|
|
|
|
2018-08-01 00:22:17 +00:00
|
|
|
base_string = bot_commands.find_around(x_pos, z_pos, radius, dimension)
|
2018-05-26 14:26:24 +00:00
|
|
|
|
2018-07-22 23:56:07 +00:00
|
|
|
if len(base_string) != 0:
|
|
|
|
await bot.say('{}, the following locations(s) within **{}** blocks of that point: \n {}'.format(
|
|
|
|
ctx.message.author.mention, radius, base_string))
|
2018-07-21 18:49:10 +00:00
|
|
|
else:
|
|
|
|
await bot.say('{}, there are no locations within {} blocks of that point'
|
|
|
|
.format(ctx.message.author.mention, radius))
|
2018-07-23 00:26:21 +00:00
|
|
|
except InvalidDimError:
|
|
|
|
await bot.say('{}, {} is an invalid dimension.'.format(ctx.message.author.mention, dimension))
|
2018-05-26 14:26:24 +00:00
|
|
|
|
2018-06-23 20:27:00 +00:00
|
|
|
|
|
|
|
@bot.command(pass_context=True)
|
2018-07-29 14:29:27 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-08-01 01:16:14 +00:00
|
|
|
async def add_item(ctx, item_name: str, quantity: int, diamond_price: int, * args):
|
2018-06-23 21:51:00 +00:00
|
|
|
'''
|
2018-07-21 02:11:50 +00:00
|
|
|
Adds an item to a shop's inventory.
|
2018-07-21 20:08:26 +00:00
|
|
|
Quantity for Diamond Price.
|
2018-07-15 18:27:11 +00:00
|
|
|
|
2018-07-21 20:08:26 +00:00
|
|
|
?additem [Item Name] [Quantity] [Price] [Shop name]
|
2018-06-23 21:51:00 +00:00
|
|
|
'''
|
2018-08-01 01:16:14 +00:00
|
|
|
shop_name = get_name(args)
|
2018-06-30 15:07:56 +00:00
|
|
|
try:
|
2018-08-01 00:22:17 +00:00
|
|
|
bot_commands.add_item(item_name, quantity, diamond_price, shop_name=shop_name,
|
|
|
|
discord_uuid=ctx.message.author.id)
|
2018-07-24 01:12:23 +00:00
|
|
|
await bot.say('{}, **{}** has been added to the inventory of your shop.'.format(ctx.message.author.mention,
|
|
|
|
item_name))
|
2018-06-30 15:07:56 +00:00
|
|
|
except PlayerNotFound:
|
|
|
|
await bot.say('{}, you don\'t have any shops in the database.'.format(ctx.message.author.mention))
|
2018-07-21 20:08:26 +00:00
|
|
|
except LocationInitError:
|
|
|
|
await bot.say('{}, you have more than one shop in the database, please specify a shop name.'
|
|
|
|
.format(ctx.message.author.mention))
|
2018-06-30 15:07:56 +00:00
|
|
|
except LocationLookUpError:
|
|
|
|
await bot.say('{}, you don\'t have any shops named **{}** in the database.'.format(ctx.message.author.mention,
|
2018-07-22 23:56:07 +00:00
|
|
|
shop_name))
|
2018-07-22 01:44:43 +00:00
|
|
|
|
2018-06-23 20:27:00 +00:00
|
|
|
|
2018-07-29 14:29:27 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-06-23 20:27:00 +00:00
|
|
|
@bot.command(pass_context=True)
|
2018-07-21 05:06:00 +00:00
|
|
|
async def selling(ctx, item_name: str):
|
2018-06-23 21:51:00 +00:00
|
|
|
'''
|
|
|
|
Lists all the shops selling an item
|
2018-07-15 18:27:11 +00:00
|
|
|
|
|
|
|
?selling [item]
|
2018-06-23 21:51:00 +00:00
|
|
|
'''
|
2018-07-22 23:56:07 +00:00
|
|
|
try:
|
|
|
|
result = bot_commands.selling(item_name)
|
|
|
|
await bot.say('{}, the following shops sell **{}**: \n{}'.format(ctx.message.author.mention, item_name, result))
|
|
|
|
except ItemNotFound:
|
2018-07-29 14:29:27 +00:00
|
|
|
await bot.say('{}, no shop sells **{}**.'.format(ctx.message.author.mention, item_name))
|
2018-07-22 01:44:43 +00:00
|
|
|
|
2018-06-23 16:08:40 +00:00
|
|
|
|
2018-07-29 14:29:27 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
2018-07-01 15:10:10 +00:00
|
|
|
@bot.command(pass_context=True)
|
2018-07-21 22:25:18 +00:00
|
|
|
async def info(ctx, * args):
|
2018-07-01 15:10:10 +00:00
|
|
|
'''
|
2018-07-21 02:11:50 +00:00
|
|
|
Displays info about a location.
|
|
|
|
|
|
|
|
If the location is a shop, it displays the shop's inventory.
|
2018-07-15 18:27:11 +00:00
|
|
|
|
2018-07-21 01:50:24 +00:00
|
|
|
?info [Location Name]
|
2018-07-01 15:10:10 +00:00
|
|
|
'''
|
2018-08-01 01:16:14 +00:00
|
|
|
loc = get_name(args)
|
2018-07-21 03:10:13 +00:00
|
|
|
try:
|
2018-07-28 00:02:41 +00:00
|
|
|
|
|
|
|
if loc is None:
|
2018-07-22 23:56:07 +00:00
|
|
|
raise commands.UserInputError
|
|
|
|
|
2018-07-28 00:02:41 +00:00
|
|
|
info_str = bot_commands.info(loc)
|
2018-07-22 23:56:07 +00:00
|
|
|
await bot.say(info_str)
|
2018-07-21 03:10:13 +00:00
|
|
|
except IndexError:
|
2018-08-01 00:22:17 +00:00
|
|
|
await bot.say('{}, no locations in the database match {}.'.format(ctx.message.author.mention, loc))
|
2018-07-21 03:10:13 +00:00
|
|
|
return
|
2018-07-01 15:10:10 +00:00
|
|
|
|
2018-08-01 00:22:17 +00:00
|
|
|
|
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
|
|
|
@bot.command(pass_context=True)
|
|
|
|
async def edit_pos(ctx, x_pos: int, y_pos: int, * args):
|
|
|
|
'''
|
|
|
|
Edits the position of a location
|
|
|
|
|
|
|
|
?edit_pos [X Coordinate] [Z Coordinate] [Location Name]
|
|
|
|
'''
|
2018-08-01 01:16:14 +00:00
|
|
|
loc = get_name(args)
|
2018-08-01 00:22:17 +00:00
|
|
|
try:
|
|
|
|
loc_str = bot_commands.edit_pos(x_pos, y_pos, loc, discord_uuid=ctx.message.author.id)
|
|
|
|
|
|
|
|
await bot.say('{}, the following location has been updated: \n\n{}'.format(ctx.message.author.mention, loc_str))
|
|
|
|
except LocationLookUpError:
|
|
|
|
await bot.say('{}, you do not have a location called **{}**.'.format(
|
|
|
|
ctx.message.author.mention, loc))
|
|
|
|
|
|
|
|
|
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
|
|
|
@bot.command(pass_context=True)
|
|
|
|
async def edit_tunnel(ctx, tunnel_color: str, tunnel_number: int, * args):
|
|
|
|
'''
|
|
|
|
Edits the tunnel of a location
|
|
|
|
|
|
|
|
?edit_tunnel [Tunnel Color] [Tunnel Number] [Location Name]
|
|
|
|
'''
|
2018-08-01 01:16:14 +00:00
|
|
|
loc = get_name(args)
|
2018-08-01 00:22:17 +00:00
|
|
|
try:
|
|
|
|
loc_str = bot_commands.edit_tunnel(tunnel_color, tunnel_number, loc, discord_uuid=ctx.message.author.id)
|
|
|
|
|
|
|
|
await bot.say('{}, the following location has been updated: \n\n{}'.format(ctx.message.author.mention, loc_str))
|
|
|
|
except LocationLookUpError:
|
|
|
|
await bot.say('{}, you do not have a location called **{}**.'.format(
|
|
|
|
ctx.message.author.mention, loc))
|
2018-08-01 00:31:21 +00:00
|
|
|
except InvalidTunnelError:
|
2018-08-01 01:16:14 +00:00
|
|
|
await bot.say('{}, **{}** is an invalid tunnel color.'.format(ctx.message.author.mention, tunnel_color))
|
|
|
|
|
2018-08-01 00:22:17 +00:00
|
|
|
|
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
|
|
|
@bot.command(pass_context=True)
|
|
|
|
async def edit_name(ctx, new_name: str, current_name: str):
|
|
|
|
'''
|
|
|
|
Edits the name of a location
|
|
|
|
|
|
|
|
IF A NAME HAS SPACES IN IT YOU NEED TO WRAP IT IN QUOTATION MARKS. ie "Cool Shop 123"
|
|
|
|
?edit_name [New Name] [Current Name]
|
|
|
|
'''
|
|
|
|
try:
|
|
|
|
loc_str = bot_commands.edit_name(new_name, current_name, discord_uuid=ctx.message.author.id)
|
|
|
|
|
|
|
|
await bot.say('{}, the following location has been updated: \n\n{}'.format(ctx.message.author.mention, loc_str))
|
|
|
|
except LocationLookUpError:
|
|
|
|
await bot.say('{}, you do not have a location called **{}**.'.format(
|
|
|
|
ctx.message.author.mention, current_name))
|
|
|
|
|
|
|
|
|
2018-08-01 01:16:14 +00:00
|
|
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
|
|
|
@bot.command(pass_context=True)
|
|
|
|
async def delete_item(ctx, item: str, * args):
|
|
|
|
'''
|
|
|
|
Deletes an item listing from a shop inventory
|
|
|
|
|
|
|
|
?delete_name [Item] [Shop Name]
|
|
|
|
'''
|
|
|
|
|
|
|
|
shop = get_name(args)
|
|
|
|
try:
|
|
|
|
bot_commands.delete_item(item, shop, discord_uuid=ctx.message.author.id)
|
|
|
|
|
2018-08-01 01:23:35 +00:00
|
|
|
await bot.say('{}, **{}** has been removed from the inventory of **{}**.'.
|
|
|
|
format(ctx.message.author.mention, item, shop))
|
2018-08-01 01:16:14 +00:00
|
|
|
except LocationLookUpError:
|
|
|
|
await bot.say('{}, you do not have a shop called **{}**.'.format(ctx.message.author.mention, shop))
|
|
|
|
except DeleteEntryError:
|
2018-08-01 01:23:35 +00:00
|
|
|
await bot.say('{}, **{}** does not sell **{}**.'.format(ctx.message.author.mention, shop, item))
|
2018-08-01 01:16:14 +00:00
|
|
|
|
2018-07-01 15:10:10 +00:00
|
|
|
# Helper Functions ************************************************************
|
2018-06-23 16:08:40 +00:00
|
|
|
|
2018-07-28 00:02:41 +00:00
|
|
|
def get_name(args):
|
|
|
|
if len(args) > 0:
|
|
|
|
name = ' '.join(args)
|
|
|
|
else:
|
|
|
|
name = None
|
|
|
|
|
|
|
|
return name
|
2018-07-22 23:56:07 +00:00
|
|
|
|
2018-07-01 15:10:10 +00:00
|
|
|
def get_nickname(discord_user):
|
2018-06-23 16:08:40 +00:00
|
|
|
if discord_user.nick is None:
|
2018-06-30 15:07:56 +00:00
|
|
|
name = discord_user.display_name
|
2018-06-23 16:08:40 +00:00
|
|
|
else:
|
2018-06-30 15:07:56 +00:00
|
|
|
name = discord_user.nick
|
|
|
|
|
|
|
|
if name == 'dootb.in ꙩ ⃤':
|
|
|
|
name = 'aeskdar'
|
|
|
|
|
|
|
|
return name
|
2018-06-23 16:08:40 +00:00
|
|
|
|
|
|
|
|
2018-07-15 18:27:11 +00:00
|
|
|
def get_args_dict(args):
|
|
|
|
if len(args) != 0:
|
2018-08-01 00:22:17 +00:00
|
|
|
return dict(zip_longest(*[iter(args)] * 2, fillvalue=" "))
|
2018-07-15 18:27:11 +00:00
|
|
|
else:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
2018-07-23 02:51:22 +00:00
|
|
|
def update_user_names(bot_commands):
|
|
|
|
threading.Timer(600, update_user_names, [bot_commands]).start()
|
|
|
|
session = bot_commands.interface.database.Session()
|
2018-07-24 01:12:23 +00:00
|
|
|
print("Updating MC usernames...")
|
2018-07-23 02:51:22 +00:00
|
|
|
player_list = session.query(Player).all()
|
|
|
|
|
|
|
|
for player in player_list:
|
|
|
|
player.name = grab_playername(player.mc_uuid)
|
|
|
|
|
|
|
|
session.commit()
|
|
|
|
|
|
|
|
session.close()
|
|
|
|
|
|
|
|
|
2018-05-25 16:32:29 +00:00
|
|
|
# Bot Startup ******************************************************************
|
2018-06-23 16:08:40 +00:00
|
|
|
|
2018-07-21 18:28:31 +00:00
|
|
|
config = read_config()
|
2018-06-23 16:08:40 +00:00
|
|
|
|
2018-07-21 18:28:31 +00:00
|
|
|
TOKEN = config['Discord']['Token']
|
2018-06-30 15:53:27 +00:00
|
|
|
|
2018-07-21 18:28:31 +00:00
|
|
|
engine_arg = get_engine_arg(config)
|
2018-06-30 15:53:27 +00:00
|
|
|
|
2018-07-22 23:56:07 +00:00
|
|
|
bot_commands = Commands(engine_arg)
|
2018-07-15 15:56:56 +00:00
|
|
|
|
2018-07-23 02:51:22 +00:00
|
|
|
update_user_names(bot_commands)
|
|
|
|
|
2018-07-21 18:28:31 +00:00
|
|
|
bot.run(TOKEN)
|
2018-05-21 16:57:20 +00:00
|
|
|
|
2018-07-23 02:51:22 +00:00
|
|
|
|
2018-07-28 00:02:41 +00:00
|
|
|
|