def __init__(self, irc):
     self.__parent = super(Roundup, self)
     self.__parent.__init__(irc)
     self.saidBugs = ircutils.IrcDict()
     self.saidAttachments = ircutils.IrcDict()
     sayTimeout = self.registryValue('bugSnarferTimeout')
     for k in irc.state.channels.keys():
         self.saidBugs[k] = TimeoutQueue(sayTimeout)
         self.saidAttachments[k] = TimeoutQueue(sayTimeout)
     #period = self.registryValue('mboxPollTimeout')
     #schedule.addPeriodicEvent(self._pollMbox, period, name=self.name(),
     #                          now=False)
     for name in self.registryValue('roundups'):
         registerRoundup(name)
     reload(sys)
     sys.setdefaultencoding('utf-8')
Beispiel #2
0
    def __init__(self, irc):
        self.__parent = super(Mantis, self)
        self.__parent.__init__(irc)

        self.saidBugs = ircutils.IrcDict()
        sayTimeout = self.registryValue('bugSnarferTimeout')
        for k in irc.state.channels.keys():
            self.saidBugs[k] = TimeoutQueue(sayTimeout)

        self.urlbase = self.registryValue('urlbase')
        self.privateurlbase = self.registryValue('privateurlbase')

        if self.privateurlbase != "":
            serviceUrl = self.privateurlbase + '/api/soap/mantisconnect.php'
        else:
            serviceUrl = self.urlbase + '/api/soap/mantisconnect.php'

        self.server = SOAPProxy(serviceUrl)._ns(namespace)
        self.username = self.registryValue('username')
        self.password = self.registryValue('password')
        self.oldperiodic = self.registryValue('bugPeriodicCheck')
        self.irc = irc
        self.lastBug = 0

        bugPeriodicCheck = self.oldperiodic
        if bugPeriodicCheck > 0:
            schedule.addPeriodicEvent(self._bugPeriodicCheck,
                                      bugPeriodicCheck,
                                      name=self.name())

        reload(sys)
        sys.setdefaultencoding('utf-8')
 def _shouldSayAttachment(self, attach_id, channel):
     if channel not in self.saidAttachments:
         sayTimeout = self.registryValue('bugSnarferTimeout')
         self.saidAttachments[channel] = TimeoutQueue(sayTimeout)
     if attach_id in self.saidAttachments[channel]:
         return False
     self.saidAttachments[channel].enqueue(attach_id)
     return True
Beispiel #4
0
 def __init__(self, irc):
     self.__parent = super(Herald, self)
     self.__parent.__init__(irc)
     self.db = HeraldDB(filename)
     world.flushers.append(self.db.flush)
     self.lastParts = plugins.ChannelUserDictionary()
     splitTimeout = conf.supybot.plugins.Herald.throttle.afterSplit
     self.splitters = TimeoutQueue(splitTimeout)
     self.lastHerald = plugins.ChannelUserDictionary()
Beispiel #5
0
 def _addRelayMsg(self, msg):
     channel = msg.args[0]
     if channel in self.lastRelayMsgs:
         q = self.lastRelayMsgs[channel]
     else:
         q = TimeoutQueue(60) # XXX Make this configurable.
         self.lastRelayMsgs[channel] = q
     unformatted = ircutils.stripFormatting(msg.args[1])
     normalized = utils.str.normalizeWhitespace(unformatted)
     q.enqueue(normalized)
    def _shouldSayBug(self, bug_id, channel):
        if channel not in self.saidBugs:
            sayTimeout = self.registryValue('bugSnarferTimeout')
            self.saidBugs[channel] = TimeoutQueue(sayTimeout)
        if bug_id in self.saidBugs[channel]:
            return False

        self.saidBugs[channel].enqueue(bug_id)
        #self.log.debug('After checking bug %s queue is %r' \
        #                % (bug_id, self.saidBugs[channel]))
        return True
Beispiel #7
0
    def __init__(self, irc):

        self.__parent = super(Redmine, self)
        self.__parent.__init__(irc)

        self.saidBugs = ircutils.IrcDict()
        sayTimeout = self.registryValue('bugSnarferTimeout')
        for k in irc.state.channels.keys():
            self.saidBugs[k] = TimeoutQueue(sayTimeout)

        self.url = self.registryValue('urlbase')
        self.auth = BasicAuth(self.registryValue('apikey'),
                              str(random.random()))
        self.resource = Resource(self.url, filters=[self.auth])
Beispiel #8
0
    def relay(self, irc, msg, channel=None):
        channel = (channel or msg.args[0]).lower()
        self.log.debug("RelayNext (%s): got channel %s", irc.network, channel)
        if not channel in irc.state.channels:
            return

        # Check for ignored events first. Checking for "'.' not in msg.nick" is for skipping
        # ignore checks from servers.
        ignoredevents = map(str.upper,
                            self.registryValue('events.userIgnored', channel))
        if msg.command in ignoredevents and msg.nick != irc.nick and '.' not in msg.nick and\
                ircdb.checkIgnored(msg.prefix, channel):
            self.log.debug("RelayNext (%s): ignoring message from %s",
                           irc.network, msg.prefix)
            return

        # Get the source channel
        source = "%s@%s" % (channel, irc.network)
        source = source.lower()

        out_s = self._format(irc, msg, channel)
        if out_s:
            for relay in self.db.values():
                self.log.debug("RelayNext (%s): check if %s in %s",
                               irc.network, source, relay)
                if source in relay:  # If our channel is in a relay
                    self.log.debug("RelayNext: found %s to be in relay %s",
                                   source, relay)

                    # Remove ourselves from the target channels so we don't get duplicated messages
                    targets = list(relay)
                    targets.remove(source)

                    self.log.debug("RelayNext: found targets %s for relay %s",
                                   targets, relay)

                    if self.registryValue("antiflood.enable", channel):
                        # Flood prevention timeout - how long commands of a certain type
                        # should cease being relayed after flood prevention triggers
                        timeout = self.registryValue("antiflood.timeout",
                                                     channel)

                        # If <maximum> messages of the same kind on one channel is
                        # received in <seconds> seconds, flood prevention timeout is
                        # triggered.
                        maximum = self.registryValue("antiflood.maximum",
                                                     channel)
                        seconds = self.registryValue("antiflood.seconds",
                                                     channel)

                        # Store the message in a counter, with the keys taking the
                        # form of (source channel@network, command name). If the counter
                        # doesn't already exist, create one here.
                        try:
                            self.msgcounters[(source,
                                              msg.command)].enqueue(msg.prefix)
                        except KeyError:
                            self.msgcounters[(
                                source, msg.command)] = TimeoutQueue(seconds)

                        # Two different limits: one for messages and one for all others
                        if msg.command == "PRIVMSG":
                            maximum = self.registryValue(
                                "antiflood.maximum", channel)
                        else:
                            maximum = self.registryValue(
                                "antiflood.maximum.nonPrivmsgs", channel)

                        if len(self.msgcounters[(source,
                                                 msg.command)]) > maximum:
                            # Amount of messages in the counter surpassed our limit,
                            # announce the flood and block relaying messages of the
                            # same type for X seconds
                            self.log.debug(
                                "RelayNext (%s): message from %s blocked by "
                                "flood protection.", irc.network, channel)

                            if self.floodTriggered.get((source, msg.command)):
                                # However, only send the announcement once.
                                return

                            c = msg.command
                            e = format(
                                "Flood detected on %s (%s %ss/%s seconds), "
                                "not relaying %ss for %s seconds!", channel,
                                maximum, c, seconds, c, timeout)
                            out_s = self._format(irc,
                                                 msg,
                                                 channel,
                                                 announcement=e)

                            self.floodTriggered[(source, msg.command)] = True
                            self.log.info("RelayNext (%s): %s", irc.network, e)
                        else:
                            self.floodTriggered[(source, msg.command)] = False

                    for cn in targets:
                        # Iterate over all the relay targets for this message:
                        # each target is stored internally as a #channel@netname
                        # string.
                        target, net = cn.split("@")
                        otherIrc = world.getIrc(net)
                        if otherIrc is None:
                            self.log.debug(
                                "RelayNext: message to network %r"
                                " dropped, we are not connected "
                                "there!", net)
                            return

                        target_chanobj = otherIrc.state.channels.get(target)
                        if (not target_chanobj
                            ) or otherIrc.nick not in target_chanobj.users:
                            # We're not in the target relay channel!
                            self.log.debug(
                                "RelayNext: message to %s@%s "
                                "dropped, we are not in that "
                                "channel!", target, net)
                        else:
                            out_msg = ircmsgs.privmsg(target, out_s)

                            # Tag the message as relayed so we (and other relayers) don't
                            # try to relay it again.
                            out_msg.tag('relayedMsg')
                            otherIrc.queueMsg(out_msg)
Beispiel #9
0
 def __init__(self, irc):
     self.__parent = super(Bitbucket, self)
     self.__parent.__init__(irc)
     self.timeout_queue = TimeoutQueue(self.registryValue('snarferTimeout'))