Removed y coord from all commands and fixed test cases to match new changes
parent
fc95d3d986
commit
ba5da981b4
|
@ -3,7 +3,7 @@ import enum
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from BotErrors import *
|
from BotErrors import *
|
||||||
from sqlalchemy import create_engine, exists, literal
|
from sqlalchemy import create_engine, exists, literal
|
||||||
from sqlalchemy.orm import sessionmaker, relationship
|
from sqlalchemy.orm import sessionmaker, relationship, column_property
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
from MinecraftAccountInfoGrabber import *
|
from MinecraftAccountInfoGrabber import *
|
||||||
|
@ -26,13 +26,13 @@ class DatabaseInterface:
|
||||||
def __init__(self, db_engine_arg):
|
def __init__(self, db_engine_arg):
|
||||||
self.database = GeoffreyDatabase(db_engine_arg)
|
self.database = GeoffreyDatabase(db_engine_arg)
|
||||||
|
|
||||||
def add_location(self, owner, name, x_pos, y_pos, z_pos, dimension=None):
|
def add_location(self, owner, name, x_pos, z_pos, dimension=None):
|
||||||
location = Location(name, x_pos, y_pos, z_pos, owner, dimension)
|
location = Location(name, x_pos, z_pos, owner, dimension)
|
||||||
self.database.add_object(location)
|
self.database.add_object(location)
|
||||||
return location
|
return location
|
||||||
|
|
||||||
def add_shop(self, owner, name, x_pos, y_pos, z_pos, dimension=None):
|
def add_shop(self, owner, name, x_pos, z_pos, dimension=None):
|
||||||
shop = Shop(name, x_pos, y_pos, z_pos, owner, dimension)
|
shop = Shop(name, x_pos, z_pos, owner, dimension)
|
||||||
self.database.add_object(shop)
|
self.database.add_object(shop)
|
||||||
return shop
|
return shop
|
||||||
|
|
||||||
|
@ -183,13 +183,13 @@ class DatabaseInterface:
|
||||||
|
|
||||||
|
|
||||||
class DiscordDatabaseInterface(DatabaseInterface):
|
class DiscordDatabaseInterface(DatabaseInterface):
|
||||||
def add_location(self, owner_uuid, name, x_pos, y_pos, z_pos, dimension=None):
|
def add_location(self, owner_uuid, name, x_pos, z_pos, dimension=None):
|
||||||
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
||||||
return DatabaseInterface.add_location(self, owner, name, x_pos, y_pos, z_pos, dimension)
|
return DatabaseInterface.add_location(self, owner, name, x_pos, z_pos, dimension)
|
||||||
|
|
||||||
def add_shop(self, owner_uuid, name, x_pos, y_pos, z_pos, dimension=None):
|
def add_shop(self, owner_uuid, name, x_pos, z_pos, dimension=None):
|
||||||
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
||||||
return DatabaseInterface.add_shop(self, owner, name, x_pos, y_pos, z_pos, dimension)
|
return DatabaseInterface.add_shop(self, owner, name, x_pos, z_pos, dimension)
|
||||||
|
|
||||||
def add_tunnel(self, owner_uuid, color, number, location_name=""):
|
def add_tunnel(self, owner_uuid, color, number, location_name=""):
|
||||||
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
||||||
|
@ -372,11 +372,10 @@ class Location(SQL_Base):
|
||||||
'polymorphic_identity': 'Location'
|
'polymorphic_identity': 'Location'
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, name, x, y, z, owner, dimension):
|
def __init__(self, name, x, z, owner, dimension):
|
||||||
try:
|
try:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
|
||||||
self.z = z
|
self.z = z
|
||||||
self.owner = owner
|
self.owner = owner
|
||||||
|
|
||||||
|
@ -389,7 +388,7 @@ class Location(SQL_Base):
|
||||||
raise LocationInitError
|
raise LocationInitError
|
||||||
|
|
||||||
def pos_to_str(self):
|
def pos_to_str(self):
|
||||||
return '(x= {}, y= {}, z= {}) in the {}'.format(self.x, self.y, self.z, self.dimension.value.title())
|
return '(x= {}, z= {}) in the {}'.format(self.x, self.z, self.dimension.value.title())
|
||||||
|
|
||||||
def info_str(self):
|
def info_str(self):
|
||||||
return "Name: **{}**, Type: **{}** Position: **{}**".format(self.name, self.type, self.pos_to_str())
|
return "Name: **{}**, Type: **{}** Position: **{}**".format(self.name, self.type, self.pos_to_str())
|
||||||
|
@ -401,19 +400,21 @@ class Location(SQL_Base):
|
||||||
if self.tunnel is not None:
|
if self.tunnel is not None:
|
||||||
return "{}, Tunnel: **{}**".format(self.info_str(), self.tunnel)
|
return "{}, Tunnel: **{}**".format(self.info_str(), self.tunnel)
|
||||||
else:
|
else:
|
||||||
return self.info_str(self)
|
return self.info_str()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Shop(Location):
|
class Shop(Location):
|
||||||
__tablename__ = 'Shops'
|
__tablename__ = 'Shops'
|
||||||
shop_id = Column(Integer, ForeignKey('Locations.id'), primary_key=True)
|
shop_id = Column(Integer, ForeignKey('Locations.id'), primary_key=True)
|
||||||
name = Column(String)
|
name = column_property(Column(String), Location.name)
|
||||||
inventory = relationship('ItemListing', back_populates='shop', lazy='dynamic')
|
inventory = relationship('ItemListing', back_populates='shop', lazy='dynamic')
|
||||||
__mapper_args__ = {
|
__mapper_args__ = {
|
||||||
'polymorphic_identity': 'Shop',
|
'polymorphic_identity': 'Shop',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
column_property()
|
||||||
|
|
||||||
def inv_to_str(self):
|
def inv_to_str(self):
|
||||||
|
|
||||||
if len(self.inventory.all()) != 0:
|
if len(self.inventory.all()) != 0:
|
||||||
|
@ -433,8 +434,8 @@ class Shop(Location):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return Location.__str__(self)
|
return Location.__str__(self)
|
||||||
|
|
||||||
def __init__(self, name, x, y, z, owner, dimension=None):
|
def __init__(self, name, x, z, owner, dimension=None):
|
||||||
Location.__init__(self, name, x, y, z, owner, dimension)
|
Location.__init__(self, name, x, z, owner, dimension)
|
||||||
|
|
||||||
|
|
||||||
class ItemListing(SQL_Base):
|
class ItemListing(SQL_Base):
|
||||||
|
|
|
@ -86,7 +86,7 @@ async def register(ctx):
|
||||||
|
|
||||||
|
|
||||||
@bot.command(pass_context=True)
|
@bot.command(pass_context=True)
|
||||||
async def addbase(ctx, x_pos: int, y_pos: int, z_pos: int, * args):
|
async def addbase(ctx, x_pos: int, z_pos: int, * args):
|
||||||
'''
|
'''
|
||||||
Adds your base to the database. The name is optional.
|
Adds your base to the database. The name is optional.
|
||||||
?addbase [X Coordinate] [Y Coordinate] [Z Coordinate] [Base Name]
|
?addbase [X Coordinate] [Y Coordinate] [Z Coordinate] [Base Name]
|
||||||
|
@ -97,7 +97,7 @@ async def addbase(ctx, x_pos: int, y_pos: int, z_pos: int, * args):
|
||||||
else:
|
else:
|
||||||
name = '{}\'s_Base'.format(database_interface.find_player_by_discord_uuid(ctx.message.author.id).name)
|
name = '{}\'s_Base'.format(database_interface.find_player_by_discord_uuid(ctx.message.author.id).name)
|
||||||
try:
|
try:
|
||||||
base = database_interface.add_location(ctx.message.author.id, name, x_pos, y_pos, z_pos)
|
base = database_interface.add_location(ctx.message.author.id, name, x_pos, z_pos)
|
||||||
except LocationInitError:
|
except LocationInitError:
|
||||||
raise commands.UserInputError
|
raise commands.UserInputError
|
||||||
except EntryNameNotUniqueError:
|
except EntryNameNotUniqueError:
|
||||||
|
@ -110,7 +110,7 @@ async def addbase(ctx, x_pos: int, y_pos: int, z_pos: int, * args):
|
||||||
|
|
||||||
|
|
||||||
@bot.command(pass_context=True)
|
@bot.command(pass_context=True)
|
||||||
async def addshop(ctx, x_pos: int, y_pos: int, z_pos: int, *args):
|
async def addshop(ctx, x_pos: int, z_pos: int, *args):
|
||||||
'''
|
'''
|
||||||
Adds your shop to the database. The name is optional.
|
Adds your shop to the database. The name is optional.
|
||||||
?addshop [X Coordinate] [Y Coordinate] [Z Coordinate] [Shop Name]
|
?addshop [X Coordinate] [Y Coordinate] [Z Coordinate] [Shop Name]
|
||||||
|
|
|
@ -7,7 +7,7 @@ class TestGeoffreyDatabase(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.interface = DiscordDatabaseInterface('sqlite:///:memory:')
|
self.interface = DiscordDatabaseInterface('sqlite:///:memory:')
|
||||||
self.owner = Player('ZeroHD', '143072699567177728')
|
self.owner = Player('ZeroHD', '143072699567177728')
|
||||||
self.loc = Location('test', 1, 2, 3, self.owner, dimension='Nether')
|
self.loc = Location('test', 1, 3, self.owner, dimension='Nether')
|
||||||
self.tunnel = Tunnel(self.owner, 'Green', 105, self.loc)
|
self.tunnel = Tunnel(self.owner, 'Green', 105, self.loc)
|
||||||
|
|
||||||
def test_add_object(self):
|
def test_add_object(self):
|
||||||
|
@ -54,18 +54,18 @@ class TestGeoffreyDatabase(TestCase):
|
||||||
self.assertEqual(shop_list[0].dimension, shop.dimension)
|
self.assertEqual(shop_list[0].dimension, shop.dimension)
|
||||||
|
|
||||||
def add_shop(self):
|
def add_shop(self):
|
||||||
return self.interface.add_shop('143072699567177728', 'test', 1, 2, 3, "nether")
|
return self.interface.add_shop('143072699567177728', 'test', 1, 3, "nether")
|
||||||
|
|
||||||
def add_player(self):
|
def add_player(self):
|
||||||
return self.interface.add_player('ZeroHD', '143072699567177728')
|
return self.interface.add_player('ZeroHD', '143072699567177728')
|
||||||
|
|
||||||
def add_loc(self):
|
def add_loc(self):
|
||||||
return self.interface.add_location('143072699567177728', 'test', 0, 0, 0)
|
return self.interface.add_location('143072699567177728', 'test', 0, 0)
|
||||||
|
|
||||||
def test_add_two_shops(self):
|
def test_add_two_shops(self):
|
||||||
owner = self.add_player()
|
owner = self.add_player()
|
||||||
shop1 = self.add_shop()
|
shop1 = self.add_shop()
|
||||||
shop2 = self.interface.add_shop('143072699567177728', 'no u', 1, 2, 3)
|
shop2 = self.interface.add_shop('143072699567177728', 'no u', 1, 3)
|
||||||
|
|
||||||
loc_list = self.interface.find_location_by_owner_uuid('143072699567177728')
|
loc_list = self.interface.find_location_by_owner_uuid('143072699567177728')
|
||||||
|
|
||||||
|
@ -73,7 +73,6 @@ class TestGeoffreyDatabase(TestCase):
|
||||||
|
|
||||||
def test_add_tunnel(self):
|
def test_add_tunnel(self):
|
||||||
self.add_player()
|
self.add_player()
|
||||||
args=[]
|
|
||||||
tunnel1 = self.interface.add_tunnel('143072699567177728', 'green', 155, None)
|
tunnel1 = self.interface.add_tunnel('143072699567177728', 'green', 155, None)
|
||||||
|
|
||||||
tunnel2 = self.interface.find_tunnel_by_owner_name('ZeroHD')[0]
|
tunnel2 = self.interface.find_tunnel_by_owner_name('ZeroHD')[0]
|
||||||
|
@ -85,7 +84,7 @@ class TestGeoffreyDatabase(TestCase):
|
||||||
self.interface.add_item('143072699567177728', 'test', 'dirt', 1, 15)
|
self.interface.add_item('143072699567177728', 'test', 'dirt', 1, 15)
|
||||||
|
|
||||||
shops = self.interface.find_shop_selling_item('dirt')
|
shops = self.interface.find_shop_selling_item('dirt')
|
||||||
self.assertEqual(shops[0].name, 'test')
|
self.assertGreater(len(shops), 0)
|
||||||
|
|
||||||
def test_find_location_by_owner(self):
|
def test_find_location_by_owner(self):
|
||||||
owner = self.add_player()
|
owner = self.add_player()
|
||||||
|
@ -167,13 +166,13 @@ class TestGeoffreyDatabase(TestCase):
|
||||||
|
|
||||||
self.assertEqual(loc_list[0].id, loc.id)
|
self.assertEqual(loc_list[0].id, loc.id)
|
||||||
|
|
||||||
self.interface.add_shop('143072699567177728', 'testshop', 1, 2, 3, 'neThEr')
|
self.interface.add_shop('143072699567177728', 'testshop', 1, 3, 'neThEr')
|
||||||
|
|
||||||
self.interface.add_item('143072699567177728', 'testshop', 'dirts', 1, 15)
|
self.interface.add_item('143072699567177728', 'testshop', 'dirts', 1, 15)
|
||||||
|
|
||||||
shops = self.interface.find_shop_selling_item('Dirt')
|
shops = self.interface.find_shop_selling_item('diRt')
|
||||||
|
|
||||||
self.assertEqual(shops[0].name, 'testshop')
|
self.assertGreater(len(shops), 0)
|
||||||
|
|
||||||
#shops = self.database.find_shop_selling_item('sDirt')
|
#shops = self.database.find_shop_selling_item('sDirt')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue