Пример #1
0
class CloneClient(mucroombot.ChatClient):
    def __init__(self, jid, password, nick):
        super(CloneClient, self).__init__(jid, password, nick)
        self.responder = MarkovChain(PidginLogs("~/.purple/logs/jabber/%s/" % jid.as_utf8(), select_nick=nick))

    def session_started(self):
        self._session_started_helper(MucClient(self), JID(ROOM, SERVER))

    def autorespond(self, body):
        if (not self.nick in body) and random() < 0.6:
            return None
        r = self.responder.get(body)
        rr = repr(r)
        if rr[rr.find("'") + 1 : rr.rfind("'")] != r or len(r.split()) < 2:
            return None
        return r

    def message(self, stanza):
        body = stanza.get_body()
        frm = stanza.get_from().as_utf8().split("@")[0]
        if stanza.get_type() == "headline":
            return True
        print colorize("g", frm + ":"), body
        response = self.autorespond(body)
        return Message(
            to_jid=stanza.get_from(),
            from_jid=stanza.get_to(),
            stanza_type=stanza.get_type(),
            subject=stanza.get_subject(),
            body=response,
        )
Пример #2
0
class CloneClient(mucroombot.ChatClient):
    def __init__(self, jid, password, nick):
        super(CloneClient, self).__init__(jid, password, nick)
        self.responder = MarkovChain(
            PidginLogs('~/.purple/logs/jabber/%s/' % jid.as_utf8(),
                       select_nick=nick))

    def session_started(self):
        self._session_started_helper(MucClient(self), JID(ROOM, SERVER))

    def autorespond(self, body):
        if (not self.nick in body) and random() < 0.6: return None
        r = self.responder.get(body)
        rr = repr(r)
        if rr[rr.find("'") + 1:rr.rfind("'")] != r or len(r.split()) < 2:
            return None
        return r

    def message(self, stanza):
        body = stanza.get_body()
        frm = stanza.get_from().as_utf8().split('@')[0]
        if stanza.get_type() == "headline": return True
        print colorize('g', frm + ':'), body
        response = self.autorespond(body)
        return Message(to_jid=stanza.get_from(),
                       from_jid=stanza.get_to(),
                       stanza_type=stanza.get_type(),
                       subject=stanza.get_subject(),
                       body=response)
Пример #3
0
class ShakespeareClient(mucroombot.ChatClient):

    def __init__(self, jid, password, pages, character):
        super(ShakespeareClient,self).__init__(jid,password,character)
        self.responder = MarkovChain(parse_shakespeare(pages,self.nick if self.nick != 'will' else None))

    def session_started(self):
        self._session_started_helper(MucClient(self),JID(ROOM,SERVER))

    def autorespond(self,body,rate=0.2):
        if random() > rate: return None
        return self.responder.get(body)
        
    def message(self,stanza):
        body=stanza.get_body()
        frm = stanza.get_from().as_utf8().split('@')[0]
        print stanza.get_type()
        if stanza.get_type()=="headline": return True
        print colorize('g',frm+':'),body
        sleep(random())
        response = self.autorespond(body,1.0)
        return Message(to_jid=stanza.get_from(),
                       from_jid=stanza.get_to(),
                       stanza_type=stanza.get_type(),
                       subject=stanza.get_subject(),
                       body=response)