コード例 #1
0
def rpta_gtalk(conn, mess):
    """
    Respond to messages from gtalk contacts.
    """
    logtime = chatbotini.now()
    text = mess.getBody()
    #so you can convert to lower case
    text = text.replace(
                    u"\xe1", u"a").replace(
                    u"\xe9", u"e").replace(
                    u"\xed", u"i").replace(
                    u"\xf3", u"o").replace(
                    u"\xfa", u"u").replace(
                    "+", " mas ")
    #text = text.replace(u"\xbf",u"") ##u"\xbf" = ¿
    user = mess.getFrom()
    user.lang = "en"   # dup
    senderemail = user.getStripped()
    try:
        message = text.lower().replace("\n", " ").encode("utf-8")
    except AttributeError:
        message = ""
    # Log query message
    registrochat(("%s <<< %s\n" % (logtime, message)), senderemail)
    remsg = chatbotini.action_process(message, senderemail,
        conn=CONN, mess=mess)
    #stores the questions that have no answers
    record_questions_unanswered(message, remsg, senderemail,
                     logtime[1:11], logtime[12:20])
    if remsg:
        extramsg = u""
        if cache_read_rpta(senderemail) == 1:
            try:
                anios = int(text)
                if anios < 5:
                    extramsg = u"""Tan joven y ya sabes escribir?"""
                if anios > 95:
                    extramsg = u"""Vaya eres la persona más longeva que
                        estoy conociendo!"""
            except:
                pass
        message = xmpp.Message(to=mess.getFrom(),
                 body=extramsg.encode("utf-8") + remsg, typ="chat")
        CONN.send(unicode(message).encode("utf-8").replace(r"\n", "\n"))
    # Log response message
    try:
        message = message.getBody()
        registrochat(("%s >>> %s\n" % (logtime, message.encode(
        "utf-8"))), senderemail)
    except AttributeError:
        pass

    cache_write_rpta(remsg, senderemail)
コード例 #2
0
ファイル: chatbot_msn_setup.py プロジェクト: alfonsodg/sboty
def display_message(email, lines, eoh=0):
    """
    Prints an incoming message and an optional pointer at the
    end of your header.
    :rtype : Bool
    """
    message = ""

    substitutions = [
        ("\xc3\xb1", "n"),
        ("\xc3\xa1", "a"),
        ("\xc3\xa9", "e"),
        ("\xc3\xad", "i"),
        ("\xc3\xb3", "o"),
        ("\xc3\xba", "u")]

    for line in lines[-1:]:
        for search, replacement in substitutions:
            line = line.replace(search, replacement)

        message += line.strip() + " "

    message = message.strip().decode("utf-8", "ignore")

    # Log query message
    USE_FUNCTION.do_login(email, "in", message.encode("utf-8"))
    message_to_send = chatbotini.action_process(message, email, msn=MSN)

    # We really need to add empty string??
    extra_message = u""
    message_to_send += extra_message.encode("utf-8")

    MSN.sendmsg(email, message_to_send.replace(r"\n", "\n"))

    # Log response message
    USE_FUNCTION.do_login(email, "out", message_to_send)
コード例 #3
0
def disp_message(email, lines, eoh=0):
    """
    Prints an incoming message and an optional pointer at the
    end of your header.
    """
    message = ""
    for line in lines[-1:]:
        line = line.replace(
                    "\xc3\xb1", "n").replace(
                    "\xc3\xa1", "a").replace(
                    "\xc3\xa9", "e").replace(
                    "\xc3\xad", "i").replace(
                    "\xc3\xb3", "o").replace(
                    "\xc3\xba", "u")
        message += line.strip() + " "
    message = message.strip().decode("utf-8", "ignore")
    # Log query message
    USEF_FUNCT.do_login(email, "in", message.encode("utf-8"))
    message_to_send = chatbotini.action_process(message, email, msn=MSN)
    extramsg = u""
    message_to_send += extramsg.encode("utf-8")
    MSN.sendmsg(email, message_to_send.replace(r"\n", "\n"))
    # Log response message
    USEF_FUNCT.do_login(email, "out", message_to_send)
コード例 #4
0
def reply_gtalk(conn, mess):
    """
    Respond to messages from gtalk contacts.
    """
    log_time = chatbotini.now()
    text = mess.getBody()
    #so you can convert to lower case

    substitutions = [
        (u"\xe1", u"a"),
        (u"\xe9", u"e"),
        (u"\xed", u"i"),
        (u"\xf3", u"o"),
        (u"\xfa", u"u"),
        ("+", " mas ")]
    for search, replacement in substitutions:
        text = text.replace(search, replacement)

    #text = text.replace(u"\xbf",u"") ##u"\xbf" = ¿
    user = mess.getFrom()
    user.lang = "en"   # dup
    sender_email = user.getStripped()

    try:
        message = text.lower().replace("\n", " ").encode("utf-8")
    except AttributeError:
        message = ""

    # Log query message
    chat_registrar(("%s <<< %s\n" % (log_time, message)), sender_email)

    re_msg = chatbotini.action_process(
        message, sender_email, conn=CONN, mess=mess)

    #stores the questions that have no answers
    record_questions_unanswered(
        message, sender_email, log_time[1:11], log_time[12:20])
    if re_msg:
        extra_msg = u""
        if cache_read_reply(sender_email):
            # try except really needed?
            try:
                age = int(text)
            except Exception:
                pass
            else:
                if age < 5:
                    extra_msg = u"Tan joven y ya sabes escribir?"
                if age > 95:
                    extra_msg = (u"Vaya eres la persona más longeva que" +
                                u"estoy conociendo!")
        message = xmpp.Message(
            to=mess.getFrom(), body=extra_msg.encode("utf-8") + re_msg,
            typ="chat")
        conn.send(unicode(message).encode("utf-8").replace(r"\n", "\n"))

    # Log response message
    try:
        message = message.getBody()
        chat_registrar(
            ("%s >>> %s\n" % (log_time, message.encode("utf-8"))), sender_email)
    except AttributeError:
        pass
    else:
        chatregistry(
            ("%s >>> %s\n" % (logtime, message.encode("utf-8"))), senderemail)
    cache_write_reply(re_msg, sender_email)