예제 #1
0
    def doPrivmsg(self, irc, msg):

        if irc.isChannel(msg.args[0]):

            isNickInMessage = irc.nick in msg.args[1]
            isCommandPrefixInMessage = any("@" in s for s in msg.args) #HACK, fix with conf.supybot.reply.whenAddressedBy.chars ?

            if isNickInMessage and not isCommandPrefixInMessage:
                speakChan = msg.args[0]
                dbChan = plugins.getChannel(speakChan)
                now = time.time()
                f = self._markov(speakChan, irc, prefixNick=False,
                                 to=speakChan, Random=True)
                schedule.addEvent(lambda: self.q.enqueue(f), now)

            elif not isNickInMessage:
                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)
예제 #2
0
 def doPrivmsg(self, irc, msg):
     if ircmsgs.isCtcp(msg) and not ircmsgs.isAction(msg):
         return
     irc = callbacks.SimpleProxy(irc, msg)
     if msg.channel:
         payload = msg.args[1]
         words = self.registryValue('randomGrabber.minimumWords',
                                    msg.channel, irc.network)
         length = self.registryValue('randomGrabber.minimumCharacters',
                                     msg.channel, irc.network)
         grabTime = \
         self.registryValue('randomGrabber.averageTimeBetweenGrabs',
                            msg.channel, irc.network)
         channel = plugins.getChannel(msg.channel)
         if self.registryValue('randomGrabber', msg.channel, irc.network):
             if len(payload) > length and len(payload.split()) > words:
                 try:
                     last = int(self.db.select(channel, msg.nick))
                 except dbi.NoRecordError:
                     self._grab(channel, irc, msg, irc.prefix)
                     self._sendGrabMsg(irc, msg)
                 else:
                     elapsed = int(time.time()) - last
                     if (random.random() * elapsed) > (grabTime / 2):
                         self._grab(channel, irc, msg, irc.prefix)
                         self._sendGrabMsg(irc, msg)
 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)
             reply = self.db.buildReply(channel, None)
             if (reply is None):
                 return
             irc.reply(reply, prefixNick=False, to=channel)
             #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)
         if not words or len(words) == 3:
             return
         if (self.registryValue('ignoreBotCommands', channel)
                 and callbacks.addressed(irc.nick, msg)):
             return
         self.db.addPair(channel, None, words[0])
         self.db.addPair(channel, words[-1], None)
         for (first, second) in utils.seq.window(words, 2):
             self.db.addPair(channel, first, second)
예제 #4
0
    def doPrivmsg(self, irc, msg):
        if (irc.isChannel(msg.args[0])):

            channel = plugins.getChannel(msg.args[0])

            if (not msg.tagged("repliedTo")):
                self._reply(channel, irc, msg, False)
예제 #5
0
 def invalidCommand(self, irc, msg, tokens):
     if '=~' in tokens:
         self.changeFactoid(irc, msg, tokens)
     elif tokens and tokens[0] in ('no', 'no,'):
         self.replaceFactoid(irc, msg, tokens)
     elif ['is', 'also'] in utils.seq.window(tokens, 2):
         self.augmentFactoid(irc, msg, tokens)
     else:
         key = ' '.join(tokens)
         key = self._sanitizeKey(key)
         channel = plugins.getChannel(msg.channel or msg.args[0])
         fact = self.db.getFactoid(channel, key)
         if fact:
             self.db.updateRequest(channel, key, msg.prefix)
             # getFactoid returns "all results", so we need to extract the
             # first one.
             fact = fact[0]
             # Update the requested count/requested by for this key
             hostmask = msg.prefix
             # Now actually get the factoid and respond accordingly
             (type, text) = self._parseFactoid(irc, msg, fact)
             if type == 'action':
                 irc.reply(text, action=True)
             elif type == 'reply':
                 irc.reply(text, prefixNick=False)
             elif type == 'define':
                 irc.reply(format(_('%s is %s'), key, text),
                           prefixNick=False)
             else:
                 assert False, 'Spurious type from _parseFactoid'
         else:
             if 'is' in tokens or '_is_' in tokens:
                 self.addFactoid(irc, msg, tokens)
예제 #6
0
 def addMsg(self, msg):
     assert msg.command == 'PRIVMSG'
     (channel, text) = msg.args
     if not ircutils.isChannel(channel):
         return
     channel = plugins.getChannel(channel)
     text = text.strip().lower()
     if not text:
         return
     try:
         id = ircdb.users.getUserId(msg.prefix)
     except KeyError:
         return
     msgwords = [s.strip(nonAlphaNumeric).lower() for s in text.split()]
     if channel not in self.channelWords:
         self.channelWords[channel] = {}
     for word in self.channelWords[channel]:
         lword = word.lower()
         count = msgwords.count(lword)
         if count:
             self.channelWords[channel][word] += count
             if (channel, id) not in self:
                 self[channel, id] = {}
             if word not in self[channel, id]:
                 self[channel, id][word] = 0
             self[channel, id][word] += count
예제 #7
0
 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)
 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)
             reply = self.db.buildReply(channel, None)
             if (reply is None):
                 return
             irc.reply(reply, prefixNick=False, to=channel)
             #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)
         if not words or len(words) == 3:
             return
         if (self.registryValue('ignoreBotCommands', channel) and callbacks.addressed(irc.nick, msg)):
             return
         self.db.addPair(channel, None, words[0])
         self.db.addPair(channel, words[-1], None)
         for (first, second) in utils.seq.window(words, 2):
             self.db.addPair(channel, first, second)
예제 #9
0
파일: plugin.py 프로젝트: Hoaas/Limnoria
 def invalidCommand(self, irc, msg, tokens):
     if "=~" in tokens:
         self.changeFactoid(irc, msg, tokens)
     elif tokens and tokens[0] in ("no", "no,"):
         self.replaceFactoid(irc, msg, tokens)
     elif ["is", "also"] in utils.seq.window(tokens, 2):
         self.augmentFactoid(irc, msg, tokens)
     else:
         key = " ".join(tokens)
         key = self._sanitizeKey(key)
         channel = plugins.getChannel(msg.args[0])
         fact = self.db.getFactoid(channel, key)
         if fact:
             self.db.updateRequest(channel, key, msg.prefix)
             # getFactoid returns "all results", so we need to extract the
             # first one.
             fact = fact[0]
             # Update the requested count/requested by for this key
             hostmask = msg.prefix
             # Now actually get the factoid and respond accordingly
             (type, text) = self._parseFactoid(irc, msg, fact)
             if type == "action":
                 irc.reply(text, action=True)
             elif type == "reply":
                 irc.reply(text, prefixNick=False)
             elif type == "define":
                 irc.reply(format(_("%s is %s"), key, text), prefixNick=False)
             else:
                 assert False, "Spurious type from _parseFactoid"
         else:
             if "is" in tokens or "_is_" in tokens:
                 self.addFactoid(irc, msg, tokens)
예제 #10
0
 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)
예제 #11
0
 def invalidCommand(self, irc, msg, tokens):
     if '=~' in tokens:
         self.changeFactoid(irc, msg, tokens)
     elif tokens and tokens[0] in ('no', 'no,'):
         self.replaceFactoid(irc, msg, tokens)
     elif ['is', 'also'] in utils.seq.window(tokens, 2):
         self.augmentFactoid(irc, msg, tokens)
     else:
         key = ' '.join(tokens)
         key = self._sanitizeKey(key)
         channel = plugins.getChannel(msg.args[0])
         fact = self.db.getFactoid(channel, key)
         if fact:
             self.db.updateRequest(channel, key, msg.prefix)
             # getFactoid returns "all results", so we need to extract the
             # first one.
             fact = fact[0]
             # Update the requested count/requested by for this key
             hostmask = msg.prefix
             # Now actually get the factoid and respond accordingly
             (type, text) = self._parseFactoid(irc, msg, fact)
             if type == 'action':
                 irc.reply(text, action=True)
             elif type == 'reply':
                 irc.reply(text, prefixNick=False)
             elif type == 'define':
                 irc.reply(format(_('%s is %s'), key, text),
                                  prefixNick=False)
             else:
                 assert False, 'Spurious type from _parseFactoid'
         else:
             if 'is' in tokens or '_is_' in tokens:
                 self.addFactoid(irc, msg, tokens)
예제 #12
0
 def addMsg(self, msg):
     assert msg.command == 'PRIVMSG'
     (channel, text) = msg.args
     if not ircutils.isChannel(channel):
         return
     channel = plugins.getChannel(channel)
     text = text.strip().lower()
     if not text:
         return
     try:
         id = ircdb.users.getUserId(msg.prefix)
     except KeyError:
         return
     msgwords = [s.strip(nonAlphaNumeric).lower() for s in text.split()]
     if channel not in self.channelWords:
         self.channelWords[channel] = {}
     for word in self.channelWords[channel]:
         lword = word.lower()
         count = msgwords.count(lword)
         if count:
             self.channelWords[channel][word] += count
             if (channel, id) not in self:
                 self[channel, id] = {}
             if word not in self[channel, id]:
                 self[channel, id][word] = 0
             self[channel, id][word] += count
예제 #13
0
파일: plugin.py 프로젝트: Elwell/supybot
 def doPayload(self, channel, payload):
     channel = plugins.getChannel(channel)
     self.chars += len(payload)
     self.words += len(payload.split())
     fRe = conf.supybot.plugins.ChannelStats.get('frowns').get(channel)()
     sRe =conf.supybot.plugins.ChannelStats.get('smileys').get(channel)()
     self.frowns += len(fRe.findall(payload))
     self.smileys += len(sRe.findall(payload))
예제 #14
0
파일: plugin.py 프로젝트: Athemis/Limnoria
 def addFactoid(self, irc, msg, tokens):
     # First, check and see if the entire message matches a factoid key
     channel = plugins.getChannel(msg.args[0])
     id = self._getUserId(irc, msg.prefix)
     try:
         (key, fact) = self._getKeyAndFactoid(tokens)
     except ValueError, e:
         irc.error(str(e), Raise=True)
예제 #15
0
 def addFactoid(self, irc, msg, tokens):
     # First, check and see if the entire message matches a factoid key
     channel = plugins.getChannel(msg.args[0])
     id = self._getUserId(irc, msg.prefix)
     try:
         (key, fact) = self._getKeyAndFactoid(tokens)
     except ValueError, e:
         irc.error(str(e), Raise=True)
예제 #16
0
파일: plugin.py 프로젝트: totte/aide
 def doPayload(self, channel, payload):
     channel = plugins.getChannel(channel)
     self.chars += len(payload)
     self.words += len(payload.split())
     fRe = conf.supybot.plugins.ChannelStats.get('frowns').get(channel)()
     sRe = conf.supybot.plugins.ChannelStats.get('smileys').get(channel)()
     self.frowns += len(fRe.findall(payload))
     self.smileys += len(sRe.findall(payload))
예제 #17
0
파일: plugin.py 프로젝트: Athemis/Limnoria
 def replaceFactoid(self, irc, msg, tokens):
     # Must be registered!
     channel = plugins.getChannel(msg.args[0])
     id = self._getUserId(irc, msg.prefix)
     del tokens[0] # remove the "no,"
     try:
         (key, fact) = self._getKeyAndFactoid(tokens)
     except ValueError, e:
         irc.error(str(e), Raise=True)
예제 #18
0
 def replaceFactoid(self, irc, msg, tokens):
     # Must be registered!
     channel = plugins.getChannel(msg.args[0])
     id = self._getUserId(irc, msg.prefix)
     del tokens[0]  # remove the "no,"
     try:
         (key, fact) = self._getKeyAndFactoid(tokens)
     except ValueError, e:
         irc.error(str(e), Raise=True)
예제 #19
0
 def _callRegexp(self, name, irc, msg, *L, **kwargs):
     try:
         self.irc = irc
         self.msg = msg
         # For later dynamic scoping
         channel = plugins.getChannel(msg.args[0])
         self.__parent._callRegexp(name, irc, msg, *L, **kwargs)
     finally:
         self.irc = None
         self.msg = None
예제 #20
0
 def _callRegexp(self, name, irc, msg, *L, **kwargs):
     try:
         self.irc = irc
         self.msg = msg
         # For later dynamic scoping
         channel = plugins.getChannel(msg.args[0])
         self.__parent._callRegexp(name, irc, msg, *L, **kwargs)
     finally:
         self.irc = None
         self.msg = None
예제 #21
0
파일: plugin.py 프로젝트: Hoaas/Limnoria
 def changeFactoid(self, irc, msg, tokens):
     id = self._getUserId(irc, msg.prefix)
     (key, regexp) = map(" ".join, utils.iter.split("=~".__eq__, tokens, maxsplit=1))
     channel = plugins.getChannel(msg.args[0])
     # Check and make sure it's in the DB
     fact = self._getFactoid(irc, channel, key)
     self._checkNotLocked(irc, channel, key)
     # It's fair game if we get to here
     try:
         r = utils.str.perlReToReplacer(regexp)
     except ValueError, e:
         irc.errorInvalid("regexp", regexp, Raise=True)
예제 #22
0
 def addFactoid(self, irc, msg, tokens):
     # First, check and see if the entire message matches a factoid key
     channel = plugins.getChannel(msg.channel or msg.args[0])
     id = self._getUserId(irc, msg.prefix)
     try:
         (key, fact) = self._getKeyAndFactoid(tokens)
     except ValueError as e:
         irc.error(str(e), Raise=True)
     # Check and make sure it's not in the DB already
     if self.db.getFactoid(channel, key):
         irc.error(format(_('Factoid %q already exists.'), key), Raise=True)
     self.db.addFactoid(channel, key, fact, id)
     irc.replySuccess()
예제 #23
0
 def changeFactoid(self, irc, msg, tokens):
     id = self._getUserId(irc, msg.prefix)
     (key, regexp) = map(' '.join,
                         utils.iter.split('=~'.__eq__, tokens, maxsplit=1))
     channel = plugins.getChannel(msg.args[0])
     # Check and make sure it's in the DB
     fact = self._getFactoid(irc, channel, key)
     self._checkNotLocked(irc, channel, key)
     # It's fair game if we get to here
     try:
         r = utils.str.perlReToReplacer(regexp)
     except ValueError, e:
         irc.errorInvalid('regexp', regexp, Raise=True)
예제 #24
0
 def addFactoid(self, irc, msg, tokens):
     # First, check and see if the entire message matches a factoid key
     channel = plugins.getChannel(msg.args[0])
     id = self._getUserId(irc, msg.prefix)
     try:
         (key, fact) = self._getKeyAndFactoid(tokens)
     except ValueError as e:
         irc.error(str(e), Raise=True)
     # Check and make sure it's not in the DB already
     if self.db.getFactoid(channel, key):
         irc.error(format(_('Factoid %q already exists.'), key), Raise=True)
     self.db.addFactoid(channel, key, fact, id)
     irc.replySuccess()
예제 #25
0
 def replaceFactoid(self, irc, msg, tokens):
     # Must be registered!
     channel = plugins.getChannel(msg.channel or msg.args[0])
     id = self._getUserId(irc, msg.prefix)
     del tokens[0]  # remove the "no,"
     try:
         (key, fact) = self._getKeyAndFactoid(tokens)
     except ValueError as e:
         irc.error(str(e), Raise=True)
     _ = self._getFactoid(irc, channel, key)
     self._checkNotLocked(irc, channel, key)
     self.db.removeFactoid(channel, key)
     self.db.addFactoid(channel, key, fact, id)
     irc.replySuccess()
예제 #26
0
파일: plugin.py 프로젝트: Elwell/supybot
 def addMsg(self, msg, id=None):
     if ircutils.isChannel(msg.args[0]):
         channel = plugins.getChannel(msg.args[0])
         if (channel, 'channelStats') not in self:
             self[channel, 'channelStats'] = ChannelStat()
         self[channel, 'channelStats'].addMsg(msg)
         try:
             if id is None:
                 id = ircdb.users.getUserId(msg.prefix)
         except KeyError:
             return
         if (channel, id) not in self:
             self[channel, id] = UserStat()
         self[channel, id].addMsg(msg)
예제 #27
0
    def mensa(self, irc, msg, args, argstring):
        """[<mensa>] [<time>]

    Shows the dishes served today in <mensa>. <mensa> is one of "kath"
    (default) for Mensa 1 (Katharinenstraße), "beeth" for Mensa 2 
    (Beethovenstraße), "hbk" for Mensa HBK or "abend" for Abendmensa
    (Katharinenstraße, default for times between 3pm and 8pm).
    <time> specifies the time to show, can be one of "mo", "di", "mi", "do",
    "fr", "sa" for the respective weekdays, or "today"/"heute" (default),
    "tomorrow"/"morgen" for todays resp. tomorrows dishes. From 8pm on, the 
    dishes for the next day are shown.
    """

        multiline = self.registryValue("multiline", plugins.getChannel(msg.args[0]))

        # parse parameters if given
        day = None
        mensa = None
        if argstring and len(argstring) > 0:
            arglist = argstring.split(" ")
            for argn in arglist:
                # translate to english :P
                if argn.strip() == "morgen":
                    day = "tomorrow"
                elif argn.strip() == "heute":
                    day = "today"
                elif argn.strip() in ["mo", "di", "mi", "do", "fr", "sa", "today", "tomorrow"]:
                    day = argn

                if argn.strip() in ["kath", "beeth", "abend", "hbk", "3"]:
                    mensa = argn
                elif argn.strip().rfind("1") != -1:
                    mensa = "kath"
                elif argn.strip().rfind("2") != -1:
                    mensa = "beeth"

        # print "calling mensa with mensa=%s,day=%s,multiline=%d" % (mensa, day, multiline)

        rply = self._mensa(mensa, day, multiline)

        if rply == False:
            irc.reply("Error in parameters. See help for this command.")
            return

        # do reply
        if multiline:
            for s in rply:
                irc.reply(s, prefixNick=False)
        else:
            irc.reply(" ".join(rply), prefixNick=False)
예제 #28
0
 def replaceFactoid(self, irc, msg, tokens):
     # Must be registered!
     channel = plugins.getChannel(msg.args[0])
     id = self._getUserId(irc, msg.prefix)
     del tokens[0] # remove the "no,"
     try:
         (key, fact) = self._getKeyAndFactoid(tokens)
     except ValueError as e:
         irc.error(str(e), Raise=True)
     _ = self._getFactoid(irc, channel, key)
     self._checkNotLocked(irc, channel, key)
     self.db.removeFactoid(channel, key)
     self.db.addFactoid(channel, key, fact, id)
     irc.replySuccess()
예제 #29
0
파일: plugin.py 프로젝트: totte/aide
 def addMsg(self, msg, id=None):
     if ircutils.isChannel(msg.args[0]):
         channel = plugins.getChannel(msg.args[0])
         if (channel, 'channelStats') not in self:
             self[channel, 'channelStats'] = ChannelStat()
         self[channel, 'channelStats'].addMsg(msg)
         try:
             if id is None:
                 id = ircdb.users.getUserId(msg.prefix)
         except KeyError:
             return
         if (channel, id) not in self:
             self[channel, id] = UserStat()
         self[channel, id].addMsg(msg)
예제 #30
0
 def doPrivmsg(self, irc, msg):
     if (ircmsgs.isAction(msg) and irc.isChannel(msg.args[0])):
         self.log.debug("Trying to match against '%s'", ircmsgs.unAction(msg))
         matches = re.match('^(hands|tosses|throws|gives)\s+(.+?)\s+(.+)', ircmsgs.unAction(msg))
         if (matches):
             (verb, person, thing) = matches.groups()
             self.log.debug("Matches: %s", matches.groups())
             if (person.lower() == irc.nick.lower()):
                 dropped = self._addItem(plugins.getChannel(msg.args[0]),thing)
                 if (len(dropped) == 0):
                     irc.reply("picked up %s."%thing, action = True)
                 elif (len(dropped) == 1):
                     irc.reply("picked up %s, but dropped %s."%(thing, dropped[0]), action = True)
                 else:
                     irc.reply("picked up %s, but dropped %s, and %s."%(thing, ', '.join(dropped[0:-1]), dropped[-1]), action = True)
예제 #31
0
 def augmentFactoid(self, irc, msg, tokens):
     # Must be registered!
     id = self._getUserId(irc, msg.prefix)
     pairs = list(utils.seq.window(tokens, 2))
     isAlso = pairs.index(['is', 'also'])
     key = ' '.join(tokens[:isAlso])
     new_text = ' '.join(tokens[isAlso+2:])
     channel = plugins.getChannel(msg.args[0])
     fact = self._getFactoid(irc, channel, key)
     self._checkNotLocked(irc, channel, key)
     # It's fair game if we get to here
     fact = fact[0]
     new_fact = format(_('%s, or %s'), fact, new_text)
     self.db.updateFactoid(channel, key, new_fact, id)
     irc.replySuccess()
예제 #32
0
 def augmentFactoid(self, irc, msg, tokens):
     # Must be registered!
     id = self._getUserId(irc, msg.prefix)
     pairs = list(utils.seq.window(tokens, 2))
     isAlso = pairs.index(['is', 'also'])
     key = ' '.join(tokens[:isAlso])
     new_text = ' '.join(tokens[isAlso + 2:])
     channel = plugins.getChannel(msg.channel or msg.args[0])
     fact = self._getFactoid(irc, channel, key)
     self._checkNotLocked(irc, channel, key)
     # It's fair game if we get to here
     fact = fact[0]
     new_fact = format(_('%s, or %s'), fact, new_text)
     self.db.updateFactoid(channel, key, new_fact, id)
     irc.replySuccess()
예제 #33
0
 def changeFactoid(self, irc, msg, tokens):
     id = self._getUserId(irc, msg.prefix)
     (key, regexp) = list(map(' '.join,
                         utils.iter.split('=~'.__eq__, tokens, maxsplit=1)))
     channel = plugins.getChannel(msg.args[0])
     # Check and make sure it's in the DB
     fact = self._getFactoid(irc, channel, key)
     self._checkNotLocked(irc, channel, key)
     # It's fair game if we get to here
     try:
         r = utils.str.perlReToReplacer(regexp)
     except ValueError as e:
         irc.errorInvalid('regexp', regexp, Raise=True)
     fact = fact[0]
     new_fact = r(fact)
     self.db.updateFactoid(channel, key, new_fact, id)
     irc.replySuccess()
예제 #34
0
 def changeFactoid(self, irc, msg, tokens):
     id = self._getUserId(irc, msg.prefix)
     (key, regexp) = list(
         map(' '.join, utils.iter.split('=~'.__eq__, tokens, maxsplit=1)))
     channel = plugins.getChannel(msg.channel)
     # Check and make sure it's in the DB
     fact = self._getFactoid(irc, channel, key)
     self._checkNotLocked(irc, channel, key)
     # It's fair game if we get to here
     try:
         r = utils.str.perlReToReplacer(regexp)
     except ValueError as e:
         irc.errorInvalid('regexp', regexp, Raise=True)
     fact = fact[0]
     new_fact = r(fact)
     self.db.updateFactoid(channel, key, new_fact, id)
     irc.replySuccess()
예제 #35
0
    def doRemember(self, irc, msg, match):
        r'(.+)\s+is\s+(.+)'
        if not callbacks.addressed(irc.nick, msg):
            return

        (pattern, reaction) = match.groups()
        self.log.info("Learning that '%s' means '%s'!", pattern, reaction)
        channel = plugins.getChannel(msg.args[0])
        msg.tag("repliedTo")

        if self.db.addReaction(channel, pattern, reaction).result():
            existing = self.db.getReactions(channel, pattern).result()
            if len(existing) > 1:
                irc.reply("I now have %d meanings for %s."%(len(existing), pattern))
            else:
                irc.replySuccess()
        else:
            irc.reply("I already knew that.")
예제 #36
0
파일: plugin.py 프로젝트: Kefkius/mazabot
 def doPrivmsg(self, irc, msg):
     irc = callbacks.SimpleProxy(irc, msg)
     if irc.isChannel(msg.args[0]):
         (chan, payload) = msg.args
         words = self.registryValue('randomGrabber.minimumWords', chan)
         length = self.registryValue('randomGrabber.minimumCharacters',chan)
         grabTime = \
         self.registryValue('randomGrabber.averageTimeBetweenGrabs', chan)
         channel = plugins.getChannel(chan)
         if self.registryValue('randomGrabber', chan):
             if len(payload) > length and len(payload.split()) > words:
                 try:
                     last = int(self.db.select(channel, msg.nick))
                 except dbi.NoRecordError:
                     self._grab(irc, channel, msg, irc.prefix)
                     self._sendGrabMsg(irc, msg)
                 else:
                     elapsed = int(time.time()) - last
                     if (random.random() * elapsed) > (grabTime / 2):
                         self._grab(channel, irc, msg, irc.prefix)
                         self._sendGrabMsg(irc, msg)
예제 #37
0
파일: plugin.py 프로젝트: fhats/dbtp-meral
 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, memekov=True, 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) or callbacks.addressed('tekin', msg)):
             self.log.info("Did not record a message for tekin: %s" % msg)
             return
         if msg and msg.args[1].startswith('tekin'):
             self.log.info("Ignoring message: %s" % 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)
예제 #38
0
    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)
예제 #39
0
 def doPrivmsg(self, irc, msg):
     if (irc.isChannel(msg.args[0])):
         channel = plugins.getChannel(msg.args[0])
예제 #40
0
 def isNoisy(self, msg):
     channel = plugins.getChannel(msg.args[0])