Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    def _registerRoundInGame(**params):
        DB.execute(
            """
			INSERT INTO game_has_round
			SET
				game_id = %(game_id)s,
				round_id = %(round_id)s
		""", params)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    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)
Пример #8
0
    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)
Пример #9
0
    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)
Пример #10
0
    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)
Пример #11
0
    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
Пример #12
0
    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
Пример #13
0
    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
Пример #14
0
    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 "Словцо успешно обновлено. Надеюсь, оно было получше прежнего"
Пример #15
0
 def updateSettings(**params):
     return DB.execute(
         "UPDATE game SET settings = %(settings)s WHERE id = %(game_id)s",
         params)
Пример #16
0
 def updateRoundStatus(**params):
     DB.execute(
         "UPDATE round SET status=%(status)s WHERE id = %(round_id)s",
         params)
Пример #17
0
 def _start(**params):
     return DB.execute(
         "INSERT INTO round SET game_id = %(game_id)s, number = %(number)s",
         params).lastrowid
Пример #18
0
 def setGamePassword(**params):
     DB.execute(
         "UPDATE game SET password = %(password)s WHERE id = %(game_id)s",
         params)
Пример #19
0
 def setGameStatus(**params):
     DB.execute(
         "UPDATE game SET status = %(status)s WHERE id = %(game_id)s",
         params)
Пример #20
0
 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)