def do_login(self, email, logtype, msg):
        """
        Performs the chat log.
        """
        if CONFIG["log history"]:
            logfile = CONFIG["history directory"] + "/" + email
            if logtype == "in":
                lines = chatbotini.now() + " <<< " + str(msg) + "\n"
            elif logtype == "out":
                lines = chatbotini.now() + " >>> " + str(msg) + "\n"

            file_dict = open(logfile, "a")
            file_dict.write(lines)
            file_dict.close()
Beispiel #2
0
    def do_login(self, email, log_type, msg):
        """
        Performs the chat log.
        """
        if CONFIG["log history"]:
            logfile = "%s/%s" % (CONFIG["history directory"], email)
            lines = '\n'
            if log_type == "in":
                lines = "%s <<< %s\n" % (chatbotini.now(), str(msg))
            elif log_type == "out":
                lines = "%s >>> %s\n" % (chatbotini.now(), str(msg))

            file_dict = open(logfile, "a")
            file_dict.write(lines)
            file_dict.close()
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)
Beispiel #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)