当前位置: 首页>>代码示例>>Python>>正文


Python schedule.addEvent函数代码示例

本文整理汇总了Python中supybot.schedule.addEvent函数的典型用法代码示例。如果您正苦于以下问题:Python addEvent函数的具体用法?Python addEvent怎么用?Python addEvent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了addEvent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: newquestion

        def newquestion(self):
            if self.num == 0:
                self.active = False
            elif (
                self.unanswered > self.registryValue("inactiveShutoff", self.channel)
                and self.registryValue("inactiveShutoff", self.channel) >= 0
            ):
                self.reply("Seems like no one's playing any more.")
                self.active = False
            elif len(self.questions) == 0:
                self.reply("Oops!  I ran out of questions!")
                self.active = False
            if not self.active:
                self.stop()
                return
            self.hints = 0
            self.num -= 1
            self.numAsked += 1
            which = self.rng.randint(0, len(self.questions) - 1)
            q = self.questions.pop(which)
            sep = self.registryValue("questionFileSeparator")
            self.q = q[: q.find(sep)]
            self.a = q[q.find(sep) + len(sep) :].split(sep)
            self.reply(
                "\x03%s#%d of %d: %s" % (self.registryValue("color", self.channel), self.numAsked, self.total, self.q)
            )

            def event():
                self.timedEvent()

            eventTime = time.time() + self.registryValue("timeout", self.channel) / (
                self.registryValue("numHints", self.channel) + 1
            )
            if self.active:
                schedule.addEvent(event, eventTime, "next_%s" % self.channel)
开发者ID:quantumlemur,项目名称:Supybot-Plugins,代码行数:35,代码来源:plugin.py

示例2: doPrivmsg

 def doPrivmsg(self, irc, msg):
     if irc.isChannel(msg.args[0]):
         speakChan = msg.args[0]
         dbChan = plugins.getChannel(speakChan)
         canSpeak = False
         now = time.time()
         throttle = self.registryValue('randomSpeaking.throttleTime',
                                       speakChan)
         prob = self.registryValue('randomSpeaking.probability', speakChan)
         delay = self.registryValue('randomSpeaking.maxDelay', speakChan)
         if now > self.lastSpoke + throttle:
             canSpeak = True
         if canSpeak and random.random() < prob:
             f = self._markov(speakChan, irc, prefixNick=False,
                              to=speakChan, Random=True)
             schedule.addEvent(lambda: self.q.enqueue(f), now + delay)
             self.lastSpoke = now + delay
         words = self.tokenize(msg)
         # This shouldn't happen often (CTCP messages being the possible
         # exception)
         if not words:
             return
         if self.registryValue('ignoreBotCommands', speakChan) and \
                 callbacks.addressed(irc.nick, msg):
             return
         words.insert(0, None)
         words.insert(0, None)
         words.append(None)
         def doPrivmsg(db):
             for (first, second, follower) in utils.seq.window(words, 3):
                 db.addPair(dbChan, first, second, follower,
                            isFirst=(first is None and second is None),
                            isLast=(follower is None))
         self.q.enqueue(doPrivmsg)
开发者ID:GlitterCakes,项目名称:PoohBot,代码行数:34,代码来源:plugin.py

示例3: newquestion

 def newquestion(self):
     inactiveShutoff = self.registryValue('inactiveShutoff',
                                          self.channel)
     if self.num == 0:
         self.active = False
     elif self.unanswered > inactiveShutoff and inactiveShutoff >= 0:
         self.reply(_('Seems like no one\'s playing any more.'))
         self.active = False
     elif len(self.questions) == 0:
         self.reply(_('Oops!  I ran out of questions!'))
         self.active = False
     if not self.active:
         self.stop()
         return
     self.hints = 0
     self.num -= 1
     self.numAsked += 1
     which = self.rng.randint(0, len(self.questions)-1)
     q = self.questions.pop(which)
     sep = self.registryValue('questionFileSeparator')
     self.q = q[:q.find(sep)]
     self.a = q[q.find(sep)+len(sep):].split(sep)
     color = self.registryValue('color', self.channel)
     self.reply(_('\x03%s#%d of %d: %s') % (color, self.numAsked,
                                         self.total, self.q))
     def event():
         self.timedEvent()
     timeout = self.registryValue('timeout', self.channel)
     numHints = self.registryValue('numHints', self.channel)
     eventTime = time.time() + timeout / (numHints + 1)
     if self.active:
         schedule.addEvent(event, eventTime, 'next_%s' % self.channel)
开发者ID:AlanBell,项目名称:Supybot-plugins,代码行数:32,代码来源:plugin.py

示例4: request

 def request(self, irc, msg, args, channel, reason):
     """<channel> - channel name for which you make request, <reason> - reason why do you want bot (it must be some good reason, not some bullshit)
     
     Request bot for <channel>, you must specify <reason> why do you want it."""
     # TODO: Before anything happens we should check if <channel> is valid IRC channel name
     # because if it's not we won't be able to join it, collect irc.state and our code will
     # probably brake in the unwanted manner
     
     #TODO: If we're already on channel nothing should be done and user should be
     # presented with explanation (we still have to implement that in our code)"""
     nick = msg.nick
     isChannelBanned = self._checkChannelBan(channel)
     # TODO: change this because this will probably return dict of more info about ban
     if isChannelBanned == "Valid":
         isRequesterBanned = self._checkRequesterBan(nick)
         # TODO: Change this because this will probably behave like channel ban and will return dict
         if isRequesterBanned == "Valid":
             # We're doing it this way because it's much more easier than trying to reimplement
             # admin join function with all those network, group, et. stuff
             adminPlugin = irc.getCallback("Admin")
             adminPlugin.join(irc, msg, [channel.lower()])
             # We must schedule this command because when bot joins some channel it neads few seconds
             # to collect irc.state and we can't access those right after the join
             schedule.addEvent(self._channelState, time.time() + 5, args=[irc, msg, nick, channel, adminPlugin])
         elif isRequesterBanned == "Banned":
             irc.reply("You can't request bot becuase you're on ban list.")
         else:
             irc.reply("There was some ugly internal error. Please try again and notify my owner about this.")
     elif isChannelBanned == "Banned":
         irc.reply("This channel is banned and you can't request bot for it.")
     else:
         irc.reply("There was some ugly internal error. Please try again and notify my owner about this.")
开发者ID:kg-bot,项目名称:SupyBot,代码行数:32,代码来源:plugin.py

示例5: starthello

 def starthello(self, irc, msg, args):
     """Nothing"""
     channel = msg.args[0]
     eventName = "%s_sayhello" % channel
     def sayHello():
         irc.queueMsg(ircmsgs.privmsg("DonVitoCorleone", "Function _sayHello is called"))
         eventNumber = self.read_timer_number()
         eventNumber = eventNumber["n"]
         irc.queueMsg(ircmsgs.privmsg("DonVitoCorleone", "eventN is %i" % eventNumber))
         if eventNumber <= 1:
             irc.queueMsg(ircmsgs.privmsg("DonVitoCorleone", "It's diferent"))
             self.write_timer_number()
         """if eventNumber <= 5:
             irc.sendMsg(ircmsgs.privmsg("DonVitoCorleone", "Current i before is %i" % eventNumber))
             eventNumber += 1
             irc.queueMsg(ircmsgs.privmsg("DonVitoCorleone", "I after is %i" % eventNumber))
             irc.queueMsg(ircmsgs.privmsg("DonVitoCorleone", "Hello World"))
         else:
             irc.queueMsg(ircmsgs.privmsg("DonVitoCorleone", schedule.schedule.events.keys()))
             schedule.removeEvent(eventName)
             irc.queueMsg(ircmsgs.privmsg("DonVitoCorleone", "Going to remove event %s" % eventName))"""
     schedule.addPeriodicEvent(sayHello, 60, eventName, now=False)
     def stopHello():
         print "Going to stop %s" % eventName
         try:
             schedule.removeEvent(eventName)
             print "Event %s stopped" % eventName
         except Exception as e:
             print e
     schedule.addEvent(stopHello, time.time() + 100)
开发者ID:kg-bot,项目名称:SupyBot,代码行数:30,代码来源:plugin.py

示例6: _topic_callback

    def _topic_callback(self):
        sections = {
            self.testing_rc_bugs.get_number_bugs: 'RC bug count',
            self.stable_rc_bugs.get_number_bugs: 'Stable RC bug count',
            self.new_queue.get_size: 'NEW queue',
            RmQueue().get_size: 'RM queue',
        }

        with self.topic_lock:
            values = {}
            for callback, prefix in sections.iteritems():
                values[callback] = callback()

            for channel in self.irc.state.channels:
                new_topic = topic = self.irc.state.getTopic(channel)

                for callback, prefix in sections.iteritems():
                    if values[callback]:
                        new_topic = rewrite_topic(new_topic, prefix, values[callback])

                if topic != new_topic:
                    log.info("Queueing change of topic in #%s to '%s'" % (channel, new_topic))
                    self.queued_topics[channel] = new_topic

                    event_name = '%s_topic' % channel
                    try:
                        schedule.removeEvent(event_name)
                    except KeyError:
                        pass
                    schedule.addEvent(lambda channel=channel: self._update_topic(channel),
                        time.time() + 60, event_name)
开发者ID:xtaran,项目名称:debian-devel-changes-bot,代码行数:31,代码来源:plugin.py

示例7: doPrivmsg

 def doPrivmsg(self, irc, msg):
     if irc.isChannel(msg.args[0]):
         channel = plugins.getChannel(msg.args[0])
         canSpeak = False
         now = time.time()
         throttle = self.registryValue('randomSpeaking.throttleTime',
                                       channel)
         prob = self.registryValue('randomSpeaking.probability', channel)
         delay = self.registryValue('randomSpeaking.maxDelay', channel)
         irc = callbacks.SimpleProxy(irc, msg)
         if now > self.lastSpoke + throttle:
             canSpeak = True
         if canSpeak and random.random() < prob:
             f = self._markov(channel, irc, prefixNick=False, to=channel,
                              Random=True)
             schedule.addEvent(lambda: self.q.enqueue(f), now + delay)
             self.lastSpoke = now + delay
         words = self.tokenize(msg)
         words.insert(0, '\n')
         words.insert(0, '\n')
         words.append('\n')
         # This shouldn't happen often (CTCP messages being the possible exception)
         if not words or len(words) == 3:
             return
         if self.registryValue('ignoreBotCommands', channel) and \
                 callbacks.addressed(irc.nick, msg):
             return
         def doPrivmsg(db):
             for (first, second, follower) in utils.seq.window(words, 3):
                 db.addPair(channel, first, second, follower)
         self.q.enqueue(doPrivmsg)
开发者ID:D0MF,项目名称:supybot-plugins,代码行数:31,代码来源:plugin.py

示例8: shoa

	def shoa(self, irc, msg, args):
		"""
		Shoa ist anberaumt
		"""
		
		if(self._checkCPO(irc, msg)):
		    
			nicks = []
			nick4 = []
			
			def unlimit():
				irc.queueMsg(ircmsgs.unlimit(msg.args[0], 0))
				
			irc.queueMsg(ircmsgs.limit(msg.args[0], 1))  
			schedule.addEvent(unlimit, time.time() + 3*60)
			
			for nick in irc.state.channels[msg.args[0]].users:
				if nick not in irc.state.channels[msg.args[0]].ops:
					nicks.append(nick)
			
			i = 0
			for nick in nicks:
				i = i+1
				nick4.append(nick)
				if (len(nick4) >= 4):
					irc.queueMsg(ircmsgs.kicks(msg.args[0], nicks, 'Reichskristallnacht'))
					nick4 = []
				elif ((len(nicks) - i) < 4):
					irc.queueMsg(ircmsgs.kicks(msg.args[0], nicks, 'Reichskristallnacht'))
				
			irc.noReply()
开发者ID:krautchan,项目名称:erica,代码行数:31,代码来源:plugin.py

示例9: k

	def k(self, irc, msg, args, nicks):
		"""[user] ... [user]
		Kick mit Timeban
		"""

		if(self._checkCPO(irc, msg)):
			
			hostmasks = []
			
			for nick in nicks:
				prefix = irc.state.nickToHostmask(nick)
				user = ircutils.userFromHostmask(prefix)
				host = ircutils.hostFromHostmask(prefix)
			
				hostmask = '*!*@%s' % host
				if(host.find('mibbit.com') != -1):
					hostmask = '*!%[email protected]*.mibbit.com' % user
					hostmasks.append(hostmask)
					hostmask = '*!*@%s' % self._numToDottedQuad(user)
					
				hostmasks.append(hostmask)
			
			irc.queueMsg(ircmsgs.bans(msg.args[0], hostmasks))
			irc.queueMsg(ircmsgs.kicks(msg.args[0], nicks, 'Your behavior is not conducive to the desired environment.'))
			
			def unban():
				irc.queueMsg(ircmsgs.unbans(msg.args[0], hostmasks))
			
			schedule.addEvent(unban, time.time() + 900)
			
		irc.noReply()
开发者ID:krautchan,项目名称:erica,代码行数:31,代码来源:plugin.py

示例10: __init__

 def __init__(self, irc, victim, wires, detonateTime, goodWire, channel, sender, showArt, showCorrectWire, debug):
     self.victim = victim
     self.startTime = time.time();
     self.detonateTime = detonateTime
     self.wires = wires
     self.goodWire = goodWire
     self.active = True
     self.channel = channel
     self.sender = sender
     self.irc = irc
     self.showArt = showArt
     self.showCorrectWire = showCorrectWire
     self.debug = debug
     self.thrown = False
     self.responded = False
     self.rng = random.Random()
     self.rng.seed()
     if self.debug:
         self.irc.reply('I just created a bomb in %s' % channel)
     def detonate():
         self.detonate(irc)
     schedule.addEvent(detonate, self.startTime + self.detonateTime, '%s_bomb' % self.channel)
     formattedTime = "%02d:%02d:%02d" % (detonateTime / 3600, detonateTime / 60, detonateTime % 60)
     s = 'stuffs a bomb down %s\'s pants.  The display reads [%s].  The wires are: %s.' % (self.victim, formattedTime, utils.str.commaAndify(wires))
     self.irc.queueMsg(ircmsgs.action(self.channel, s))
     if self.victim == irc.nick:
         time.sleep(1)
         cutWire = self.rng.choice(self.wires)
         self.irc.queueMsg(ircmsgs.privmsg(self.channel, '@cutwire %s' % cutWire))
         time.sleep(1)
         self.cutwire(self.irc, cutWire)
开发者ID:alxsoares,项目名称:supybot-plugins,代码行数:31,代码来源:plugin.py

示例11: _giveClue

    def _giveClue(self, irc, channel, now=False):
        state = self.states[channel]
        (delay, clue, valid) = state.getClue()

        def event():
            try:
                schedule.removeEvent("Eureka-nextClue-%s" % channel)
            except KeyError:
                pass
            if clue is None:
                assert valid is None
                irc.reply(
                    _("Nobody replied with (one of this) " "answer(s): %s.")
                    % ", ".join([y for x, y in state.answers if x == "r"]),
                    prefixNick=False,
                )
                self._ask(irc, channel)
            else:
                irc.reply(_("Another clue: %s") % clue, prefixNick=False)
                self._giveClue(irc, channel)

        eventName = "Eureka-nextClue-%s" % channel
        if now and eventName in schedule.schedule.events:
            schedule.schedule.events[eventName]()
            schedule.removeEvent(eventName)
        schedule.addEvent(event, time.time() + delay, eventName)
开发者ID:Azelphur,项目名称:Supybot-plugins,代码行数:26,代码来源:plugin.py

示例12: perform_standup

 def perform_standup(self):
     """Perform the daily standup"""
     # based on what time it is, guess which standup we are having
     # Which team is it?
     irc = self.irc
     now = datetime.datetime.now()
     stand_up = None
     for st in self.__standups:
         # What time is it?
         hour, min, sec = st["time"]
         if hour == now.hour and min == now.minute:
             stand_up = st
             break
     else:  # did not find one
         print "Did not find a matching standup"
         return
     irc.queueMsg(
         ircmsgs.privmsg(
             stand_up["channel"],
             "%s -  %s - Yesterday, Today, Blocked?" % (" ".join(stand_up["members"]), stand_up["name"]),
         )
     )
     # schedule the next event
     next_time = self._nextStandup(stand_up["name"])
     schedule.addEvent(self.perform_standup, next_time, stand_up["name"])
     print "[Perform Standup] Scheduling standup at %s for %s" % (str(next_time), stand_up["name"])
开发者ID:kwoodson,项目名称:bot-plugins,代码行数:26,代码来源:plugin.py

示例13: doPrivmsg

 def doPrivmsg(self, irc, msg):
     channel, text = msg.args
     text = text.lower()
     if '#' in channel:
         #print self.regex
         #irc.reply('testing %s against %s' % (text, self._regexString))
         if self.regex.match(text):
             try:
                 hostmask = irc.state.nickToHostmask(msg.nick)
             except KeyError:
                 return
             (nick, user, host) = ircutils.splitHostmask(hostmask)
             user = self._fnUser.sub('*', user)
             banmask = ircutils.joinHostmask('*', user, msg.host)
             if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
                 return
             irc.queueMsg(ban(channel, banmask, 'For swearing. 5 minute timeout'))
             irc.queueMsg(kick(channel, msg.nick, 'For swearing'))
             def unBan():
                 if channel in irc.state.channels and \
                    banmask in irc.state.channels[channel].bans:
                     irc.queueMsg(unban(channel, banmask))
             schedule.addEvent(unBan, time.time()+300)
         elif 'fag' in text.split():
             try:
                 hostmask = irc.state.nickToHostmask(msg.nick)
             except KeyError:
                 return
             (nick, user, host) = ircutils.splitHostmask(hostmask)
             irc.reply('No thanks %s I don\'t smoke' % user)
     return msg
开发者ID:chan-jesus,项目名称:no-cussing-supybot-plugin,代码行数:31,代码来源:plugin.py

示例14: version

    def version(self, irc, msg, args, channel, optlist):
        """[<channel>] [--nicks]

        Sends a CTCP VERSION to <channel>, returning the various
        version strings returned.  It waits for 10 seconds before returning
        the versions received at that point.  If --nicks is given, nicks are
        associated with the version strings; otherwise, only the version
        strings are given.
        """
        self.versions = ircutils.IrcDict()
        nicks = False
        for (option, arg) in optlist:
            if option == 'nicks':
                nicks = True
        irc.queueMsg(ircmsgs.privmsg(channel, '\x01VERSION\x01'))
        def doReply():
            if self.versions:
                L = []
                for (reply, nicks) in self.versions.iteritems():
                    if nicks:
                        L.append(format('%L responded with %q', nicks, reply))
                    else:
                        L.append(reply)
                irc.reply(format('%L', L))
            else:
                irc.reply('I received no version responses.')
        wait = self.registryValue('versionWait')
        schedule.addEvent(doReply, time.time()+wait)
开发者ID:Athemis,项目名称:Limnoria,代码行数:28,代码来源:plugin.py

示例15: run_callback

 def run_callback(callback, id_):
     ''' Run the callback 'now' on main thread. '''
     try:
         schedule.removeEvent(id_)
     except KeyError:
         pass
     schedule.addEvent(callback, time.time(), id_)
开发者ID:gmorell,项目名称:supybot-git,代码行数:7,代码来源:plugin.py


注:本文中的supybot.schedule.addEvent函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。