added team owner id to database

This commit is contained in:
Sakimori 2020-12-26 21:53:46 -05:00
parent 663fc6c3f6
commit e369099544
3 changed files with 9 additions and 8 deletions

View File

@ -62,7 +62,8 @@ def initialcheck():
counter integer PRIMARY KEY, counter integer PRIMARY KEY,
name text NOT NULL, name text NOT NULL,
team_json_string text NOT NULL, team_json_string text NOT NULL,
timestamp text NOT NULL timestamp text NOT NULL,
owner_id integer
); """ ); """
if conn is not None: if conn is not None:
@ -190,14 +191,14 @@ def get_user_player(user):
conn.close() conn.close()
return player return player
def save_team(name, team_json_string): def save_team(name, team_json_string, user_id):
conn = create_connection() conn = create_connection()
try: try:
if conn is not None: if conn is not None:
c = conn.cursor() c = conn.cursor()
store_string = """ INSERT INTO teams(name, team_json_string, timestamp) store_string = """ INSERT INTO teams(name, team_json_string, timestamp, owner_id)
VALUES (?,?, ?) """ VALUES (?,?, ?, ?) """
c.execute(store_string, (re.sub('[^A-Za-z0-9 ]+', '', name), team_json_string, datetime.datetime.now(datetime.timezone.utc))) #this regex removes all non-standard characters c.execute(store_string, (re.sub('[^A-Za-z0-9 ]+', '', name), team_json_string, datetime.datetime.now(datetime.timezone.utc), user_id)) #this regex removes all non-standard characters
conn.commit() conn.commit()
conn.close() conn.close()
return True return True

View File

@ -479,11 +479,11 @@ def get_team(name):
# except: # except:
#return None #return None
def save_team(this_team): def save_team(this_team, user_id):
try: try:
this_team.prepare_for_save() this_team.prepare_for_save()
team_json_string = jsonpickle.encode(this_team, keys=True) team_json_string = jsonpickle.encode(this_team, keys=True)
db.save_team(this_team.name, team_json_string) db.save_team(this_team.name, team_json_string, user_id)
return True return True
except: except:
return None return None

View File

@ -573,7 +573,7 @@ async def save_team_batch(message, command):
react, user = await client.wait_for('reaction_add', timeout=20.0, check=react_check) react, user = await client.wait_for('reaction_add', timeout=20.0, check=react_check)
if react.emoji == "👍": if react.emoji == "👍":
await message.channel.send("You got it, chief. Saving now.") await message.channel.send("You got it, chief. Saving now.")
games.save_team(newteam) games.save_team(newteam, message.author.id)
await message.channel.send("Saved! Thank you for flying Air Matteo. We hope you had a pleasant data entry.") await message.channel.send("Saved! Thank you for flying Air Matteo. We hope you had a pleasant data entry.")
return return
elif react.emoji == "👎": elif react.emoji == "👎":