def set(**params): DB.execute( """ INSERT INTO vote SET word_id = %(word_id)s, game_id = %(game_id)s, round_id = %(round_id)s, weight = %(weight)s, player_id = %(player_id)s ON DUPLICATE KEY UPDATE weight = %(weight)s """, params)
def add(wordsLimit, wordMinLength, **params): params['word'] = params['word'].strip().lower() wordsForToday = DB.getList( """ SELECT * FROM word WHERE player_id = %(player_id)s AND game_id = %(game_id)s AND round_id = %(round_id)s AND series_id = %(series_id)s """, params) if len(wordsForToday) >= wordsLimit: return False, Word.ERROR_CODES['NOT_IN_TIME_WORD'] % wordsLimit status, response = Word.isWordValid(params['word'], params['series_id'], wordMinLength) if not status: return False, response DB.execute( """ INSERT INTO word SET word = %(word)s, player_id = %(player_id)s, game_id = %(game_id)s, round_id = %(round_id)s, series_id = %(series_id)s """, params) wordsForToday = DB.getList( """ SELECT * FROM word WHERE player_id = %(player_id)s AND game_id = %(game_id)s AND round_id = %(round_id)s AND series_id = %(series_id)s """, params) additionalMsg = "" if len(wordsForToday) == wordsLimit: additionalMsg = " У тебя больше не осталось словцов в этом раунде, растяпа!" if len(wordsForToday) < wordsLimit: additionalMsg = " Ты можешь предложить ещё %d смешных словца" % ( wordsLimit - len(wordsForToday)) return True, "Твоё жалкое словцо \"%s\" принято, свинюшка! %s" % ( params['word'], additionalMsg)
def _registerRoundInGame(**params): DB.execute( """ INSERT INTO game_has_round SET game_id = %(game_id)s, round_id = %(round_id)s """, params)
def setState(**params): DB.execute( """ INSERT IGNORE INTO player_state SET isReady = 1, round_id = %(round_id)s, player_id = %(player_id)s ON DUPLICATE KEY UPDATE isReady=ABS(isReady - 1) """, params) return Player.getState(**params)
def setSeriesPassword(**params): params['password'] = md5(params['password'] + Config.get('MISC.password_salt')) DB.execute( """ UPDATE series_has_player SET password = %(password)s WHERE series_id = %(series_id)s AND player_id = %(player_id)s """, params)
def setSeriesPassword(**params): DB.execute( """ INSERT IGNORE INTO series_has_player SET series_id = %(series_id)s, player_id = %(player_id)s, password = %(password)s ON DUPLICATE KEY UPDATE password = %(password)s """, params)
def setGamePassword(**params): DB.execute( """ INSERT IGNORE INTO game_has_player SET game_id = %(game_id)s, player_id = %(player_id)s, password = %(password)s ON DUPLICATE KEY UPDATE password = %(password)s """, params)
def joinSeries(**params): DB.execute( """ INSERT IGNORE INTO series_has_player SET series_id = %(series_id)s, player_id = %(player_id)s, role = %(role)s """, params) DB.execute( """ UPDATE player SET series_id = %(series_id)s, game_id = 0 WHERE id = %(player_id)s """, params)
def joinGame(**params): DB.execute( """ INSERT IGNORE INTO game_has_player SET game_id = %(game_id)s, player_id = %(player_id)s, role = %(role)s """, params) DB.execute( """ UPDATE player SET game_id = %(game_id)s WHERE id = %(player_id)s """, params)
def update(**params): return DB.execute( """ UPDATE game SET winner_id = %(winner_id)s, winnerWord_id=%(winnerWord_id)s, status = %(status)s WHERE id = %(game_id)s """, params)
def _init(**params): if 'status' not in params: params['status'] = Game.STATUS_PREPARATION game_id = DB.execute( """ INSERT INTO game SET creator_id = %(player_id)s, status = %(status)s, settings = %(settings)s, series_id = %(series_id)s """, params).lastrowid logging.info("New game was started. ID: %d" % game_id) Round.getId(game_id) params[ 'role'] = Series.PLAYER_ROLE_MEMBER if 'seriesRole' not in params else params[ 'seriesRole'] Player.joinSeries(**params) params[ 'role'] = Game.PLAYER_ROLE_ADMIN if 'gameRole' not in params else params[ 'gameRole'] Player.joinGame(game_id=game_id, **params) return game_id
def add(update=None, name=None, telegram_id=None): name = Player._buildPlayerName( update.message.chat) if not name else name telegram_id = update.message.chat.id if not telegram_id else telegram_id player_id = DB.execute( """ INSERT INTO player SET name = %(name)s, telegram_id = %(telegram_id)s """, dict(name=name, telegram_id=telegram_id)).lastrowid logging.info("Player '%s' was added. ID: %s" % (name, player_id)) return player_id
def save(**params): return DB.execute( """ INSERT INTO log SET game_id = %(game_id)s, round_id = %(round_id)s, group_id = %(group_id)s, data = %(data)s, winnerPlayer_id = %(winnerPlayer_id)s, winnerWord_id = %(winnerWord_id)s """, params).lastrowid
def update(wordMinLength, **params): params['oldWord'] = params['oldWord'].lower() params['newWord'] = params['newWord'].lower() if params['newWord'] == params['oldWord']: return "И ты прислал два одинаковых слова... Зачем ты так глуп, а?" oldWord = DB.getOne( """ SELECT * FROM word WHERE word = %(oldWord)s AND player_id = %(player_id)s AND round_id = %(round_id)s AND game_id = %(game_id)s """, params) if not oldWord: return "У тебя нет такого словца в последнем раунде или он уже завершён, дурында!" status, response = Word.isWordValid(word=params['newWord'], series_id=params['series_id'], wordMinLength=wordMinLength) if not status: return response affectedRows = DB.execute(""" UPDATE word SET word = '%s' WHERE id = %d""" % (params['newWord'], oldWord['id'])).rowcount return "Хм... Я не смог обновить словцо. Интересно почему?" if not affectedRows else "Словцо успешно обновлено. Надеюсь, оно было получше прежнего"
def updateSettings(**params): return DB.execute( "UPDATE game SET settings = %(settings)s WHERE id = %(game_id)s", params)
def updateRoundStatus(**params): DB.execute( "UPDATE round SET status=%(status)s WHERE id = %(round_id)s", params)
def _start(**params): return DB.execute( "INSERT INTO round SET game_id = %(game_id)s, number = %(number)s", params).lastrowid
def setGamePassword(**params): DB.execute( "UPDATE game SET password = %(password)s WHERE id = %(game_id)s", params)
def setGameStatus(**params): DB.execute( "UPDATE game SET status = %(status)s WHERE id = %(game_id)s", params)
def addWordToGroup(**params): # lastGroupNumber = Group._getLastGroupNumber(params) # params['number'] = 1 if not lastGroupNumber else lastGroupNumber+1 DB.execute( "INSERT INTO groups SET word_id=%(word_id)s, player_id = %(player_id)s, game_id=%(game_id)s, round_id=%(round_id)s, number=%(number)s, status=%(status)s", params)