SHARE
TWEET

Untitled

a guest Dec 9th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. from xmpp import *
  3. import debugHandlers
  4.  
  5.  
  6.  
  7.  
  8. def messageHandler(sess,mess):
  9.     if mess.getAttr('type')=='groupchat': #if message from group chat
  10.         time=mess.getTimestamp()
  11.         if time==None:                        #if messages are new    
  12.             text=mess.getBody()               #get text
  13.             nick=mess.getFrom().getResource() #get nick
  14.                       #also get time
  15.             print(time,nick,text)
  16. #
  17. #    node=mess.getFrom().getNode()  
  18. #    dom= mess.getFrom().getDomain()
  19. #    wtf= mess.getFrom().getStripped()
  20. #    to = mess.getAttrs()
  21. #    subj=mess.getSubject()
  22. #    thread=mess.getThread()  
  23. #    print(dir(mess))
  24. #    print(dir(sess))
  25.  
  26. def presenceHandler(sess,pres):
  27.     if pres.getStatusCode()=='307':     #kicked
  28.         print pres.getFrom().getResource(),'was kicked'
  29.         print 'Reason:%s'%pres.getReason()
  30.     if pres.getStatusCode()=='301':       #banned
  31.         print pres.getFrom().getResource(),'was banned'
  32.         print 'Reason:%s'%pres.GetReason()
  33.         cl.reconnectAndReauth()
  34.        
  35. #    print ('getFrom().get')
  36.     print pres.getFrom().getResource() #Sender nick
  37.     print pres.getFrom().getNode()     #Sender room
  38.     print pres.getFrom().getDomain()   #sender domain
  39.     print pres.getFrom().getStripped() #sender room@domain
  40. #    print ('get*()')
  41.     print pres.getStatus()             #None
  42.     print pres.getStatusCode()         #None,307 when kicked
  43. #    print pres.getTo()                #
  44.     print pres.getType()               #None, error, unavailable when someone
  45.                                        #exit or kicked
  46.     print pres.getReason()             #None or Reason of kick/ban
  47.     print pres.getTags(pres)           #[]
  48.  
  49.  
  50.    
  51.  
  52. Account=('なの@jabber.jp','','Nano')  
  53. PROXY={}
  54. Conf=('NanoRoom@Conference.jabber.jp','')
  55. printing=True
  56.  
  57. cl=Client('jabber.jp',debug=[])
  58. cl.connect(PROXY)
  59. cl.RegisterHandler('message',debugHandlers.messDebugHandler)
  60. cl.RegisterHandler('presence',presenceHandler)
  61. cl.auth(JID(Account[0]).getNode(),Account[1],Account[2])
  62. p=Presence(to='%s/Nano'%Conf[0])
  63. p.setTag('None',namespace=NS_MUC).setTagData('password',Conf[1])
  64. print p
  65. print cl.User
  66. print cl.Resource
  67. print dir(cl)
  68. cl.send(p)
  69. while cl.isConnected():
  70.     cl.Process(1)
  71. print("I'm gone")
  72. #exit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top