예제 #1
0
def funcAleatorio(sender,msg):
    msg = msg.split()
    if(len(msg) == 1):
        retorno = 'Para usar a função Aleatorio, favor seguir o seguinte modelo ex: Aleatorio [Quantidade de Números] [Minimo] [Maximo]'
        payloadTextoSimples(sender,retorno)
    else:
        try:
            qtd = int(mensagem[1])
        except SyntaxError:
            retorno = "Para usar essa função se deve passar 3 Argumentos, Quantidade de Numeros, o Valor *Minimo e o *Maximo"
            payloadTextoSimples(sender, retorno)
            retorno = "Exemplo: Aleatorio 6 1 60 \n Aleatorio 6, Consideramos o valor minimo e maximo default como 1-60"
            payloadTextoSimples(sender, retorno)
            return 0
        try:
            minimo = int(mensagem[2])
        except IndexError:
            minimo = 1

        try:
            maximo = int(mensagem[3])
        except IndexError:
            maximo = 60

        if qtd > (maximo - minimo):
            retorno = "Valores Invalidos"
            payloadTextoSimples(sender,retorno)
        else:
            lista = geraAleatorio(qtd,minimo,maximo)
            lista.sort()
            texto = str(lista[0])
            for i in lista[1:]:
                texto = texto + "-" + str(i)
            retorno = "Os {} Números sorteados entre {}-{} foram: \n".format(qtd,minimo,maximo) + texto
            payloadTextoSimples(sender, retorno)
예제 #2
0
파일: app.py 프로젝트: chrmorais/RannyBot
def handle_mqtt_message(client, userdata, message):
    data = dict(
        topic=message.topic,
        payload=message.payload.decode()
    )
    s = message.payload.decode()
    json_acceptable_string = s.replace("'", "\"")
    d = json.loads(json_acceptable_string)
    payloadTextoSimples(d['sender'],d['msg'])
예제 #3
0
def FuncCryptomoeda(sender, msg):
	msg = msg.split()    
	if(len(msg) == 1):
		retorno = 'Para usar a função Cryptomoeda, favor seguir o seguinte modelo ex: Cryptomoeda Bitcoin ou Crypto BTC'
		listaReplies = ['Cryptomoeda Bitcoin', 'Crypto BTC']
		payloadReplies(sender,retorno,listaReplies)
	else:
		retorno = cryptoLista(msg[1])
		payloadTextoSimples(sender, retorno)
예제 #4
0
파일: wiki.py 프로젝트: chrmorais/RannyBot
def wiki(sender,pesq):
    url = requests.get('https://pt.wikipedia.org/w/api.php?action=opensearch&search='+pesq+'=1&namespace=0&format=json')
    result = json.loads(url.text)
    a = result[1]
    b = result[2]
    c = result[3]
    lista = [a,b,c]
    if len(a) == 0:
    	retorno = "Vish, Não encontramos nada para isso."
    	payloadTextoSimples(sender, retorno)
    else:
	    for i in range(len(a)):
	    	retorno = "{}: {} \nPARA MAIS INFORMAÇÕES ACESSE:{}".format(a[i], b[i],c[i])
	    	payloadTextoSimples(sender, retorno)
예제 #5
0
def funcPiada(sender):
    pageNum = randint(1, 40)
    lista = raspalink(str(pageNum))
    link = choice(lista)
    retorno = raspaPiada(link)
    payloadTextoSimples(sender, retorno)
예제 #6
0
파일: app.py 프로젝트: chrmorais/RannyBot
def webhook():
    if request.method == 'POST':
        try:
            data = json.loads(request.data)

            text = data['entry'][0]['messaging'][0]['message']['text'] # mensagem recebida
            #A principio nao vai precisar mais :)
            #msg = str(text.lower()) #mensagem json para string
            msg = tratatexto(str(text))

            #Variaveis
            '''
            #text = MENSAGEM QUE CHEGA PARA O FACEBOOK
            #msg = text tratado.
            #sender = quem enviou a msg.
            '''
            sender = data['entry'][0]['messaging'][0]['sender']['id'] # id do mensageiro

            if msg in entrada:
                retorno = 'Olá, tudo bem? Em que posso lhe ajudar, Você já conhece minhas funções? :)'#Mensagem de retorno ao usuario
                payloadTextoSimples(sender,retorno)
                funcFuncao(sender)

            elif msg in listafuncao:
                funcFuncao(sender)

            elif msg in sentimentos:
                retorno = 'Estou muito Bem :) Obrigado.'
                payloadTextoSimples(sender,retorno)

            elif msg in tchau:
                retorno = 'Até mais :), estou a sua disposição'
                payloadTextoSimples(sender,retorno)

            elif msg in ajuda:
            	listaAjuda = [['Policia','190'],['SAMU','192'],['Bombeiro','193']]
            	payloadAjuda(sender,listaAjuda)

            elif msg in meuid:
                payloadTextoSimples(sender,str(sender))

            elif msg in teste:
                testepayload(sender)

            else:
                #Aqui começa a parte via token:
                splitz = msg.split()
                if splitz[0] in noticias:
                    funcNoticias(sender,msg)

                elif splitz[0] in aleatorio:
                    funcAleatorio(sender,msg)

                elif splitz[0] in wiki:
                    funcWiki(sender,msg)

                elif splitz[0] in games:
                    funcGames(sender, msg)

                elif splitz[0] in cryptocoin:
                    from bitcoin import FuncCryptomoeda
                    FuncCryptomoeda(sender,msg)

                else:
                    retorno='Isso não faz parte da minha função.'
                    payloadTextoSimples(sender,retorno)
                    funcFuncao(sender)

        except Exception as e:
           print(traceback.format_exc())

    elif request.method == 'GET': # Para a verificação inicial
        if request.args.get('hub.verify_token') == tokenVerify:
            print("verificado")
            return request.args.get('hub.challenge')
        return render_template("home.html")
    return "Nada retornado"
예제 #7
0
def funcNoticias(sender, msg):
    retorno = NoticiaEsporte(sender, msg)
    print(retorno)
    for i in retorno:
        payloadTextoSimples(sender, i)