Exemple #1
0
    def processChannelMessage(self, m):
        if m.modCommand == "tumblr":
            helptext = "tumblr commands are: brain, followers"

            msg = unicode(StringUtil.removeFormattingAndColors(m.getTrailing()))
            commands = msg.split()
            if len(commands) == 1:
                m.reply(helptext)
            elif commands[1] == "brain":
                words = goatpy.tumblr.get_words()
                m.reply("%s: My brain is full of '%s'" % (m.sender,
                    " ".join(words)))
            elif commands[1] == "followers":
                msg = goatpy.tumblr.followers()
                m.reply(msg)
            else:
                m.reply(helptext)
        elif m.modCommand == "tumblrbrain":
            m.reply("It's 'tumblr brain' now.")
        elif m.sender not in BOTS:
            msg = unicode(StringUtil.removeFormattingAndColors(m.getTrailing()))
            words = goatpy.tumblr.add_words(msg)
            last_post = goatpy.tumblr.get_last_post_time()
            now = time.time()
            if now - last_post > IDLE_TIME:
                tags = [m.sender]
                count = random.randint(2, 3)
                words = goatpy.tumblr.get_random_words()
                tags.extend(words)
                response = goatpy.tumblr.post_search(" ".join(words), tags=tags)
                if response is not None:
                    m.reply(response)
Exemple #2
0
    def processChannelMessage(self, m):
        commands = {
            "gis": goatpy.tumblr.gis_search,
            "bis": goatpy.tumblr.bis_search,
            "yis": goatpy.tumblr.bis_search,  # TODO
        }

        msg = StringUtil.removeFormattingAndColors(m.getTrailing())
        img_match = URL_RX.search(msg)
        video_match = VIDEO_RX.search(msg)
        response = None
        tags = [m.sender]

        if img_match:
            url = img_match.group()
            if is_obsessed(m) or random.random() < 0.60:
                goatpy.tumblr.cache_url(url)  # saves as seen
            else:
                tags.append("picture")
                response = goatpy.tumblr.safe_post(url, tags=tags)
        elif video_match:
            url = video_match.group()
            if is_obsessed(m) or random.random() < 0.60:
                goatpy.tumblr.cache_url(url)  # saves as seen
            else:
                tags.append("video")
                response = goatpy.tumblr.safe_post(url, post_type="video", tags=tags)
        elif m.modCommand in commands:
            msg = unicode(StringUtil.removeFormattingAndColors(m.getTrailing()))
            tokens = msg.split()
            if len(tokens) > 1:
                search = " ".join(tokens[1:])
                if is_obsessed(m):
                    goatpy.tumblr.cache_search(search)  # saves as seen
                else:
                    provider = "bis"
                    parser = CommandParser(m)
                    if parser.hasVar("provider"):
                        provider = parser.get("provider")
                        if provider == "my mommy":
                            provider = "gis"
                        elif provider not in commands:
                            print "Unknown provider: %s" % provider
                            return

                    tags = [m.sender]
                    tags.extend(tokens[1:])
                    response = commands[provider](search, tags=tags)

        if response is not None:
            m.reply(response)
Exemple #3
0
    def updateStats(self, m):
        msg = StringUtil.removeFormattingAndColors(m.getTrailing()).lower()
        word_count = len(msg.split())
        seen_types = {}
        pure = True

        for word_type, (impure, rx) in WORD_TYPES_RX.items():
            if re.search(rx, msg):
                if impure:
                    pure = False
                seen_types[word_type] = True

        # goat is fickle.
        if random.random() < .0005:
          pure = False

        user_store = KVStore.getUserStore(m)
        user_store.save(LAST_SEEN, time.time())

        chan_store = KVStore.getChanStore(m)
        for store, is_channel in [(chan_store, True), (user_store, False)]:
            if pure:
                self.purity_update(m, store, is_channel)
            else:
                self.purity_fail(m, store, is_channel)
            store.incSave(LINE_COUNT)
            store.incSave(WORD_COUNT, word_count)
            for word_type, seen in seen_types.items():
                store.incSave(word_type, 1)
Exemple #4
0
 def processChannelMessage(self, m):
     match = URL_RX.search(
         StringUtil.removeFormattingAndColors(m.getTrailing()))
     if match:
         url = match.group()
         # arbitrary treshold for long urls
         if len(url) > 24 and "git.io" not in url:
             msg = build_message(url)
             if msg is not None:
                 m.reply(msg)
Exemple #5
0
 def processChannelMessage(self, m):
     match = URL_RX.search(
         StringUtil.removeFormattingAndColors(m.getTrailing()))
     if match:
         url = match.group()
         # arbitrary treshold for long urls
         if len(url) > 24 and "git.io" not in url:
             msg = build_message(url)
             if msg is not None:
                 m.reply(msg)