Пример #1
0
 def part(self, channel):
     """ leave conference. """
     if channel.startswith("#"): return
     presence = Presence({'to': channel})
     presence.type = 'unavailable'
     self.send(presence)
     if channel in self.state['joinedchannels']: self.state['joinedchannels'].remove(channel)
     self.state.save()
     return 1
Пример #2
0
 def part(self, channel):
     """ leave conference. """
     if channel.startswith("#"): return
     presence = Presence({'to': channel})
     presence.type = 'unavailable'
     self.send(presence)
     if channel in self.state['joinedchannels']: self.state['joinedchannels'].remove(channel)
     self.state.save()
     return 1
Пример #3
0
 def handle_presence(self, data, *args, **kwargs):
     """ message handler. """
     try:
         p = Presence()
         p.parse(data, self)
         frm = p.fromm
         nickk = ""
         nick = p.nick
         if self.cfg.user in frm: self.pongcheck = True
         if nick:
             self.userhosts[nick] = stripped(frm)
             nickk = nick
         jid = p.fromm
         if nickk and jid and self.cfg.fulljids:
             channel = p.channel
             if not self.jids.has_key(channel):
                 self.jids[channel] = {}
             self.jids[channel][nickk] = jid
             self.userhosts[nickk] = stripped(jid)
             logging.debug(
                 '%s - setting jid of %s (%s) to %s' %
                 (self.cfg.name, nickk, channel, self.userhosts[nickk]))
         if p.type == 'subscribe':
             pres = Presence({'to': p.fromm, 'type': 'subscribed'})
             self.send(pres)
             pres = Presence({'to': p.fromm, 'type': 'subscribe'})
             self.send(pres)
         nick = p.resource
         if p.type != 'unavailable':
             p.joined = True
             p.type = 'available'
         elif self.cfg.user in p.userhost:
             try:
                 del self.jids[p.channel]
                 logging.debug('%s - removed %s channel jids' %
                               (self.cfg.name, p.channel))
             except KeyError:
                 pass
         else:
             try:
                 del self.jids[p.channel][p.nick]
                 logging.debug('%s - removed %s jid' %
                               (self.cfg.name, p.nick))
             except KeyError:
                 pass
         self.put(p)
     except Exception, ex:
         logging.error(str(ex))
Пример #4
0
 def handle_presence(self, data, *args, **kwargs):
     """ message handler. """   
     try:
         p = Presence()
         p.parse(data, self)
         frm = p.fromm
         nickk = ""   
         nick = p.nick
         if self.cfg.user in frm: self.pongcheck = True
         if nick: 
             self.userhosts[nick] = stripped(frm)
             nickk = nick
         jid = p.fromm
         if nickk and jid and self.cfg.fulljids:
             channel = p.channel
             if not self.jids.has_key(channel):
                 self.jids[channel] = {}
             self.jids[channel][nickk] = jid
             self.userhosts[nickk] = stripped(jid)
             logging.debug('%s - setting jid of %s (%s) to %s' % (self.cfg.name, nickk, channel, self.userhosts[nickk]))
         if p.type == 'subscribe':
             pres = Presence({'to': p.fromm, 'type': 'subscribed'})
             self.send(pres)
             pres = Presence({'to': p.fromm, 'type': 'subscribe'})
             self.send(pres)
         nick = p.resource
         if p.type != 'unavailable':
             p.joined = True
             p.type = 'available'
         elif self.cfg.user in p.userhost:
             try:
                 del self.jids[p.channel]
                 logging.debug('%s - removed %s channel jids' % (self.cfg.name, p.channel))
             except KeyError: pass
         else:   
             try:
                 del self.jids[p.channel][p.nick]
                 logging.debug('%s - removed %s jid' % (self.cfg.name, p.nick))
             except KeyError: pass
         self.put(p)
     except Exception, ex: logging.error(str(ex))
Пример #5
0
 def handle_presence(self, data):
     """ presence handler. """
     p = Presence(data)
     p.parse()
     frm = p.fromm
     nickk = ""
     nick = p.nick
     if self.cfg.user in frm: self.pongcheck = True 
     if nick: 
         self.userhosts[nick] = stripped(frm)
         nickk = nick
     jid = None
     for node in p.subelements:
         try:
             jid = node.x.item.jid 
         except (AttributeError, TypeError):
             continue
     if nickk and jid and self.cfg.fulljids:
         channel = p.channel
         if not self.jids.has_key(channel):
             self.jids[channel] = {}
         self.jids[channel][nickk] = jid
         self.userhosts[nickk] = stripped(jid)
         logging.debug('%s - setting jid of %s (%s) to %s' % (self.cfg.name, nickk, channel, self.userhosts[nickk]))
     if p.type == 'subscribe':
         pres = Presence({'to': p.fromm, 'type': 'subscribed'})
         self.send(pres)
         pres = Presence({'to': p.fromm, 'type': 'subscribe'})
         self.send(pres)
     nick = p.resource
     if p.type != 'unavailable':
         p.joined = True
         p.type = 'available'
     elif self.cfg.user in p.userhost:
         try:
             del self.jids[p.channel]
             logging.debug('%s - removed %s channel jids' % (self.cfg.name, p.channel))
         except KeyError:
             pass
     else:
         try:
             del self.jids[p.channel][p.nick]
             logging.debug('%s - removed %s jid' % (self.cfg.name, p.nick))
         except KeyError:
             pass
     if p.type == 'error':
         for node in p.subelements:
             try:
                 err = node.error.code
             except (AttributeError, TypeError):
                 err = 'no error set'
             try:
                 txt = node.text.data
             except (AttributeError, TypeError):
                 txt = ""
         if err:
             logging.error('%s - error - %s - %s'  % (self.cfg.name, err, txt))
         try:
             method = getattr(self,'handle_' + err)
             try:
                 method(p)
             except:
                 handle_exception()
         except AttributeError:
             pass
     self.doevent(p)
Пример #6
0
 def handle_presence(self, data):
     """ presence handler. """
     p = Presence(data)
     p.parse()
     frm = p.fromm
     nickk = ""
     nick = p.nick
     if self.me in p.userhost: return 0
     if nick: 
         self.userhosts[nick] = str(frm)
         nickk = nick
     jid = None
     for node in p.subelements:
         try:
             jid = node.x.item.jid 
         except (AttributeError, TypeError):
             continue
     if nickk and jid:
         channel = p.channel
         if not self.jids.has_key(channel):
             self.jids[channel] = {}
         self.jids[channel][nickk] = jid
         self.userhosts[nickk] = str(jid)
         logging.debug('%s - setting jid of %s (%s) to %s' % (self.name, nickk, channel, jid))
     if p.type == 'subscribe':
         pres = Presence({'to': p.fromm, 'type': 'subscribed'})
         self.send(pres)
         pres = Presence({'to': p.fromm, 'type': 'subscribe'})
         self.send(pres)
     nick = p.resource
     if p.type != 'unavailable':
         p.joined = True
         p.type = 'available'
     elif self.me in p.userhost:
         try:
             del self.jids[p.channel]
             logging.debug('%s - removed %s channel jids' % (self.name, p.channel))
         except KeyError:
             pass
     else:
         try:
             del self.jids[p.channel][p.nick]
             logging.debug('%s - removed %s jid' % (self.name, p.nick))
         except KeyError:
             pass
     if p.type == 'error':
         for node in p.subelements:
             try:
                 err = node.error.code
             except (AttributeError, TypeError):
                 err = 'no error set'
             try:
                 txt = node.text.data
             except (AttributeError, TypeError):
                 txt = ""
         if err:
             logging.error('%s - error - %s - %s'  % (self.name, err, txt))
         self.errorwait.check(p)
         try:
             method = getattr(self,'handle_' + err)
             try:
                 method(p)
             except:
                 handle_exception()
         except AttributeError:
             pass
     self.doevent(p)