Пример #1
0
def handle_feedback(bot, event):
    """ 
        arguments: <feedbacktxt> - give feedback to [email protected], this needs a jabber server to be able to send the feedback.
        the feedback command can be used in a pipeline.
    
    """ 
    if not event.rest and event.inqueue: payload = waitforqueue(event.inqueue, 2000)
    else: payload = event.rest 
    fleet = getfleet()
    feedbackbot = fleet.getfirstjabber()
    if not feedbackbot: event.reply("can't find an xmpp bot to send the feedback with") ; return
    event.reply("sending to [email protected]")
    feedbackbot.say("*****@*****.**", "%s send you this: %s" % (event.userhost, payload), event=event)
    event.done()
Пример #2
0
 def wait(self, nr=1000):
     nr = int(nr)
     result = []
     if not self.busy: self.startout()
     self.finished.acquire()
     if self.threaded and self.untildone:
         logging.info("waiting until done")
         while 1: self.finished.wait(0.1)
     else:
         while nr > 0 and (self.busy and not self.dostop): self.finished.wait(0.1) ; nr -= 100
     self.finished.release()
     if self.dowait and self.thread: logging.warn("joining thread %s" % self.thread) ; self.thread.join(nr/1000)
     if not "TICK" in self.cbtype: logging.info(self.busy)
     if not self.resqueue: res = waitforqueue(self.resqueue, nr)
     else: res = self.resqueue
     return list(res)
Пример #3
0
 def gettopic(self, channel, event=None):
     """ get topic data. """
     q = queue.Queue()
     i332 = waiter.register("332", queue=q)
     i333 = waiter.register("333", queue=q)
     self.putonqueue(7, None, 'TOPIC %s' % channel)
     res = waitforqueue(q, 5000)
     who = what = when = None
     for r in res:
         if not r.postfix: continue
         try:
             if r.cmnd == "332": what = r.txt ; waiter.ready(i332) ; continue
             waiter.ready(i333)
             splitted = r.postfix.split()
             who = splitted[2]
             when = float(splitted[3])
         except (IndexError, ValueError): continue
         return (what, who, when)
Пример #4
0
 def _dccloop(self, sock, nick, userhost, channel=None):
     """ loop for dcc commands. """
     sockfile = sock.makefile('r')
     sock.setblocking(True)
     res = ""
     partyline.add_party(self, sock, nick, userhost, channel)
     while 1:
         time.sleep(0.01)
         try:
             res = sockfile.readline()
             logging.warn("%s got %s (%s)" % ( userhost, res, self.cfg.name))
             if self.stopped or not res:
                 logging.warn('closing dcc with %s (%s)' % (nick, self.cfg.name))
                 partyline.del_party(nick)
                 return
         except socket.timeout:
             continue
         except socket.error as ex:
             try:
                 (errno, errstr) = ex
             except:
                 errno = 0
                 errstr = str(ex)
             if errno == 35 or errno == 11:
                 continue
             else:
                 raise
         except Exception as ex:
             handle_exception()
             logging.warn('closing dcc with %s' % (nick, self.cfg.name))
             partyline.del_party(nick)
             return
         try:
             res = self.normalize(res)
             ievent = IrcEvent()
             ievent.printto = sock
             ievent.bottype = "irc"
             ievent.nick = nick
             ievent.userhost = userhost
             ievent.auth = userhost
             ievent.channel = channel or ievent.userhost
             ievent.origtxt = res
             ievent.txt = res
             ievent.cmnd = 'DCC'
             ievent.cbtype = 'DCC'
             ievent.bot = self
             ievent.sock = sock
             ievent.speed = 1
             ievent.isdcc = True
             ievent.msg = True
             logging.debug("%s - dcc - constructed event" % self.cfg.name)
             ievent.bind()
             if ievent.hascc():
                 ievent.iscommand = True
                 ievent.showall = True
                 ievent.nodispatch = False
                 ievent.bind()
                 self.put(ievent)
                 continue
             elif ievent.txt[0] == "@":
                 partyline.say_broadcast_notself(ievent.nick, "[%s] %s" % (ievent.nick, ievent.txt))
                 q = queue.Queue()
                 ievent.queues = [q]
                 ievent.txt = ievent.txt[1:]
                 self.doevent(ievent)
                 result = waitforqueue(q, 3000)
                 if result:
                     for i in result:
                         partyline.say_broadcast("[bot] %s" % i)
                 continue
             else:
                 partyline.say_broadcast_notself(ievent.nick, "[%s] %s" % (ievent.nick, ievent.txt))
         except socket.error as ex:
             try:
                 (errno, errstr) = ex
             except:
                 errno = 0
                 errstr = str(ex)
             if errno == 35 or errno == 11:
                 continue
         except Exception as ex:
             handle_exception()
     sockfile.close()
     logging.warn('closing dcc with %s (%s)' %  (nick, self.cfg.name))