Example #1
0
    def cmd_play(self, update, context):
        """/play command"""
        if update.effective_user.is_bot is True:
            return

        self.logger.info(update.message.text + ' from user ' +
                         str(update.effective_user.id))

        if update.effective_chat.get_member_count(
        ) < self.parameters['min_members']:
            out_text = self.texter.get_text('min_members_group_play',
                                            lang=Config.DEFAULT_LANGUAGE)
            context.bot.send_message(
                chat_id=update.effective_chat.id,
                text=out_text.format(
                    min_members=self.parameters['min_members']),
                parse_mode='HTML')
            return
        if update.effective_chat.id not in self.chats:
            # TODO improvement: add different game types later
            game = self.games['textquiz']
            chat = Chat(c_id=update.effective_chat.id,
                        u_id=update.effective_user.id,
                        game=game,
                        parameters=self.parameters,
                        is_on=True,
                        lang=Config.DEFAULT_LANGUAGE)
            chat.next_question()
            self.chats[update.effective_chat.id] = chat
        else:
            chat = self.chats[update.effective_chat.id]
            chat.is_on = True
        self.session.merge(
            models.Chat(id=chat.id,
                        u_id=chat.u_id,
                        q_id=chat.q_id,
                        is_on=chat.is_on,
                        lang=chat.lang,
                        game=chat.game.name))
        self.session.commit()
        if update.effective_user.id not in chat.users:
            self.new_player(update)
        self.cmd_ask(update, context)