Advertisement
Guest User

bino-echobot.py

a guest
Aug 31st, 2010
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. #echobot.py
  2. from twisted.words.xish import domish
  3. from wokkel.xmppim import MessageProtocol, AvailablePresence
  4.  
  5. from twisted.web import xmlrpc
  6.  
  7.  
  8. class EchoBotProtocol(MessageProtocol):
  9.     def connectionMade(self):
  10.         print "Connected!"
  11.  
  12.         # send initial presence
  13.         self.send(AvailablePresence())
  14.  
  15.     def connectionLost(self, reason):
  16.         print "Disconnected!"
  17.  
  18.     def onMessage(self, msg):
  19.         print str(msg)
  20.  
  21.         if msg["type"] == 'chat' and hasattr(msg, "body"):
  22.             reply = domish.Element((None, "message"))
  23.             reply["to"] = msg["from"]
  24.             reply["from"] = msg["to"]
  25.             reply["type"] = 'chat'
  26.             reply.addElement("body", content="echo: " + str(msg.body))
  27.  
  28.             self.send(reply)
  29.     def mycall(self, msg):
  30.         print "ooppss= "+(msg)
  31.  
  32.         reply = domish.Element((None, "message"))
  33.         reply["to"] = 'bino@jabber.int'
  34.         reply["from"] = 'iwic02@jabber.int'
  35.         reply["type"] = 'chat'
  36.         reply.addElement("body", content='Some body sent this : ' + str((msg)))
  37.  
  38.         xmppclient.send(reply)
  39.        
  40.  
  41.         return 'your msg is : '+ msg
  42.  
  43. class MyRPC(xmlrpc.XMLRPC):
  44.     def __init__(self):
  45.         self.allowNone = True
  46.         self.useDateTime = False
  47.         self.fc = EchoBotProtocol()
  48.         #self.fc = echobot()
  49.  
  50.     def xmlrpc_dispatch(self, m):
  51.         return self.fc.mycall(m)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement