Beispiel #1
0
 def join(self, channel, password=None, nick=None):
     """ join conference. """
     if channel.startswith("#"): return
     try:
         if not nick: nick = channel.split('/')[1]
     except IndexError: nick = self.nick
     channel = channel.split('/')[0]
     q = Queue.Queue()
     self.errorwait.register("409", q, 3)
     self.errorwait.register("401", q, 3)
     self.errorwait.register("400", q, 3)
     presence = Presence({'to': channel + '/' + nick})
     if password:
          presence.x.password = password             
     self.send(presence)
     errorobj = waitforqueue(q, 3000)
     if errorobj:
         err = errorobj[0].error
         logging.error('%s - error joining %s - %s' % (self.name, channel, err))
         if err >= '400':
             if channel not in self.channels409: self.channels409.append(channel)
         return err
     self.timejoined[channel] = time.time()
     chan = ChannelBase(channel, self.botname)
     chan.data['nick'] = nick
     if password:
         chan.data['key'] = password
     if not chan.data.has_key('cc'):
         chan.data['cc'] = self.cfg['defaultcc'] or '!'
     if channel not in self.state['joinedchannels']:
         self.state['joinedchannels'].append(channel)
         self.state.save()
     if channel in self.channels409:
         self.channels409.remove(channel)
     return 1
Beispiel #2
0
 def __init__(self, waveid, botname=None):
     ChannelBase.__init__(self, waveid, botname)
     self.data.seenblips = self.data.seenblips or 0
     self.data.threshold = self.data.threshold or -1
     self.data.nrcloned = self.data.nrcloned or 0
     self.data.waveid = waveid
     self.wavelet = None
     self.event = None
     logging.debug("created wave with id: %s" % waveid)
Beispiel #3
0
 def join(self, channel, password=None):
     """ join channel with optional password. """
     if not channel: return
     if password:
         self._raw('JOIN %s %s' % (channel, password))
         chan = ChannelBase(channel, self.botname)
         if chan: chan.setpass('IRC', password)
     else: self._raw('JOIN %s' % channel)
     if self.state:
         if channel not in self.state.data.joinedchannels:
             self.state.data.joinedchannels.append(channel)
             self.state.save()
Beispiel #4
0
Datei: bot.py Projekt: code2u/jsb
 def update_web(self, channel, txt):
     from google.appengine.api.channel import channel as gchan
     chan = ChannelBase(channel, botname="gae-web")
     logging.warn("%s - webchannels are %s" % (self.cfg.name, chan.data.webchannels))
     remove = []
     for c in chan.data.webchannels:
         try:
             if c:
                 logging.warn("%s - sending %s to channel %s" % (self.cfg.name, txt, c))
                 gchan.send_message(c, txt)
         except gchan.InvalidChannelClientIdError:
             remove.append(c)
     if remove:
         for c in remove: chan.data.webchannels.remove(c) ; logging.warn("%s - closing channel %s" % (self.cfg.name, c))
         chan.save()
Beispiel #5
0
 def stop(self, botname, type, name, channel):
     """ stop watching a feed. """
     item = self.byname(name)
     if not item: return False
     try:
         logging.warn("trying to remove %s from %s feed list" % (name, channel))
         chan = ChannelBase(channel, botname)
         chan.data.feeds.remove(name)
         chan.save()
     except ValueError:
         logging.warn("can't remove %s from %s feed list" % (name, channel))
     try:
         item.data.watchchannels.remove([botname, type, channel])
         item.save()
         logging.debug("stopped %s feed in %s channel" % (name, channel))
     except ValueError: return False
     return True
Beispiel #6
0
 def update_web(self, channel, txt, end="<br>"):
     from google.appengine.api.channel import channel as gchan
     chan = ChannelBase(channel, botname="gae-web")
     #logging.warn("%s - webchannels are %s" % (self.name, chan.data.webchannels))
     remove = []
     for c in chan.data.webchannels:
         try:
             if c:
                 logging.debug("%s - sending to channel %s" %
                               (self.name, chan))
                 gchan.send_message(c, txt + end)
         except gchan.InvalidChannelClientIdError:
             remove.append(c)
     if remove:
         for c in remove:
             chan.data.webchannels.remove(c)
         chan.save()
Beispiel #7
0
 def join(self, channel, password=None, nick=None):
     """ join conference. """
     if channel.startswith("#"): return
     logging.warn("joining %s" % channel)
     try:
         if not nick: nick = channel.split('/')[1]
     except IndexError:
         nick = self.cfg.nick or "jsonbot"
     self.timejoined[channel] = time.time()
     chan = ChannelBase(channel, self.botname)
     chan.data['nick'] = nick
     if password:
         chan.data['key'] = password
     if chan.data['key'] and not password: password = chan.data['key']
     if not chan.data.has_key('cc'):
         chan.data['cc'] = self.cfg['defaultcc'] or '!'
     if channel not in self.state['joinedchannels']:
         self.state['joinedchannels'].append(channel)
         self.state.save()
     if channel in self.channels409:
         self.channels409.remove(channel)
     chan.save()
     channel = channel.split('/')[0]
     q = Queue.Queue()
     presence = Presence({
         'to': channel + '/' + nick,
         "xmlns": 'http://jabber.org/protocol/muc'
     })
     if password:
         presence.x = {}
         presence.x['password'] = password
     self.send(presence)
     return 1
Beispiel #8
0
 def join(self, channel, password=None, nick=None):
     """ join conference. """
     if channel.startswith("#"): return
     logging.warn("joining %s" % channel)
     try:
         if not nick: nick = channel.split('/')[1]
     except IndexError: nick = self.cfg.nick or "jsonbot"
     channel = channel.split('/')[0]
     q = Queue.Queue()
     presence = Presence({'to': channel + '/' + nick, "xmlns": 'http://jabber.org/protocol/muc' })
     if password:
          presence.x.password = password             
     self.send(presence)
     self.timejoined[channel] = time.time()
     chan = ChannelBase(channel, self.botname)
     chan.data['nick'] = nick
     if password:
         chan.data['key'] = password
     if not chan.data.has_key('cc'):
         chan.data['cc'] = self.cfg['defaultcc'] or '!'
     if channel not in self.state['joinedchannels']:
         self.state['joinedchannels'].append(channel)
         self.state.save()
     if channel in self.channels409:
         self.channels409.remove(channel)
     chan.save()
     return 1
Beispiel #9
0
 def join(self, channel, password=None):
     """ join a channel .. use optional password. """
     chan = ChannelBase(channel, self.cfg.name)
     if password:
         chan.data.key = password.strip()
         chan.save()
     result = Irc.join(self, channel, chan.data.key)
     if result != 1:
         return result
     got = False
     if not chan.data.cc:
         chan.data.cc = self.cfg.globalcc or ''
         got = True
     if not chan.data.perms:
         chan.data.perms = []
         got = True
     if not chan.data.mode:
         chan.data.mode = ""
         got = True
     if got:
         chan.save()
     self.getchannelmode(channel)
     return 1
Beispiel #10
0
Datei: bot.py Projekt: code2u/jsb
 def join(self, channel, password=None):
     """ join a channel .. use optional password. """
     chan = ChannelBase(channel, self.cfg.name)
     if password:
         chan.data.key = password.strip()
         chan.save()
         # logging.warn("%s - using key %s for channel %s" % (self.cfg.name, chan.data.key, channel))
     result = Irc.join(self, channel, chan.data.key)
     if result != 1:
         return result
     got = False
     if not chan.data.cc:
         chan.data.cc = self.cfg.defaultcc or "!"
         got = True
     if not chan.data.perms:
         chan.data.perms = []
         got = True
     if not chan.data.mode:
         chan.data.mode = ""
         got = True
     if got:
         chan.save()
     self.getchannelmode(channel)
     return 1
Beispiel #11
0
 def handle_ievent(self, ievent):
     """ handle ircevent .. dispatch to 'handle_command' method. """
     try:
         if ievent.cmnd == 'JOIN' or ievent.msg:
             if ievent.nick in self.nicks401:
                 self.nicks401.remove(ievent.nick)
                 logging.debug('%s - %s joined .. unignoring' %
                               (self.name, ievent.nick))
         if not ievent.chan and ievent.channel:
             ievent.chan = ChannelBase(ievent.channel, self.botname)
         method = getattr(self, 'handle_' + ievent.cmnd.lower())
         if method:
             try:
                 method(ievent)
             except:
                 handle_exception()
     except AttributeError:
         pass
     try:
         self.wait.check(ievent)
     except:
         handle_exception()
Beispiel #12
0
 def join(self, channel, password=None):
     """ join a channel .. use optional password. """
     result = Irc.join(self, channel, password)
     if result != 1:
         return result
     chan = ChannelBase(channel, self.botname)
     got = False
     if password:
         chan.setkey('IRC',password)
         got = True
     if not chan.data.cc:
         chan.data.cc = self.cfg.defaultcc or '!'
         got = True
     if not chan.data.perms:
         chan.data.perms = []
         got = True
     if not chan.data.mode:
         chan.data.mode = ""
         got = True
     if got:
         chan.save()
     self.getchannelmode(channel)
     return 1
Beispiel #13
0
 def join(self, channel, password=None):
     """ join a channel .. use optional password. """
     chan = ChannelBase(channel, self.cfg.name)
     if password:
         chan.data.key = password.strip()
         chan.save()
     result = Irc.join(self, channel, chan.data.key)
     if result != 1:
         return result
     got = False
     if not chan.data.cc:
         chan.data.cc = self.cfg.globalcc or ''
         got = True
     if not chan.data.perms:
         chan.data.perms = []
         got = True
     if not chan.data.mode:
         chan.data.mode = ""
         got = True
     if got:
         chan.save()
     self.getchannelmode(channel)
     return 1