moved
Ok. I will no longer be posting on livejournal. I have moved my blog to http://thetofu.com
Thanks lj!
Thanks lj!
By logging in to LiveJournal using a third-party service you accept LiveJournal's User agreement
svn co https://svn.ik.nu/wokkel/branches/wokkel-muc-client-support-24 wokkel python setup.py install
""" A simple last bot wokkel example """ from twisted.internet import defer import datetime from twisted.words.protocols.jabber import jid from wokkel import muc class MUCLastBot(muc.MUCClient): """ """
def __init__(self, server, room, nick): muc.MUCClient.__init__(self) self.server = server self.room = room self.nick = nick self.room_jid = jid.internJID(self.room+'@'+self.server+'/'+self.nick) self.last = {} self.activity = None def _getLast(self, nick): return self.last.get(nick.lower()) def _setLast(self, user): user.last = datetime.datetime.now() self.last[user.nick.lower()] = user self.activity = user
def initialized(self): """The bot has connected to the xmpp server, now try to join the room. """ self.join(self.server, self.room, self.nick).addCallback(self.initRoom) @defer.inlineCallbacks def initRoom(self, room): """Configure the room if we just created it. """ if int(room.status) == muc.STATUS_CODE_CREATED: config_form = yield self.getConfigureForm(self.room_jid.userhost()) # set config default config_result = yield self.configure(self.room_jid.userhost())
def userJoinedRoom(self, room, user): """If a user joined a room, make sure they are in the last dict """ self._setLast(user) def userLeftRoom(self, room, user): self._setLast(user)
def receivedGroupChat(self, room, user, body): # check if this message addresses the bot cmd = None user_nick = None try: cmd, user_nick = body.split(" ") except ValueError: # value error means it was a one word body cmd = body cmd = cmd.replace("!", "") method = getattr(self, 'cmd_'+cmd, None) if method: method(room, user_nick) # log last message user.last_message = body self._setLast(user)
def cmd_last(self, room, user_nick): """ """ if user_nick is None: # show last person to do something self._sendLast(room, self.activity) else: u = self._getLast(user_nick) if u: self._sendLast(room, u) else: self.groupChat(self.room_jid, 'Sorry %s, That person is unknown to me.' % (user.nick,)) def _sendLast(self, room, user): """ Grab last information from user and room and send it to the room. """ last_message = getattr(user,'last_message', '') last_stamp = getattr(user,'last', '') if room.inRoster(user): message = """%s is in this room and said '%s' at %s.""" % (user.nick, last_message, last_stamp) else: message = """%s left this room at %s and last said '%s'.""" % (user.nick, last_stamp, last_message) self.groupChat(self.room_jid, message)
from twisted.application import service from twisted.words.protocols.jabber import jid from wokkel.client import XMPPClient from client import MUCLastBot application = service.Application("lastbot") xmppclient = XMPPClient(jid.internJID("test@thetofu.com/lastbot"), "test") xmppclient.logTraffic = True mucbot = MUCLastBot('chat.speeqe.com','last', 'LastBot') mucbot.setHandlerParent(xmppclient) xmppclient.setServiceParent(application)
twisted -y muc.tac
====================== teams by rating ========================== team rating rd total wins - losses New York Yankees 1580.0 28.465171 162 94 - 68 Boston Red Sox 1571.0 29.260524 162 96 - 66 Cleveland Indians 1564.0 28.649712 162 96 - 66 Los Angeles Angels of Anaheim 1562.0 28.888047 162 94 - 68 Arizona Diamondbacks 1537.0 28.440955 162 90 - 72 Colorado Rockies 1534.0 28.165939 163 90 - 73 Detroit Tigers 1533.0 28.574597 162 88 - 74 Seattle Mariners 1532.0 28.210795 162 88 - 74 Toronto Blue Jays 1529.0 28.210438 162 83 - 79 Philadelphia Phillies 1529.0 28.447520 162 89 - 73 San Diego Padres 1523.0 28.317698 163 89 - 74 New York Mets 1510.0 28.604631 162 88 - 74 Los Angeles Dodgers 1505.0 28.615645 162 82 - 80 Minnesota Twins 1495.0 28.312780 162 79 - 83 Atlanta Braves 1494.0 28.618743 162 84 - 78 Chicago Cubs 1494.0 28.402241 162 85 - 77 Oakland Athletics 1488.0 28.395109 162 76 - 86 Texas Rangers 1487.0 28.586974 162 75 - 87 Milwaukee Brewers 1474.0 28.445591 162 83 - 79 St. Louis Cardinals 1464.0 28.453097 162 78 - 84 Washington Nationals 1462.0 28.858994 162 73 - 89 San Francisco Giants 1462.0 28.315478 162 71 - 91 Chicago White Sox 1461.0 28.461948 162 72 - 90 Kansas City Royals 1461.0 28.856424 162 69 - 93 Baltimore Orioles 1460.0 28.501870 162 69 - 93 Tampa Bay Rays 1450.0 28.742325 162 66 - 96 Houston Astros 1448.0 28.453125 162 73 - 89 Cincinnati Reds 1442.0 28.818955 162 72 - 90 Florida Marlins 1438.0 28.412856 162 71 - 91 Pittsburgh Pirates 1424.0 28.681253 162 68 - 94