2018-11-22 02:09:30 +00:00
|
|
|
from django.db.models import Q, F
|
|
|
|
from GeoffreyApp.models import *
|
2018-12-17 16:02:43 +00:00
|
|
|
from GeoffreyApp.errors import *
|
2018-12-15 22:00:45 +00:00
|
|
|
from GeoffreyApp.minecraft_api import *
|
2018-12-17 21:16:21 +00:00
|
|
|
import inspect
|
2019-01-04 21:09:44 +00:00
|
|
|
import datetime
|
2019-01-11 22:40:12 +00:00
|
|
|
import re
|
2019-08-16 17:00:26 +00:00
|
|
|
import enum
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
from GeoffreyApp.util import objects_list_to_json
|
2018-12-30 01:41:18 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
class RequestTypes(enum.Enum):
|
|
|
|
POST = "POST"
|
|
|
|
GET = "GET"
|
2018-12-30 01:41:18 +00:00
|
|
|
|
2019-01-14 20:22:18 +00:00
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
command_dict = {RequestTypes.GET: {}, RequestTypes.POST: {}}
|
|
|
|
|
|
|
|
|
|
|
|
class Command:
|
|
|
|
def __init__(self, func, permission_level, command_name=None):
|
|
|
|
self.func = func
|
|
|
|
self.params = self.get_required_args(func)
|
|
|
|
self.help = self.parse_help(func)
|
|
|
|
self.permission_level = permission_level
|
|
|
|
|
|
|
|
if command_name is None:
|
|
|
|
self.name = func.__name__
|
|
|
|
else:
|
|
|
|
self.name = command_name
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def parse_help(func):
|
|
|
|
try:
|
|
|
|
match = re.search(".*:help:.*", func.__doc__)
|
|
|
|
|
|
|
|
return match.group(0).partition(":help: ")[-1]
|
|
|
|
except:
|
|
|
|
return ' '
|
2019-01-14 20:22:18 +00:00
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_required_args(func):
|
|
|
|
args = inspect.getfullargspec(func)
|
2019-01-14 20:22:18 +00:00
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
return args.args + args.kwonlyargs
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@property
|
|
|
|
def json(self):
|
|
|
|
return {"command": self.name, "help": self.help, "permission_level": self.permission_level.name}
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-19 21:54:17 +00:00
|
|
|
def command(type, permission_level=PermissionLevel.PLAYER, command_name=None):
|
2018-12-17 21:16:21 +00:00
|
|
|
def command_dec(func):
|
|
|
|
def add_command():
|
2019-08-19 21:54:17 +00:00
|
|
|
command_obj = Command(func, permission_level, command_name=command_name)
|
|
|
|
command_dict[type][command_obj.name] = command_obj
|
2018-12-30 01:41:18 +00:00
|
|
|
return func
|
2019-08-16 17:00:26 +00:00
|
|
|
|
2018-12-17 21:16:21 +00:00
|
|
|
return add_command()
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2018-12-17 21:16:21 +00:00
|
|
|
return command_dec
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
def match_tunnel(tunnel_direction):
|
|
|
|
for direction in Tunnel.TUNNEL_NAMES:
|
|
|
|
if re.search("{}.*".format(tunnel_direction), direction[1], re.IGNORECASE):
|
|
|
|
return direction[0]
|
2019-01-27 18:43:30 +00:00
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
raise InvalidTunnelError
|
2019-01-27 18:43:30 +00:00
|
|
|
|
|
|
|
|
2019-08-19 21:54:17 +00:00
|
|
|
def get_player_by_name(mc_username):
|
|
|
|
try:
|
|
|
|
uuid = grab_UUID(mc_username)
|
|
|
|
return get_player(mc_uuid=uuid)
|
|
|
|
except UsernameLookupFailed:
|
|
|
|
raise PlayerNotFound
|
|
|
|
|
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
def get_player(discord_uuid=None, mc_uuid=None):
|
2019-01-11 22:40:12 +00:00
|
|
|
try:
|
2019-09-26 01:02:58 +00:00
|
|
|
discord_uuid = str(discord_uuid) if discord_uuid else None
|
|
|
|
mc_uuid = str(mc_uuid) if mc_uuid else None
|
2019-08-16 15:18:53 +00:00
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
if discord_uuid is not None:
|
|
|
|
player = Player.objects.get(discord_uuid__iexact=discord_uuid)
|
|
|
|
elif mc_uuid is not None:
|
|
|
|
player = Player.objects.get(mc_uuid__iexact=mc_uuid)
|
|
|
|
else:
|
|
|
|
raise AttributeError
|
|
|
|
except Player.DoesNotExist:
|
|
|
|
raise PlayerNotFound
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
return player
|
|
|
|
|
|
|
|
|
|
|
|
def get_location(owner, name=None, loc_type=Location):
|
|
|
|
if name is None:
|
2019-01-04 21:09:44 +00:00
|
|
|
loc_list = loc_type.objects.filter(owner=owner).all()
|
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
if len(loc_list) == 1:
|
|
|
|
loc = loc_list[0]
|
|
|
|
elif len(loc_list) == 0:
|
|
|
|
raise NoLocationsInDatabase
|
|
|
|
else:
|
|
|
|
raise EntryNameNotUniqueError
|
|
|
|
else:
|
2019-01-04 21:09:44 +00:00
|
|
|
loc_list = loc_type.objects.filter(owner=owner, name__iexact=name).all()
|
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
if len(loc_list) == 1:
|
|
|
|
loc = loc_list[0]
|
|
|
|
else:
|
|
|
|
raise LocationLookUpError
|
|
|
|
|
|
|
|
return loc
|
|
|
|
|
|
|
|
|
2019-01-02 23:17:53 +00:00
|
|
|
def add_location(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None, loc_type=Location):
|
|
|
|
player = get_player(discord_uuid, mc_uuid)
|
2019-02-17 03:13:53 +00:00
|
|
|
|
|
|
|
name_was_none = False
|
2019-02-03 15:01:06 +00:00
|
|
|
if name is None:
|
|
|
|
name = "{}'s {}".format(player.name, loc_type.__name__)
|
2019-02-17 03:13:53 +00:00
|
|
|
name_was_none = True
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2019-02-03 15:01:06 +00:00
|
|
|
if Location.objects.filter(name__iexact=name).all().count() > 0:
|
2019-02-17 03:13:53 +00:00
|
|
|
if name_was_none:
|
|
|
|
raise LocationLookUpError
|
|
|
|
else:
|
|
|
|
raise EntryNameNotUniqueError
|
2019-02-03 15:01:06 +00:00
|
|
|
else:
|
2019-01-31 20:07:25 +00:00
|
|
|
location = loc_type.objects.create(name=name, x_coord=x_pos, z_coord=z_pos)
|
|
|
|
location.owner.add(player)
|
|
|
|
location.save()
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
return location.json
|
2019-01-02 23:17:53 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2018-11-22 02:09:30 +00:00
|
|
|
def register(player_name, discord_uuid):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: POST
|
|
|
|
:param player_name: Minecraft in-game name
|
|
|
|
:param discord_uuid: Discord UUID if registering from Discord
|
|
|
|
:return: JSON representation of the new Player
|
2019-01-11 22:40:12 +00:00
|
|
|
:raise: PlayerInDBError
|
2019-01-02 23:17:53 +00:00
|
|
|
:help: Registers your Discord and Minecraft account with the the database
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
mc_uuid = grab_UUID(player_name)
|
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
try:
|
|
|
|
get_player(mc_uuid=mc_uuid)
|
|
|
|
raise PlayerInDBError
|
2019-01-11 22:42:23 +00:00
|
|
|
except PlayerNotFound:
|
2019-01-11 22:40:12 +00:00
|
|
|
player = Player.objects.create(name=player_name, mc_uuid=mc_uuid, discord_uuid=discord_uuid)
|
|
|
|
player.save()
|
|
|
|
return player.json
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2018-12-08 21:37:00 +00:00
|
|
|
def add_base(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: POST
|
|
|
|
:param x_pos: MC X Coordinate
|
|
|
|
:param z_pos: MC Z Coordinate
|
|
|
|
:param name: Base Name (If None, Defaults to Player's Base)
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
|
|
|
:return: JSON representation of the new base
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: EntryNameNotUniqueError, PlayerNotFound, LocationLookupError
|
2019-02-02 15:34:49 +00:00
|
|
|
:help: Adds your base to the database.
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2018-12-08 21:37:00 +00:00
|
|
|
return add_location(x_pos, z_pos, name=name, discord_uuid=discord_uuid, mc_uuid=mc_uuid, loc_type=Base)
|
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2018-12-08 21:37:00 +00:00
|
|
|
def add_shop(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: POST
|
|
|
|
:param x_pos: MC X Coordinate
|
|
|
|
:param z_pos: MC Z Coordinate
|
|
|
|
:param name: Shop Name (If None, Defaults to Player's Shop)
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
|
|
|
:return: JSON representation of the new shop
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: EntryNameNotUniqueError, PlayerNotFound, LocationLookupError
|
2019-02-17 03:13:53 +00:00
|
|
|
:help: Adds your shop to the database.
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-01-02 23:17:53 +00:00
|
|
|
return add_location(x_pos, z_pos, name=name, discord_uuid=discord_uuid, mc_uuid=mc_uuid, loc_type=Shop)
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2019-02-02 22:31:02 +00:00
|
|
|
def add_town(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-02-02 22:31:02 +00:00
|
|
|
:request: POST
|
|
|
|
:param x_pos: MC X Coordinate
|
|
|
|
:param z_pos: MC Z Coordinate
|
2019-05-11 16:46:30 +00:00
|
|
|
:param name: Town Name (If None, Defaults to Player's Town)
|
2019-02-02 22:31:02 +00:00
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
|
|
|
:return: JSON representation of the new town
|
|
|
|
:raises: EntryNameNotUniqueError, PlayerNotFound, LocationLookupError
|
2019-02-17 03:13:53 +00:00
|
|
|
:help: Adds your town to the database.
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-02-02 22:31:02 +00:00
|
|
|
|
|
|
|
return add_location(x_pos, z_pos, name=name, discord_uuid=discord_uuid, mc_uuid=mc_uuid, loc_type=Town)
|
|
|
|
|
2019-03-02 17:48:28 +00:00
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2019-03-02 17:48:28 +00:00
|
|
|
def add_farm(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-03-02 17:48:28 +00:00
|
|
|
:request: POST
|
|
|
|
:param x_pos: MC X Coordinate
|
|
|
|
:param z_pos: MC Z Coordinate
|
2019-05-11 16:46:30 +00:00
|
|
|
:param name: Farm Name (If None, Defaults to Player's Farm)
|
2019-03-02 17:48:28 +00:00
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
2019-05-11 16:46:30 +00:00
|
|
|
:return: JSON representation of the new farm
|
2019-03-02 17:48:28 +00:00
|
|
|
:raises: EntryNameNotUniqueError, PlayerNotFound, LocationLookupError
|
|
|
|
:help: Adds your public farm to the database.
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-03-02 17:48:28 +00:00
|
|
|
|
|
|
|
return add_location(x_pos, z_pos, name=name, discord_uuid=discord_uuid, mc_uuid=mc_uuid, loc_type=PublicFarm)
|
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2019-05-11 16:46:30 +00:00
|
|
|
def add_market(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None):
|
|
|
|
"""
|
|
|
|
:request: POST
|
|
|
|
:param x_pos: MC X Coordinate
|
|
|
|
:param z_pos: MC Z Coordinate
|
|
|
|
:param name: Market Name (If None, Defaults to Player's Market)
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
|
|
|
:return: JSON representation of the market
|
|
|
|
:raises: EntryNameNotUniqueError, PlayerNotFound, LocationLookupError
|
|
|
|
:help: Adds your market to the database.
|
|
|
|
"""
|
|
|
|
|
|
|
|
return add_location(x_pos, z_pos, name=name, discord_uuid=discord_uuid, mc_uuid=mc_uuid, loc_type=Market)
|
|
|
|
|
2019-03-02 17:48:28 +00:00
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2019-05-12 16:27:36 +00:00
|
|
|
def add_attraction(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None):
|
2019-05-12 16:23:59 +00:00
|
|
|
"""
|
|
|
|
:request: POST
|
|
|
|
:param x_pos: MC X Coordinate
|
|
|
|
:param z_pos: MC Z Coordinate
|
|
|
|
:param name: Market Name (If None, Defaults to Player's Attraction)
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
|
|
|
:return: JSON representation of the attraction
|
|
|
|
:raises: EntryNameNotUniqueError, PlayerNotFound, LocationLookupError
|
|
|
|
:help: Adds your attraction to the database.
|
|
|
|
"""
|
|
|
|
|
|
|
|
return add_location(x_pos, z_pos, name=name, discord_uuid=discord_uuid, mc_uuid=mc_uuid, loc_type=Attraction)
|
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2018-11-22 02:09:30 +00:00
|
|
|
def add_tunnel(tunnel_direction, tunnel_number, location_name=None, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: POST
|
|
|
|
:param tunnel_direction: Tunnel Direction
|
|
|
|
:param tunnel_number: Tunnel Coordinate
|
|
|
|
:param location_name: Name of the Location to attach the tunnel to
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
|
|
|
:return: JSON Representation of the Tunnel
|
2019-01-14 20:22:18 +00:00
|
|
|
:raises: PlayerNotFound, LocationHasTunnelError, EntryNameNotUniqueError, NoLocationsInDatabase, InvalidTunnelError
|
2019-02-02 15:34:49 +00:00
|
|
|
:help: Adds your tunnel to the database.
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-11-22 02:09:30 +00:00
|
|
|
player = get_player(discord_uuid, mc_uuid)
|
|
|
|
if location_name is None:
|
2019-01-11 22:40:12 +00:00
|
|
|
loc = get_location(player)
|
2018-11-22 02:09:30 +00:00
|
|
|
location_name = loc.name
|
2019-01-11 22:40:12 +00:00
|
|
|
else:
|
|
|
|
loc = get_location(player, name=location_name)
|
|
|
|
|
2019-01-14 20:22:18 +00:00
|
|
|
tunnel_direction = match_tunnel(tunnel_direction)
|
2019-01-11 22:40:12 +00:00
|
|
|
|
|
|
|
if Tunnel.objects.filter(location=loc).first():
|
|
|
|
raise LocationHasTunnelError
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2018-12-18 18:13:14 +00:00
|
|
|
tunnel = Tunnel.objects.create(tunnel_direction=tunnel_direction, tunnel_number=tunnel_number,
|
|
|
|
location=get_location(player, location_name))
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
return tunnel.json
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.GET)
|
2019-01-11 22:40:12 +00:00
|
|
|
def find_location(search, limit=25):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: GET
|
|
|
|
:param search: Location name or owner to search for
|
2019-01-11 22:40:12 +00:00
|
|
|
:param limit: How man locations to return
|
2019-01-02 23:17:53 +00:00
|
|
|
:return: List of the matching locations
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: LocationLookupError
|
2019-01-02 23:17:53 +00:00
|
|
|
:help: Finds all the locations matching the search term
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
locations = Location.objects.filter(Q(name__icontains=search) | Q(owner__name__icontains=search)).all()[:limit]
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
if len(locations) == 0:
|
2018-11-22 02:09:30 +00:00
|
|
|
raise LocationLookUpError
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
return objects_list_to_json(locations)
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2018-11-22 02:09:30 +00:00
|
|
|
def delete(name, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-14 20:22:18 +00:00
|
|
|
:request: POST
|
2019-01-02 23:17:53 +00:00
|
|
|
:param name: Name of location to delete
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
|
|
|
:return: Location Name
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: LocationLookUpError
|
2019-01-02 23:17:53 +00:00
|
|
|
:help: Deletes a location from the database
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
owner = get_player(discord_uuid, mc_uuid)
|
2019-01-11 22:40:12 +00:00
|
|
|
try:
|
2019-08-16 15:18:53 +00:00
|
|
|
if Location.objects.get(name__iexact=name, owner=owner).delete() == 0:
|
|
|
|
raise Location.DoesNotExist
|
2019-01-11 22:40:12 +00:00
|
|
|
except Location.DoesNotExist:
|
|
|
|
raise LocationLookUpError
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
return name
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-02-02 15:34:49 +00:00
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.GET)
|
2018-11-22 02:09:30 +00:00
|
|
|
def find_around(x_pos, z_pos, radius=200):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: GET
|
|
|
|
:param x_pos: MC X Coordinate
|
|
|
|
:param z_pos: MC Z Coordinate
|
|
|
|
:param radius: Radius to each around (default 200)
|
|
|
|
:return: List of all locations in the radius
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: LocationLookupError
|
2019-01-02 23:17:53 +00:00
|
|
|
:help: Finds all the locations around a certain point
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2019-01-14 20:22:18 +00:00
|
|
|
x_pos = int(x_pos)
|
|
|
|
z_pos = int(z_pos)
|
|
|
|
radius = int(radius)
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
locations = Location.objects.filter(x_coord__range=(x_pos - radius, x_pos + radius),
|
|
|
|
z_coord__range=(z_pos - radius, z_pos + radius)).all()
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
if len(locations) == 0:
|
|
|
|
raise LocationLookUpError
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
return objects_list_to_json(locations)
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2018-11-22 02:09:30 +00:00
|
|
|
def add_item(item_name, quantity, diamond_price, shop_name=None, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: POST
|
|
|
|
:param item_name: name of the item
|
|
|
|
:param quantity: number of items being sold
|
|
|
|
:param diamond_price: price in diamonds
|
|
|
|
:param shop_name: Name of the shop, can be blank if the user only has one shop
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
|
|
|
:return: Item Listing
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: PlayerNotFound, LocationLookupError, EntryNameNotUniqueError, NoLocationsInDatabase
|
2019-02-17 03:13:53 +00:00
|
|
|
:help: Adds an item to a shop's inventory.
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
player = get_player(discord_uuid, mc_uuid)
|
|
|
|
|
2018-12-18 18:13:14 +00:00
|
|
|
shop = get_location(player, shop_name, Shop).shop
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
item_listing = ItemListing.objects.create(shop=shop, amount=int(quantity), price=int(diamond_price),
|
|
|
|
item_name=item_name)
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
return item_listing.json
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2019-03-02 17:48:28 +00:00
|
|
|
def add_resource(resource_name, farm_name=None, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-03-02 17:48:28 +00:00
|
|
|
:request: POST
|
|
|
|
:param resource_name: name of the resource
|
2019-03-22 14:41:50 +00:00
|
|
|
:param farm_name: name of the farm to add the resource to. Can be none.
|
2019-03-02 17:48:28 +00:00
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
|
|
|
:return: Item Listing
|
|
|
|
:raises: PlayerNotFound, LocationLookupError, EntryNameNotUniqueError, NoLocationsInDatabase
|
|
|
|
:help: Adds a resource to a farm.
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-03-02 17:48:28 +00:00
|
|
|
|
|
|
|
player = get_player(discord_uuid, mc_uuid)
|
|
|
|
|
|
|
|
farm = get_location(player, farm_name, PublicFarm).publicfarm
|
|
|
|
|
|
|
|
resource = Resource.objects.create(farm=farm, resource_name=resource_name)
|
|
|
|
|
|
|
|
return resource.json
|
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.GET)
|
2019-03-02 17:48:28 +00:00
|
|
|
def find_farm(resource_name):
|
2019-05-11 16:46:30 +00:00
|
|
|
"""
|
|
|
|
:request: GET
|
|
|
|
:param resource_name: Resource to search for
|
|
|
|
:return: List of top matching farms
|
|
|
|
:raises: ResourceNotFoundError
|
|
|
|
:help: Lists farms that produce an object
|
|
|
|
"""
|
2019-03-02 17:48:28 +00:00
|
|
|
if len(resource_name) == 0:
|
|
|
|
raise EmptryString
|
|
|
|
|
2019-05-14 22:38:12 +00:00
|
|
|
farms = PublicFarm.objects.filter(resource__resource_name__icontains=resource_name).all()[:10]
|
|
|
|
|
|
|
|
if len(farms) == 0:
|
|
|
|
raise ResourceNotFoundError
|
|
|
|
|
|
|
|
return objects_list_to_json(farms)
|
2019-03-02 17:48:28 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.GET)
|
2019-02-16 21:58:58 +00:00
|
|
|
def selling(item_name):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: GET
|
|
|
|
:param item_name: Item name to search for
|
2019-05-11 16:46:30 +00:00
|
|
|
:return: List of top matching shops, sorted by the date last restocke
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: ItemNotFound
|
2019-02-16 21:58:58 +00:00
|
|
|
:help: Lists shops selling an item. Sorted by when they were last restocked.
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-02-16 21:58:58 +00:00
|
|
|
return get_selling(item_name, sort="-date_restocked")
|
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.GET)
|
2019-02-17 03:13:53 +00:00
|
|
|
def selling_price(item_name):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-02-16 21:58:58 +00:00
|
|
|
:request: GET
|
|
|
|
:param item_name: Item name to search for
|
|
|
|
:return: List of top matching shops, sorted by the
|
|
|
|
:raises: ItemNotFound
|
|
|
|
:help: Lists shops selling an item. Sorted lowest price to highest price.
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-02-16 21:58:58 +00:00
|
|
|
|
2019-02-17 03:13:53 +00:00
|
|
|
return get_selling(item_name, sort="normalized_price")
|
2019-02-16 21:58:58 +00:00
|
|
|
|
|
|
|
|
2019-02-17 03:13:53 +00:00
|
|
|
def get_selling(item_name, sort):
|
2019-01-02 23:17:53 +00:00
|
|
|
items = []
|
|
|
|
if len(item_name) == 0:
|
|
|
|
raise EmptryString
|
2018-12-14 01:58:59 +00:00
|
|
|
|
2019-09-26 01:02:58 +00:00
|
|
|
all_shop_ids = ItemListing.objects.filter(item_name__icontains=item_name).annotate(normalized_price=F('price') / F('amount')).order_by(sort).values("shop_id").all()
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-09-26 01:02:58 +00:00
|
|
|
if all_shop_ids.count() == 0:
|
2019-01-02 23:17:53 +00:00
|
|
|
raise ItemNotFound
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2019-01-04 21:09:44 +00:00
|
|
|
# Removes duplicates
|
2019-02-17 03:13:53 +00:00
|
|
|
shop_ids = []
|
|
|
|
|
|
|
|
for shop_id in all_shop_ids:
|
|
|
|
if shop_id not in shop_ids:
|
|
|
|
shop_ids.append(shop_id)
|
2019-01-04 20:18:56 +00:00
|
|
|
|
2019-02-17 03:13:53 +00:00
|
|
|
for shop_id in shop_ids:
|
2019-01-02 23:17:53 +00:00
|
|
|
shop = Shop.objects.get(pk=shop_id['shop_id']).json
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2019-07-21 15:28:25 +00:00
|
|
|
item_query = ItemListing.objects.filter(
|
2019-09-26 01:02:58 +00:00
|
|
|
item_name__icontains=item_name, shop_id=shop_id['shop_id']).order_by("-date_restocked")
|
2018-12-14 01:58:59 +00:00
|
|
|
|
2019-01-02 23:17:53 +00:00
|
|
|
item_list = []
|
|
|
|
for item in item_query:
|
|
|
|
item_list.append(item)
|
2018-12-08 21:37:00 +00:00
|
|
|
|
2019-07-21 15:28:25 +00:00
|
|
|
shop["items"] = objects_list_to_json(item_list)
|
2019-01-02 23:17:53 +00:00
|
|
|
items.append(shop)
|
|
|
|
|
|
|
|
return items
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.GET)
|
2018-11-22 02:09:30 +00:00
|
|
|
def info(location_name):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: GET
|
|
|
|
:param location_name: Name of the location to get info on
|
|
|
|
:return: JSON representation of location
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: LocationLookupError
|
2019-01-02 23:17:53 +00:00
|
|
|
:help: Finds all the locations matching the search term
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2019-01-14 20:22:18 +00:00
|
|
|
location = Location.objects.filter(name__iexact=location_name).first()
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
if location is None:
|
2019-01-14 20:22:18 +00:00
|
|
|
location = Location.objects.filter(name__iregex=".*{}.*".format(location_name)).first()
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
if location is not None:
|
2019-02-17 03:13:53 +00:00
|
|
|
loc = location.loc_child_obj
|
|
|
|
loc_json = loc.json
|
|
|
|
|
|
|
|
if type(loc) == Shop:
|
|
|
|
loc_json["items"] = []
|
|
|
|
for item in loc.shop_selling.all():
|
|
|
|
loc_json["items"].append(item.json)
|
2019-05-11 15:47:49 +00:00
|
|
|
elif type(loc) == PublicFarm:
|
|
|
|
loc_json["resources"] = []
|
2019-05-11 16:21:00 +00:00
|
|
|
for resource in loc.resource.all():
|
2019-05-11 15:47:49 +00:00
|
|
|
loc_json["resources"].append(resource.json)
|
2019-02-17 03:13:53 +00:00
|
|
|
|
|
|
|
return loc_json
|
2018-12-18 18:13:14 +00:00
|
|
|
else:
|
|
|
|
raise LocationLookUpError
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.GET)
|
2018-11-22 02:09:30 +00:00
|
|
|
def tunnel(player_name):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: GET
|
|
|
|
:param player_name: MC player name
|
|
|
|
:return: List of all the tunnels a user owns
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: LocationLookUpError
|
|
|
|
:raises: LocationLookupError
|
2019-01-02 23:17:53 +00:00
|
|
|
:help: Finds all the tunnels a player owns
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
tunnels = Tunnel.objects.filter(location__owner__name__icontains=player_name).all()
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
if len(tunnels) == 0:
|
2018-11-22 02:09:30 +00:00
|
|
|
raise LocationLookUpError
|
|
|
|
|
2019-01-04 17:20:24 +00:00
|
|
|
return objects_list_to_json(tunnels)
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2018-11-22 02:09:30 +00:00
|
|
|
def edit_pos(x, z, loc_name, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: POST
|
|
|
|
:param x: New MC X coordinate
|
|
|
|
:param z: New MC Z Coordinate
|
|
|
|
:param loc_name: Location Name to edit
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: MC UUID
|
2019-09-26 15:22:55 +00:00
|
|
|
:return: Edited Location
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises:
|
|
|
|
:raises: PlayerNotFound, LocationLookupError, EntryNameNotUniqueError, NoLocationsInDatabase
|
2019-01-02 23:17:53 +00:00
|
|
|
:help: Edits the position of a location
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
player = get_player(discord_uuid=discord_uuid, mc_uuid=mc_uuid)
|
|
|
|
location = get_location(player, loc_name)
|
|
|
|
|
2018-12-18 18:13:14 +00:00
|
|
|
location.x_coord = x
|
|
|
|
location.z_coord = z
|
2018-11-22 02:09:30 +00:00
|
|
|
location.save()
|
|
|
|
|
2019-01-04 17:20:24 +00:00
|
|
|
return location.json
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2018-11-22 02:09:30 +00:00
|
|
|
def edit_tunnel(tunnel_direction, tunnel_number, loc_name, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: POST
|
|
|
|
:param tunnel_direction: New Tunnel Direction
|
|
|
|
:param tunnel_number: New Tunnel Address
|
|
|
|
:param loc_name: Location Name to edit
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
|
|
|
:return: Edited Location
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: PlayerNotFound, LocationLookupError, EntryNameNotUniqueError, NoLocationsInDatabase
|
2019-01-02 23:17:53 +00:00
|
|
|
:help: Edits the tunnel of a location
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
player = get_player(discord_uuid=discord_uuid, mc_uuid=mc_uuid)
|
|
|
|
location = get_location(player, loc_name)
|
2019-01-14 20:22:18 +00:00
|
|
|
tunnel_direction = match_tunnel(tunnel_direction)
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-01-14 20:22:18 +00:00
|
|
|
try:
|
|
|
|
tunnel = Tunnel.objects.get(location=location)
|
|
|
|
tunnel.tunnel_direction = tunnel_direction
|
|
|
|
tunnel.tunnel_number = tunnel_number
|
|
|
|
tunnel.save()
|
|
|
|
except Tunnel.DoesNotExist:
|
2018-11-22 02:09:30 +00:00
|
|
|
Tunnel.objects.create(tunnel_direction=tunnel_direction, tunnel_number=tunnel_number, location=location)
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
return location.json
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2018-11-22 02:09:30 +00:00
|
|
|
def edit_name(new_name, loc_name, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: POST
|
|
|
|
:param new_name: New Location Name
|
|
|
|
:param loc_name: Old Location name
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: MC UUID
|
|
|
|
:return: Edited Location
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: PlayerNotFound, LocationLookupError, EntryNameNotUniqueError, NoLocationsInDatabase
|
2019-01-02 23:17:53 +00:00
|
|
|
:help: Edits the name of a location
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
player = get_player(discord_uuid=discord_uuid, mc_uuid=mc_uuid)
|
2019-01-14 20:22:18 +00:00
|
|
|
|
|
|
|
if Location.objects.filter(name__iexact=new_name).count():
|
|
|
|
raise EntryNameNotUniqueError
|
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
location = get_location(player, loc_name)
|
|
|
|
|
|
|
|
location.name = new_name
|
|
|
|
location.save()
|
2018-12-30 01:41:18 +00:00
|
|
|
return location.json
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2019-01-04 21:09:44 +00:00
|
|
|
def delete_item(item, shop_name=None, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-14 20:22:18 +00:00
|
|
|
:request: POST
|
2019-01-02 23:17:53 +00:00
|
|
|
:param item: Item name to delete
|
|
|
|
:param shop_name: Shop selling item, can be None if the user only has one shop
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
2019-01-14 20:22:18 +00:00
|
|
|
:return: Shop where the item was deleted from
|
|
|
|
:raises: PlayerNotFound, LocationLookupError, EntryNameNotUniqueError, NoLocationsInDatabase, ItemNotFound
|
2019-01-11 22:40:12 +00:00
|
|
|
:help: Deletes an item from a shop
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
player = get_player(discord_uuid=discord_uuid, mc_uuid=mc_uuid)
|
|
|
|
|
|
|
|
shop = get_location(player, shop_name, Shop)
|
|
|
|
|
2019-01-14 20:22:18 +00:00
|
|
|
delete_list = ItemListing.objects.filter(item_name__iexact=item, shop=shop).all()
|
|
|
|
|
|
|
|
if len(delete_list) == 0:
|
|
|
|
raise ItemNotFound
|
|
|
|
|
|
|
|
delete_list.delete()
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
return shop.json
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2019-09-26 15:22:55 +00:00
|
|
|
def delete_resource(resource, farm_name=None, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-03-02 17:48:28 +00:00
|
|
|
:request: POST
|
|
|
|
:param resource: resource to delete
|
|
|
|
:param farm_name: Farm with resource, can be None if the user only has one farm
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
|
|
|
:return: PublicFarm where the resource was deleted from
|
|
|
|
:raises: PlayerNotFound, LocationLookupError, EntryNameNotUniqueError, NoLocationsInDatabase, ItemNotFound
|
|
|
|
:help: Deletes a resource from a farm
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-03-02 17:48:28 +00:00
|
|
|
|
|
|
|
player = get_player(discord_uuid=discord_uuid, mc_uuid=mc_uuid)
|
|
|
|
|
|
|
|
farm = get_location(player, farm_name, PublicFarm)
|
|
|
|
|
2019-09-26 15:22:55 +00:00
|
|
|
delete_list = Resource.objects.filter(resource_name=resource, farm=farm).all()
|
2019-03-02 17:48:28 +00:00
|
|
|
|
|
|
|
if len(delete_list) == 0:
|
|
|
|
raise ResourceNotFoundError
|
|
|
|
|
|
|
|
delete_list.delete()
|
|
|
|
|
|
|
|
return farm.json
|
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.GET)
|
2018-11-22 02:09:30 +00:00
|
|
|
def me(discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
:request: GET
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: MC UUID
|
|
|
|
:return: Returns a list of all the locations owned by a user
|
2019-01-11 22:40:12 +00:00
|
|
|
:raises: NoLocationsInDatabase, PlayerNotFound
|
2019-01-02 23:17:53 +00:00
|
|
|
:help: Find all the locations in the database
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-02 23:17:53 +00:00
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
try:
|
|
|
|
player = get_player(discord_uuid=discord_uuid, mc_uuid=mc_uuid)
|
|
|
|
except Player.DoesNotExist:
|
|
|
|
raise PlayerNotFound
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
locations = Location.objects.filter(owner=player).all()
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
if len(locations) == 0:
|
2019-01-11 22:40:12 +00:00
|
|
|
raise NoLocationsInDatabase
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
return objects_list_to_json(locations)
|
2019-01-04 21:09:44 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2019-01-04 21:09:44 +00:00
|
|
|
def restock(item_name, shop_name=None, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-04 21:09:44 +00:00
|
|
|
:request: POST
|
|
|
|
:param item_name: Item to restock
|
|
|
|
:param shop_name: Shop the item is in, can be none if the only one location is owned by the user
|
|
|
|
:param discord_uuid: Discord UUID
|
|
|
|
:param mc_uuid: Minecraft UUID
|
2019-01-06 21:23:54 +00:00
|
|
|
:return: List of items updated
|
2019-01-14 20:22:18 +00:00
|
|
|
:raises: PlayerNotFound, LocationLookupError, EntryNameNotUniqueError, NoLocationsInDatabase, ItemNotFound
|
2019-01-06 21:23:54 +00:00
|
|
|
:help: Restocks items matching the item name in your shop
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-04 21:09:44 +00:00
|
|
|
owner = get_player(discord_uuid, mc_uuid)
|
|
|
|
shop = get_location(owner, shop_name, Shop)
|
|
|
|
|
|
|
|
items = ItemListing.objects.filter(item_name__iexact=item_name, shop=shop).all()
|
|
|
|
|
2019-01-14 20:22:18 +00:00
|
|
|
if len(items) == 0:
|
|
|
|
raise ItemNotFound
|
|
|
|
else:
|
|
|
|
for item in items:
|
|
|
|
item.date_restocked = datetime.datetime.now()
|
|
|
|
item.save()
|
2019-01-06 21:23:54 +00:00
|
|
|
|
|
|
|
return objects_list_to_json(items)
|
2019-02-02 15:34:49 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2019-02-02 15:34:49 +00:00
|
|
|
def add_owner(new_owner_name, location_name, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-02-02 15:34:49 +00:00
|
|
|
:request: POST
|
|
|
|
:param new_owner_name: The MC username of the new owner
|
|
|
|
:param location_name: The name of the location to add them to
|
|
|
|
:param discord_uuid: Discord UUID of the current owner
|
|
|
|
:param mc_uuid: MC UUID of the current owner
|
2019-02-02 22:31:02 +00:00
|
|
|
:return: Update Location
|
|
|
|
:raises: PlayerNotFound, LocationLookupError, IsOwnerError, OwnerNotFound
|
2019-02-02 16:27:10 +00:00
|
|
|
:help: Adds a co-owner to a location
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-02-02 15:34:49 +00:00
|
|
|
owner = get_player(discord_uuid, mc_uuid)
|
|
|
|
|
|
|
|
try:
|
|
|
|
new_owner = Player.objects.get(name__iexact=new_owner_name)
|
|
|
|
except Player.DoesNotExist:
|
2019-02-02 22:31:02 +00:00
|
|
|
raise OwnerNotFoundError
|
2019-02-02 15:34:49 +00:00
|
|
|
|
|
|
|
location = get_location(owner, location_name, Location)
|
|
|
|
|
2019-09-26 15:22:55 +00:00
|
|
|
if location.owner.filter(id=new_owner.id):
|
2019-02-02 22:31:02 +00:00
|
|
|
raise IsOwnerError
|
2019-02-02 16:21:44 +00:00
|
|
|
|
2019-02-02 15:34:49 +00:00
|
|
|
location.owner.add(new_owner)
|
|
|
|
|
|
|
|
location.save()
|
|
|
|
|
|
|
|
return location.json
|
2019-02-02 22:31:02 +00:00
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2019-02-02 22:31:02 +00:00
|
|
|
def add_resident(new_resident_name, town_name, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-02-02 22:31:02 +00:00
|
|
|
:request: POST
|
|
|
|
:param new_resident_name: The MC username of the new resident
|
|
|
|
:param town_name: The name of the town to add the resident to, can be blank if the owner has one town
|
|
|
|
:param discord_uuid: Discord UUID of the town owner
|
|
|
|
:param mc_uuid: MC UUID of the town owner
|
|
|
|
:return: Updated Location
|
|
|
|
:raises: PlayerNotFound, LocationLookupError, IsResidentError, ResidentNotFoundError
|
|
|
|
:help: Adds a resident to a town
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-02-02 22:31:02 +00:00
|
|
|
owner = get_player(discord_uuid, mc_uuid)
|
|
|
|
|
|
|
|
try:
|
|
|
|
new_resident = Player.objects.get(name__iexact=new_resident_name)
|
|
|
|
except Player.DoesNotExist:
|
|
|
|
raise ResidentNotFoundError
|
|
|
|
|
|
|
|
town = get_location(owner, town_name, Town)
|
|
|
|
|
2019-09-26 01:13:57 +00:00
|
|
|
if town.residents.filter(id=new_resident.id).exists() | town.owner.filter(id=new_resident.id).exists():
|
2019-02-02 22:31:02 +00:00
|
|
|
raise IsResidentError
|
|
|
|
|
|
|
|
town.residents.add(new_resident)
|
|
|
|
|
|
|
|
town.save()
|
|
|
|
|
|
|
|
return town.json
|
|
|
|
|
|
|
|
|
2019-08-16 17:00:26 +00:00
|
|
|
@command(RequestTypes.POST)
|
2019-02-02 22:31:02 +00:00
|
|
|
def remove_resident(resident_name, town_name, discord_uuid=None, mc_uuid=None):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-02-02 22:31:02 +00:00
|
|
|
:request: POST
|
|
|
|
:param resident_name: Name of the resident to remove
|
|
|
|
:param town_name: Name of the town, can be blank if the owner has one town
|
|
|
|
:param discord_uuid: Owner discord uuid
|
|
|
|
:param mc_uuid: Owner mc uuid
|
2019-02-16 21:58:58 +00:00
|
|
|
:raises: PlayerNotFound, LocationLookupError, ResidentNotFoundError
|
2019-02-02 22:31:02 +00:00
|
|
|
:return: Updated town
|
2019-02-06 20:54:50 +00:00
|
|
|
:help: Removes a resident from a town
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-02-02 22:31:02 +00:00
|
|
|
|
|
|
|
owner = get_player(discord_uuid, mc_uuid)
|
|
|
|
town = get_location(owner, town_name, Town)
|
|
|
|
try:
|
2019-02-17 03:13:53 +00:00
|
|
|
resident = town.residents.get(name__iexact=resident_name)
|
2019-02-02 22:31:02 +00:00
|
|
|
except Player.DoesNotExist:
|
|
|
|
raise ResidentNotFoundError
|
|
|
|
|
|
|
|
town.residents.remove(resident)
|
|
|
|
|
|
|
|
town.save()
|
|
|
|
return town.json
|
2019-08-19 21:54:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
@command(RequestTypes.POST, permission_level=PermissionLevel.MOD)
|
|
|
|
def mod_delete(player_name, location_name):
|
|
|
|
uuid = grab_UUID(player_name)
|
|
|
|
delete(location_name, mc_uuid=uuid)
|
|
|
|
|
|
|
|
|
|
|
|
@command(RequestTypes.POST, permission_level=PermissionLevel.MOD)
|
|
|
|
def mod_delete_item(player_name, item_name, shop_name):
|
|
|
|
uuid = grab_UUID(player_name)
|
|
|
|
delete_item(item_name, shop_name=shop_name, mc_uuid=uuid)
|
|
|
|
|
|
|
|
|
|
|
|
@command(RequestTypes.POST, permission_level=PermissionLevel.MOD)
|
|
|
|
def mod_edit_name(player_name, new_name, loc_name):
|
|
|
|
uuid = grab_UUID(player_name)
|
|
|
|
edit_name(new_name, loc_name, mc_uuid=uuid)
|
|
|
|
|
|
|
|
|
|
|
|
@command(RequestTypes.POST, permission_level=PermissionLevel.MOD)
|
|
|
|
def mod_remove_resident(player_name, resident_name, town_name):
|
|
|
|
uuid = grab_UUID(player_name)
|
|
|
|
remove_resident(resident_name, town_name, mc_uuid=uuid)
|
|
|
|
|
|
|
|
|
|
|
|
@command(RequestTypes.POST, permission_level=PermissionLevel.MOD)
|
|
|
|
def mod_remove_owner(player_name, loc_name):
|
|
|
|
uuid = grab_UUID(player_name)
|
|
|
|
owner = get_player(mc_uuid=uuid)
|
|
|
|
|
|
|
|
location = get_location(owner, loc_name)
|
|
|
|
location.owner.remove(owner)
|