def update_last_seen(steam_ids): """Update last_seen column on a player Args: steam_ids: Integer or List of steam id Returns: True if any updates """ do_commit = False if type(steam_ids) == int: p = Db.find_player(steam_id=steam_ids) if p: p.last_seen = text("NOW()") DbCore.session.add(p) do_commit = True else: for steam_id in steam_ids: p = Db.find_player(steam_id=steam_id) if p: p.last_seen = text("NOW()") DbCore.session.add(p) do_commit = True if do_commit is True: DbCore.commit() return True return False
def create_chat_entry(player_id, name, data): try: entry = Chat(player_id=player_id, name=name, data=data, created=text("NOW()")) DbCore.session.add(entry) DbCore.commit() return entry except exc.SQLAlchemyError as e: out("SQL Failure - find player wildcard:", e) DbCore.reconnect() return None
def website_data_set(key, value): try: data = DbCore.session.query(WebsiteData).filter_by(key=key).first() except exc.SQLAlchemyError as e: out("SQL Failure - website_data set:", e) DbCore.reconnect() return False if not data: data = WebsiteData() data.key = key data.value = value DbCore.session.add(data) DbCore.commit() return True
def update_player(steam_id, steam_name=None, name=None): player = Db.find_player(steam_id) if player is None: return None, False altered = False if steam_name and player.steam_name != steam_name: player.steam_name = steam_name altered = True if name and player.name != name: player.name = name altered = True if altered: DbCore.session.add(player) DbCore.commit() return True
def create_player(steam_id, steam_name, name=None): """Create entry in players table Returns: Player: Object Bool: True if new entry. """ player = Db.find_player(steam_id, steam_name) if player is None: player = Player( steam_name=steam_name, steam_id=steam_id, name=name, admin=0, last_seen=text("NOW()"), created=text("NOW()"), ) DbCore.session.add(player) DbCore.commit() return player, True return player, False