Added Player Class. Location now has a player owner
parent
248e108ea1
commit
9c01ae94de
34
MCInfoBot.py
34
MCInfoBot.py
|
@ -2,7 +2,7 @@ import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy import Column, Integer, String
|
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
engine = create_engine('sqlite:///:memory:', echo=True)
|
engine = create_engine('sqlite:///:memory:', echo=True)
|
||||||
|
@ -15,18 +15,28 @@ least he knows where your bases are.'''
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix=command_prefix , description=description)
|
bot = commands.Bot(command_prefix=command_prefix , description=description)
|
||||||
|
|
||||||
|
class Player(SQL_Base):
|
||||||
|
__tablename__ = 'Players'
|
||||||
|
in_game_name = Column(String, primary_key=True)
|
||||||
|
|
||||||
|
def __init__(self,name) :
|
||||||
|
self.in_game_name = name
|
||||||
|
|
||||||
|
|
||||||
class Location(SQL_Base):
|
class Location(SQL_Base):
|
||||||
__tablename__ = 'Locations'
|
__tablename__ = 'Locations'
|
||||||
name = Column(String, primary_key=True)
|
name = Column(String, primary_key=True)
|
||||||
x = Column(Integer)
|
x = Column(Integer)
|
||||||
y = Column(Integer)
|
y = Column(Integer)
|
||||||
z = Column(Integer)
|
z = Column(Integer)
|
||||||
|
owner = Column(String, ForeignKey('Players.in_game_name'))
|
||||||
|
|
||||||
def __init__(self,args) :
|
def __init__(self,args,owner) :
|
||||||
self.name = args[0]
|
self.name = args[0]
|
||||||
self.x = int(args[1])
|
self.x = int(args[1])
|
||||||
self.y = int(args[2])
|
self.y = int(args[2])
|
||||||
self.z = int(args[3])
|
self.z = int(args[3])
|
||||||
|
self.owner = owner
|
||||||
|
|
||||||
def posToStr(self) :
|
def posToStr(self) :
|
||||||
return '(x=' + str(self.x) + ', y=' + str(self.y) + ', z=' + str(self.z) + ')'
|
return '(x=' + str(self.x) + ', y=' + str(self.y) + ', z=' + str(self.z) + ')'
|
||||||
|
@ -49,7 +59,7 @@ async def on_ready():
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def test():
|
async def test():
|
||||||
'''Check if the bot is alive'''
|
'''Check if the bot is alive.'''
|
||||||
await bot.say('I\'m here you ding dong')
|
await bot.say('I\'m here you ding dong')
|
||||||
|
|
||||||
@bot.command(pass_context=True)
|
@bot.command(pass_context=True)
|
||||||
|
@ -57,7 +67,10 @@ async def addbase(ctx, * args):
|
||||||
'''Add your base to the database.'''
|
'''Add your base to the database.'''
|
||||||
if (len(args) == 4) :
|
if (len(args) == 4) :
|
||||||
try:
|
try:
|
||||||
base = Location(args)
|
owner = Player(str(ctx.message.author.nick))
|
||||||
|
base = Location(args,owner.in_game_name)
|
||||||
|
|
||||||
|
session.add(owner)
|
||||||
session.add(base)
|
session.add(base)
|
||||||
await bot.say('{}, your base named {} located at {} has been added'
|
await bot.say('{}, your base named {} located at {} has been added'
|
||||||
' to the database.'.format(ctx.message.author.mention, base.name, base.posToStr()))
|
' to the database.'.format(ctx.message.author.mention, base.name, base.posToStr()))
|
||||||
|
@ -71,11 +84,16 @@ async def addbase(ctx, * args):
|
||||||
@bot.command(pass_context=True)
|
@bot.command(pass_context=True)
|
||||||
async def findbase(ctx, * args):
|
async def findbase(ctx, * args):
|
||||||
'''Allows you to find a base in the database.'''
|
'''Allows you to find a base in the database.'''
|
||||||
base = session.query(Location).filter_by(name=args[0]).first()
|
if (len(args) > 0) :
|
||||||
if (base is not None) :
|
|
||||||
await bot.say('{}, {} is located at {}.'.format(ctx.message.author.mention, base.name, base.posToStr()))
|
base = session.query(Location).filter_by(owner=args[0]).first()
|
||||||
|
if (base is not None) :
|
||||||
|
await bot.say('{}, {}\'s base named {} is located at {}.'.format(ctx.message.author.mention, base.owner ,base.name, base.posToStr()))
|
||||||
|
else :
|
||||||
|
await bot.say('{}, {} is not in the database'.format(ctx.message.author.mention, args[0]))
|
||||||
else :
|
else :
|
||||||
await bot.say('{}, {} is not in the database'.format(ctx.message.author.mention, args[0]))
|
await bot.say('Allows you to add your base location to the database. '
|
||||||
|
'Syntax: ?findbase [Base Name] ')
|
||||||
|
|
||||||
#Bot Startup ******************************************************************
|
#Bot Startup ******************************************************************
|
||||||
try :
|
try :
|
||||||
|
|
Loading…
Reference in New Issue