Beispiel #1
0
def getKb(chat_id, k, u_id = None):
    l = getLanguage(chat_id)
    kb = []
    if k == 'main':
        if bds.getEnabled(chat_id):
            if bds.getInGame(chat_id):
                if bds.getArriscarBlock(chat_id):
                    kb.append([[l.voltar]])
                else:
                    letras = bds.getLetras(chat_id)
                    kb.append([letras[0], letras[1], letras[2], [l.arriscar], [l.comandos]])
            elif bds.getPreGame(chat_id):
                if u_id in bds.getPlayers(chat_id)[0]:
                    kb.append([[l.sair], [l.comandos]])
                else:
                    kb.append([[l.entrar], [l.comandos]])
                kb.append([[l.cancelar_jogo, l.fechar_jogo], [l.comandos]])
            else:
                kb.append([[l.novojogo], [l.ajuda, l.rank], [l.config], [l.desligar]])
        else:
            kb.append([[l.ligar]])
    elif k == 'cmd':
        if bds.getInGame(chat_id):
            kb.append([[l.ajuda, l.rank], [l.config], [l.voltar], [l.desligar]])
            kb.append([[l.cancelar_jogo], [l.ajuda, l.rank], [l.config, l.voltar], [l.desligar]])
        elif bds.getPreGame(chat_id):
            kb.append([[l.ajuda, l.rank], [l.config, l.voltar], [l.desligar]])
    elif k == 'config':
        kb.append([['Português(BR)' + emoji_br, 'English(US)' + emoji_usa], [l.ajuda], [l.voltar]])
    elif k == 'fora':
        kb.append([[l.esta_fora]])
    elif k == 'first':
        kb.append([['Português(BR)' + emoji_br, 'English(US)' + emoji_usa]])
    return kb
Beispiel #2
0
def getKb(chat_id, k, u_id=None):
    l = getLanguage(chat_id)
    kb = []
    if k == 'main':
        if bds.getEnabled(chat_id):
            if bds.getInGame(chat_id):
                if bds.getArriscarBlock(chat_id):
                    kb.append([[l.voltar]])
                else:
                    letras = bds.getLetras(chat_id)
                    kb.append([
                        letras[0], letras[1], letras[2], [l.arriscar],
                        [l.comandos]
                    ])  #letters keyboard
            elif bds.getPreGame(chat_id):
                if u_id in bds.getPlayers(chat_id)[0]:
                    kb.append([[l.sair], [l.comandos]])  #Pre-game in
                else:
                    kb.append([[l.entrar], [l.comandos]])  #Pre-game out
                kb.append([[l.cancelar_jogo, l.fechar_jogo],
                           [l.categorias_btn], [l.comandos]])  #Pre-game admin
            else:
                kb.append([[l.novojogo], [l.ajuda, l.rank],
                           [l.config, l.sobre], [l.desligar]])  #Main
        else:
            kb.append([[l.ligar]])  #Off
    elif k == 'cmd':
        if bds.getInGame(chat_id):
            kb.append([[l.ajuda, l.rank], [l.config], [l.voltar],
                       [l.desligar]])
            kb.append([[l.cancelar_jogo], [l.ajuda, l.rank],
                       [l.config, l.voltar], [l.desligar]])
        elif bds.getPreGame(chat_id):
            kb.append([[l.ajuda, l.rank], [l.config, l.voltar], [l.desligar]])
    elif k == 'config':
        kb.append([[
            'Português(BR)' + emoji_br, 'English(US)' + emoji_usa,
            'עברית (ישראל)' + emoji_hb
        ], [l.ajuda], [l.voltar]])
    elif k == 'fora':
        kb.append([[l.esta_fora]])
    elif k == 'first':
        kb.append([[
            'Português(BR)' + emoji_br, 'English(US)' + emoji_usa,
            'עברית (ישראל)' + emoji_hb
        ]])
    if (len(kb) == 0):
        kb = [[l.att_kb]]
    return kb
Beispiel #3
0
def comandos(chat_id, message_id, u_id):
    l = getLanguage(chat_id)
    kb = getKb(chat_id, 'cmd')
    if not (bds.getInGame(chat_id) and bds.checkAdm(chat_id, u_id)):
        keyboard = makeKb(kb[0], resize_keyboard = True, selective = True)
    else:
        keyboard = makeKb(kb[1], resize_keyboard = True, selective = True)
    return [toDict(chat_id, l.comandos_msg, replyTo = message_id, replyMarkup = keyboard)]
Beispiel #4
0
def ajuda(chat_id):
    l = getLanguage(chat_id)
    if bds.getEnabled(chat_id):
        if bds.getSettings(chat_id).waiting:
            return [toDict(chat_id, l.config_help_msg)]
        if bds.getInGame(chat_id):
            return [toDict(chat_id, l.in_game_help_msg)]
        if bds.getPreGame(chat_id):
            return [toDict(chat_id, l.pre_game_help_msg)]
        return [toDict(chat_id, l.start_help_msg)]
Beispiel #5
0
def ajuda(chat_id):
    l = getLanguage(chat_id)
    if bds.getEnabled(chat_id):
        if bds.getSettings(chat_id).waiting:
            return [toDict(chat_id, l.config_help_msg)]
        if bds.getInGame(chat_id):
            return [toDict(chat_id, l.in_game_help_msg)]
        if bds.getPreGame(chat_id):
            return [toDict(chat_id, l.pre_game_help_msg)]
        return [toDict(chat_id, l.start_help_msg)]
Beispiel #6
0
def kb(chat_id, u_id, message_id):
    l = getLanguage(chat_id)
    kb = getKb(chat_id, 'main', u_id = u_id)
    keyboard = makeKb(kb[0], resize_keyboard = True, selective = True)
    if (bds.getInGame(chat_id)) or (not bds.getPreGame(chat_id)):
        i = 0
    elif bds.getPreGame(chat_id):
        i = 0
        if bds.checkAdm(chat_id, u_id):
            i = 1
    keyboard = makeKb(kb[i], resize_keyboard = True, selective = True)
    return [toDict(chat_id, l.teclado_msg, replyTo = message_id, replyMarkup = keyboard)]
Beispiel #7
0
def comandos(chat_id, message_id, u_id):
    l = getLanguage(chat_id)
    kb = getKb(chat_id, 'cmd')
    if not (bds.getInGame(chat_id) and bds.checkAdm(chat_id, u_id)):
        keyboard = makeKb(kb[0], resize_keyboard=True, selective=True)
    else:
        keyboard = makeKb(kb[1], resize_keyboard=True, selective=True)
    return [
        toDict(chat_id,
               l.comandos_msg,
               replyTo=message_id,
               replyMarkup=keyboard)
    ]
Beispiel #8
0
def getKb(chat_id, k, u_id = None):
    l = getLanguage(chat_id)
    kb = []
    if k == 'main':
        if bds.getEnabled(chat_id):
            if bds.getInGame(chat_id):
                if bds.getArriscarBlock(chat_id):
                    kb.append([[l.voltar]])
                else:
                    letras = bds.getLetras(chat_id)
                    kb.append([letras[0], letras[1], letras[2], [l.arriscar], [l.comandos]]) #letters keyboard
            elif bds.getPreGame(chat_id):
                if u_id in bds.getPlayers(chat_id)[0]:
                    kb.append([[l.sair], [l.comandos]]) #Pre-game in
                else:
                    kb.append([[l.entrar], [l.comandos]]) #Pre-game out
                kb.append([[l.cancelar_jogo, l.fechar_jogo],[l.categorias_btn], [l.comandos]]) #Pre-game admin
            else:
                kb.append([[l.novojogo], [l.ajuda, l.rank], [l.config, l.sobre], [l.desligar]]) #Main
        else:
            kb.append([[l.ligar]]) #Off
    elif k == 'cmd':
        if bds.getInGame(chat_id):
            kb.append([[l.ajuda, l.rank], [l.config], [l.voltar], [l.desligar]])
            kb.append([[l.cancelar_jogo], [l.ajuda, l.rank], [l.config, l.voltar], [l.desligar]])
        elif bds.getPreGame(chat_id):
            kb.append([[l.ajuda, l.rank], [l.config, l.voltar], [l.desligar]])
    elif k == 'config':
        kb.append([['Português(BR)' + emoji_br, 'English(US)' + emoji_usa, 'עברית (ישראל)' + emoji_hb], [l.ajuda], [l.voltar]])
    elif k == 'fora':
        kb.append([[l.esta_fora]])
    elif k == 'first':
        kb.append([['Português(BR)' + emoji_br, 'English(US)' + emoji_usa, 'עברית (ישראל)' + emoji_hb]])
    if (len(kb) == 0):
        kb = [[l.att_kb]]
    return kb
Beispiel #9
0
def voltar(chat_id, msg, message_id, u_id, esp=None):
    rpl = []
    i = 0
    if bds.getSettings(chat_id).waiting:
        bds.setWaiting(chat_id, False)
        if bds.getInGame(chat_id):
            kb = getKb(chat_id, 'cmd')
            if not bds.checkAdm(chat_id, u_id):
                i = 0
            else:
                i = 1
        elif bds.getPreGame(chat_id):
            kb = getKb(chat_id, 'cmd')
            i = 0
        else:
            kb = getKb(chat_id, 'main')
            i = 0
    else:
        if bds.getArriscarBlock(chat_id):
            bds.setArriscarBlock(chat_id, False)
        kb = getKb(chat_id, 'main', u_id=u_id)
        if len(kb) != 1:
            if not bds.checkAdm(chat_id, u_id):
                i = 0
            else:
                i = 1
    if not esp:
        keyboard = makeKb(kb[i], resize_keyboard=True, selective=True)
        rpl.append(
            toDict(chat_id, msg, replyTo=message_id, replyMarkup=keyboard))
    else:
        keyboard = makeKb(kb[0], resize_keyboard=True)
        rpl.append(toDict(chat_id, msg, replyMarkup=keyboard))
        if len(kb) != 1:
            keyboard = makeKb(kb[1], resize_keyboard=True, selective=True)
            rpl.append(
                toDict(chat_id, msg, replyTo=message_id, replyMarkup=keyboard))
    return rpl
Beispiel #10
0
def kb(chat_id, u_id, message_id, waiting):
    l = getLanguage(chat_id)
    kb = getKb(chat_id, 'main', u_id=u_id)
    keyboard = makeKb(kb[0], resize_keyboard=True, selective=True)
    if bds.getEnabled(chat_id):
        if (bds.getInGame(chat_id)) or (not bds.getPreGame(chat_id)):
            i = 0
        elif bds.getPreGame(chat_id):
            i = 0
            if bds.checkAdm(chat_id, u_id):
                i = 1
    else:
        i = 0
    keyboard = makeKb(kb[i], resize_keyboard=True, selective=True)
    if waiting:
        kb = getKb(chat_id, 'config')
        keyboard = makeKb(kb[0], resize_keyboard=True, selective=True)
    return [
        toDict(chat_id,
               l.teclado_msg,
               replyTo=message_id,
               replyMarkup=keyboard)
    ]
Beispiel #11
0
def voltar(chat_id, msg, message_id, u_id, esp = None):
    rpl = []
    i = 0
    if bds.getSettings(chat_id).waiting:
        bds.setWaiting(chat_id, False)
        if bds.getInGame(chat_id):
            kb = getKb(chat_id, 'cmd')
            if not bds.checkAdm(chat_id, u_id):
                i = 0
            else:
                i = 1
        elif bds.getPreGame(chat_id):
            kb = getKb(chat_id, 'cmd')
            i = 0
        else:
            kb = getKb(chat_id, 'main')
            i = 0
    else:
        if bds.getArriscarBlock(chat_id):
            bds.setArriscarBlock(chat_id, False)
        kb = getKb(chat_id, 'main', u_id = u_id)
        if len(kb) != 1:
            if not bds.checkAdm(chat_id, u_id):
                i = 0
            else:
                i = 1
    if not esp:
        keyboard = makeKb(kb[i], resize_keyboard = True, selective = True)
        rpl.append(toDict(chat_id, msg, replyTo = message_id, replyMarkup = keyboard))
    else:
        keyboard = makeKb(kb[0], resize_keyboard = True)
        rpl.append(toDict(chat_id, msg, replyMarkup = keyboard))
        if len(kb) != 1:
            keyboard = makeKb(kb[1], resize_keyboard = True, selective = True)
            rpl.append(toDict(chat_id, msg, replyTo = message_id, replyMarkup = keyboard))
    return rpl
Beispiel #12
0
def getInGame(chat_id):
    return bds.getInGame(chat_id)
Beispiel #13
0
    def post(self):
        urlfetch.set_default_fetch_deadline(60)
        body = json.loads(self.request.body)
        logging.info('request body:')
        logging.info(body)
        self.response.write(json.dumps(body))

        #Função que verifica se o forca_bot foi excluido ou se ele existe no BD
        def verifyBot(left_chat_participant = None):
            if left_chat_participant:
                first_name = left_chat_participant['first_name'].encode('utf-8')
                if first_name == 'The Hangman':
                    bds.delChat(chat_id)
                    return
            return

        #Dados que recebemos do telegram
        update_id = body['update_id']
        message = body['message']
        message_id = str(message.get('message_id')).encode('utf-8')
        left_chat_participant = message.get('left_chat_participant')
        new_chat_participant = message.get('new_chat_participant')
        group_chat_created = message.get('group_chat_created')
        date = message.get('date')
        text = message.get('text').encode('utf-8') if message.get('text') else message.get('text')
        if text:
            if not text.startswith('/admin'):
                text = text.lower()
        fr = message.get('from')
        chat = message['chat']
        chat_id = str(chat['id'])
        user_id = message['from']
        u_id = str(user_id.get('id')).encode('utf-8')
        u_name = user_id.get('first_name').encode('utf-8')
        bds.checkChat(chat_id)

        #'Chama' a verificação.
        if left_chat_participant:
            verifyBot(left_chat_participant = left_chat_participant)

        if not text:
            logging.info('no text')
            return

        #Função que envia o dict para o Telegram
        def reply(dict = None):
            if dict:
                resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode(dict)).read()
            else:
                logging.error('no msg or img specified')
                resp = None
            logging.info('send response:')
            logging.info(resp)

        #Lê as configurações
        def getLanguage(chat_id):
            s = bds.getSettings(chat_id) #Classe settings
            if s:
                if s.language == 'ptBR':
                    import ptBR as l
                    return l
                elif s.language == 'enUS':
                    import enUS as l
                    return l
                elif s.language == 'hbIL':
                    import hbIL as l
                    return l
            else:
                bds.checkChat(chat_id)
                s = bds.getSettings(chat_id) #Classe settings
                if s.language == 'ptBR':
                    import ptBR as l
                    return l
                elif s.language == 'enUS':
                    import enUS as l
                    return l
                elif s.language == 'hbIL':
                    import hbIL as l
                    return l
                return


        #Aqui começa a lógica principal
        l = getLanguage(chat_id)
        s = bds.getSettings(chat_id)
        ab = bds.getArriscarBlock(chat_id)
        first = bds.getFirstWelcome(chat_id)[0]
        rpl = [c.toDict(chat_id, l.sorry_msg)]

        text = '/start' if text == l.ligar.lower() else text #Tratamento para o caso do /start
        text = l.ajuda.lower() if text.startswith('/help') else text
        text = l.desligar.lower() if text.startswith('/stop') else text

        if text.startswith('@PlayHangmanBot'):
            text = text[15:]
        if (u_id in creators) and (text.startswith('/admin')): #Funções especiais dos criadores do bot
            if text.startswith('/admindelchat'):
                chat = text[14:]
                if len(chat) > 0:
                    if bds.delChat(chat):
                        rpl = [c.toDict(chat_id, 'Chat '+chat+' deletado')]
                    else:
                        rpl = [c.toDict(chat_id, 'Chat '+chat+' não existe')]
            elif text.startswith('/adminshout'):
                text = text[12:]
                chats = bds.getChats()
                rpl = []
                for i in range(len(chats)):
                    time.sleep(0.1)
                    rpl.append(c.toDict(chats[i], text))
            elif text.startswith('/admingetdadoschat'):
                chat = text[19:]
                if len(chat) > 0:
                    dados = bds.getDadosChat(chat)
                    jogos_dia = bds.getJogosDia(chat, date)
                    if dados:
                        rpl = [c.toDict(chat_id, 'Chat '+str(chat)+'\nJogos: '+ str(dados.games)+'\nJogadores: '+str(len(dados.players))+'\nJogos por dia: '+str(jogos_dia)+'\nTop player: '+dados.topPlayer.u_name.encode('utf-8')+'\n\tScore: '+str(dados.topPlayer.u_score)+'\n\tId: '+str(dados.topPlayer.u_id))]
                    else:
                        rpl = [c.toDict(chat_id, 'Chat '+chat+' não existe')]
            elif text.startswith('/admingetdadosglobais'):
                urlfetch.set_default_fetch_deadline(300)
                resp = bds.getDadosGlobais(date)
                rpl = [c.toDict(chat_id, 'Chats: '+str(resp[0])+'\nJogadores: '+str(resp[1])+'\nJogos por dia: '+str(resp[2])+'\nJogos: '+str(resp[3]))]
        elif (not s.waiting) or first:
            #comandos que indiferem do estado atual de jogo
            if '/start' in text:
                rpl = c.start(chat_id, u_id, first)
            elif bds.getEnabled(chat_id):
                if ('/kb' in text) or (l.att_kb in text):
                    rpl = c.kb(chat_id, u_id, message_id, s.waiting)
                elif l.desligar.lower() in text:
                    rpl = c.stop(chat_id)
                elif l.ajuda.lower() in text:
                    rpl = c.ajuda(chat_id)
                elif l.rank.lower() in text:
                    rpl = c.rank(chat_id)
                elif l.config.lower() in text:
                    rpl = c.config(chat_id, message_id)
                elif l.sobre.lower() in text:
                    rpl = c.sobre(chat_id)
                elif l.voltar.lower() in text:
                    rpl = c.voltar(chat_id, l.voltar_msg, message_id, u_id)
                elif l.comandos.lower() in text:
                    rpl = c.comandos(chat_id, message_id, u_id)
                #comandos inGame
                elif bds.getInGame(chat_id):
                    check = bds.checkUid(chat_id, u_id)
                    if l.cancelar_jogo.lower() in text:
                        rpl = g.cancelarJogo(chat_id, u_id)
                    elif check == True:
                        if bds.getArriscarBlock(chat_id):
                            rpl = g.arriscarPalavra2(chat_id, u_id, u_name, message_id, text)
                        elif l.arriscar.lower() in text:
                            rpl = g.arriscarPalavra1(chat_id, u_id, message_id)
                        elif (len(text) == 1) or (text.startswith('@PlayHangmanBot')):
                            if text.startswith('@PlayHangmanBot'):
                                text = text[10:]
                            rpl = g.chutarLetra(chat_id, u_id, u_name, message_id, text)
                    elif check == 'rnd':
                        rpl = [c.toDict(chat_id, l.round_errado_msg)]
                    elif check == 'out':
                        rpl = [c.toDict(chat_id, l.fora_msg)]

                #comandos preGame
                elif bds.getPreGame(chat_id):
                    if s.categorias and bds.checkAdm(chat_id, u_id):
                        rpl = p.setCategorias(chat_id, text, message_id,u_id)
                    elif l.entrar.lower() in text:
                        rpl = p.entrar(chat_id, u_id, u_name, message_id)
                    elif l.categorias_btn.lower() in text:
                        rpl = p.categorias(chat_id, u_id, message_id)
                    elif l.sair.lower() in text:
                        rpl = p.sair(chat_id, u_id, u_name, message_id)
                    elif l.fechar_jogo.lower() in text:
                        rpl = p.fecharJogo(chat_id, u_id, message_id, date)
                    elif l.cancelar_jogo.lower() in text:
                        rpl = p.cancelarJogo(chat_id, u_id)
                #se preGame e inGame == False (vide flowchart)
                elif (not bds.getPreGame(chat_id)) and (not bds.getInGame(chat_id)):
                    if l.novojogo.lower() in text:
                        rpl = c.novojogo(chat_id, u_id, u_name, message_id)
        else:
            if l.ajuda.lower() in text:
                rpl = c.ajuda(chat_id)
            elif '/kb' in text:
                rpl = c.kb(chat_id, u_id, message_id, s.waiting)
            else:
                rpl = c.changeLanguage(chat_id, text, message_id, u_id)

        error = False
        for i in range(len(rpl)):
                time.sleep(1.5)
                try:
                    reply(rpl[i])
                except Exception, e:
                    print e
                    if (str(e) == "HTTP Error 429: Unknown") and (not error):
                        error = True
                        time.sleep(2)
                        i = i - 1
                    else:
                        try:
                            reply(c.toDict(chat_id, l.error_msg))
                        except Exception, e:
                            print e
                            try:
                                reply(c.toDict(chat_id, 'Fatal error, contact @cristoferoswald or @bcesarg6.'))
                            except Exception, e:
                                print e
Beispiel #14
0
 elif l.desligar.lower() in text:
     rpl = c.stop(chat_id)
 elif l.ajuda.lower() in text:
     rpl = c.ajuda(chat_id)
 elif l.rank.lower() in text:
     rpl = c.rank(chat_id)
 elif l.config.lower() in text:
     rpl = c.config(chat_id, message_id)
 elif l.sobre.lower() in text:
     rpl = c.sobre(chat_id)
 elif l.voltar.lower() in text:
     rpl = c.voltar(chat_id, l.voltar_msg, message_id, u_id)
 elif l.comandos.lower() in text:
     rpl = c.comandos(chat_id, message_id, u_id)
 #comandos inGame
 elif bds.getInGame(chat_id):
     check = bds.checkUid(chat_id, u_id)
     if l.cancelar_jogo.lower() in text:
         rpl = g.cancelarJogo(chat_id, u_id)
     elif check == True:
         if bds.getArriscarBlock(chat_id):
             rpl = g.arriscarPalavra2(chat_id, u_id, u_name, message_id, text)
         elif l.arriscar.lower() in text:
             rpl = g.arriscarPalavra1(chat_id, u_id, message_id)
         elif (len(text) == 1) or (text.startswith('@PlayHangmanBot')):
             if text.startswith('@PlayHangmanBot'):
                 text = text[10:]
             rpl = g.chutarLetra(chat_id, u_id, u_name, message_id, text)
     elif check == 'rnd':
         rpl = [c.toDict(chat_id, l.round_errado_msg)]
     elif check == 'out':
Beispiel #15
0
    def post(self):
        urlfetch.set_default_fetch_deadline(60)
        body = json.loads(self.request.body)
        logging.info("request body:")
        logging.info(body)
        self.response.write(json.dumps(body))

        # Função que verifica se o forca_bot foi excluido ou se ele existe no BD
        def verifyBot(left_chat_participant=None):
            if left_chat_participant:
                first_name = left_chat_participant["first_name"].encode("utf-8")
                if first_name == "@hangerbot":
                    bds.delChat(chat_id)
                    return
            return

        # Dados que recebemos do telegram
        update_id = body["update_id"]
        message = body["message"]
        message_id = str(message.get("message_id")).encode("utf-8")
        left_chat_participant = message.get("left_chat_participant")
        new_chat_participant = message.get("new_chat_participant")
        group_chat_created = message.get("group_chat_created")
        date = message.get("date")
        text = message.get("text").encode("utf-8").lower() if message.get("text") else message.get("text")
        fr = message.get("from")
        chat = message["chat"]
        chat_id = str(chat["id"])
        user_id = message["from"]
        u_id = str(user_id.get("id")).encode("utf-8")
        u_name = user_id.get("first_name").encode("utf-8")

        #'Chama' a verificação
        if left_chat_participant:
            verifyBot(left_chat_participant=left_chat_participant)

        if not text:
            logging.info("no text")
            return

        # Função que envia o dict para o Telegram
        def reply(dict=None):
            if dict:
                resp = urllib2.urlopen(BASE_URL + "sendMessage", urllib.urlencode(dict)).read()
            else:
                logging.error("no msg or img specified")
                resp = None
            logging.info("send response:")
            logging.info(resp)

        # Lê as configurações
        def getLanguage(chat_id):
            s = bds.getSettings(chat_id)  # Classe settings
            if s:
                if s.language == "ptBR":
                    import ptBR as l

                    return l
                elif s.language == "enUS":
                    import enUS as l

                    return l
            else:
                bds.checkChat(chat_id)
                s = bds.getSettings(chat_id)  # Classe settings
                if s.language == "ptBR":
                    import ptBR as l

                    return l
                elif s.language == "enUS":
                    import enUS as l

                    return l
                return

        # Aqui começa a lógica principal
        l = getLanguage(chat_id)
        s = bds.getSettings(chat_id)
        ab = bds.getArriscarBlock(chat_id)
        first = bds.getFirstWelcome(chat_id)[0]
        rpl = [c.toDict(chat_id, "comando não reconhecido")]
        text = "/start" if text == l.ligar.lower() else text  # Tratamento para o caso do /start
        text = l.ajuda.lower() if text.startswith("/help") else text
        text = l.desligar.lower() if text.startswith("/stop") else text
        if text.startswith("@ccuem_bot"):
            text = text[11:]
        if u_id in creators:
            if text.startswith("/delchatadmin"):
                chat = text[14:]
                if len(chat) > 0:
                    if bds.delChat(chat):
                        rpl = [c.toDict(chat_id, "Chat " + chat + "deletado")]
                    rpl = [c.toDict(chat_id, "Chat " + chat + " não existe")]
        if (not s.waiting) or first:
            # comandos que indiferem do estado atual de jogo
            if "/start" in text:
                rpl = c.start(chat_id, u_id, message_id, first)
            elif bds.getEnabled(chat_id):
                if "/kb" in text:
                    rpl = c.kb(chat_id, u_id, message_id)
                elif l.desligar.lower() in text:
                    rpl = c.stop(chat_id)
                elif l.ajuda.lower() in text:
                    rpl = c.ajuda(chat_id)
                elif l.rank.lower() in text:
                    rpl = c.rank(chat_id)
                elif l.config.lower() in text:
                    rpl = c.config(chat_id, message_id)
                elif l.voltar.lower() in text:
                    rpl = c.voltar(chat_id, l.voltar_msg, message_id, u_id)
                elif l.comandos.lower() in text:
                    rpl = c.comandos(chat_id, message_id, u_id)
                # comandos inGame
                elif bds.getInGame(chat_id):
                    check = bds.checkUid(chat_id, u_id)
                    if l.cancelar_jogo.lower() in text:
                        rpl = g.cancelarJogo(chat_id, u_id)
                    elif check == True:
                        if bds.getArriscarBlock(chat_id):
                            rpl = g.arriscarPalavra2(chat_id, u_id, u_name, message_id, text)
                        elif l.arriscar.lower() in text:
                            rpl = g.arriscarPalavra1(chat_id, u_id, message_id)
                        elif (len(text) == 1) or (text.startswith("@ccuemBot")):
                            if text.startswith("@ccuemBot"):
                                text = text[10:]
                            rpl = g.chutarLetra(chat_id, u_id, message_id, text)
                    elif check == "rnd":
                        rpl = [c.toDict(chat_id, l.round_errado_msg)]
                    elif check == "out":
                        rpl = [c.toDict(chat_id, l.fora_msg)]

                # comandos preGame
                elif bds.getPreGame(chat_id):
                    if l.entrar.lower() in text:
                        rpl = p.entrar(chat_id, u_id, u_name, message_id)
                    elif l.sair.lower() in text:
                        rpl = p.sair(chat_id, u_id, u_name, message_id)
                    elif l.fechar_jogo.lower() in text:
                        rpl = p.fecharJogo(chat_id, u_id, message_id)
                    elif l.cancelar_jogo.lower() in text:
                        rpl = p.cancelarJogo(chat_id, u_id)
                # se preGame e inGame == False (vide flowchart)
                elif (not bds.getPreGame(chat_id)) and (not bds.getInGame(chat_id)):
                    if l.novojogo.lower() in text:
                        rpl = c.novojogo(chat_id, u_id, u_name, message_id)
        else:
            if l.ajuda.lower() in text:
                rpl = c.ajuda(chat_id)
            else:
                rpl = c.changeLanguage(chat_id, text, message_id, u_id)
        try:
            for i in range(len(rpl)):
                reply(rpl[i])
        except Exception, e:
            print e
            reply(c.toDict(chat_id, "erro"))
Beispiel #16
0
 elif l.desligar.lower() in text:
     rpl = c.stop(chat_id)
 elif l.ajuda.lower() in text:
     rpl = c.ajuda(chat_id)
 elif l.rank.lower() in text:
     rpl = c.rank(chat_id)
 elif l.config.lower() in text:
     rpl = c.config(chat_id, message_id)
 elif l.sobre.lower() in text:
     rpl = c.sobre(chat_id)
 elif l.voltar.lower() in text:
     rpl = c.voltar(chat_id, l.voltar_msg, message_id, u_id)
 elif l.comandos.lower() in text:
     rpl = c.comandos(chat_id, message_id, u_id)
 #comandos inGame
 elif bds.getInGame(chat_id):
     check = bds.checkUid(chat_id, u_id)
     if l.cancelar_jogo.lower() in text:
         rpl = g.cancelarJogo(chat_id, u_id)
     elif check == True:
         if bds.getArriscarBlock(chat_id):
             rpl = g.arriscarPalavra2(chat_id, u_id, u_name,
                                      message_id, text)
         elif l.arriscar.lower() in text:
             rpl = g.arriscarPalavra1(chat_id, u_id, message_id)
         elif (len(text)
               == 1) or (text.startswith('@PlayHangmanBot')):
             if text.startswith('@PlayHangmanBot'):
                 text = text[10:]
             rpl = g.chutarLetra(chat_id, u_id, u_name,
                                 message_id, text)