Ejemplo n.º 1
0
 def alpha_command(self, chans, name, match, direct, reply):
     ret = alpha(match.group(1), self.app_id)
     if not ret["success"]:
         reply("wolfram alpha is confused: %s" % short_url(ret["web"]))
     else:
         s = ret["output"].splitlines()
         web = short_url(ret["web"])
         if len(s) == 1:
             reply("%s (%s)" % (s[0], web))
         else:
             for part in s:
                 reply(part)
             reply("(%s)" % web)
Ejemplo n.º 2
0
 def alpha_command(self, chans, name, match, direct, reply):
     ret = alpha(match.group(1), self.app_id)
     if not ret['success']:
         reply('wolfram alpha is confused: %s' % short_url(ret['web']))
     else:
         s = ret['output'].splitlines()
         web = short_url(ret['web'])
         if len(s) == 1:
             reply('%s (%s)' % (s[0], web))
         else:
             for part in s:
                 reply(part)
             reply('(%s)' % web)
Ejemplo n.º 3
0
 def alpha_command(self, chans, name, match, direct, reply):
     ret = alpha(match.group(1), self.app_id)
     if not ret['success']:
         reply('wolfram alpha is confused: %s' % short_url(ret['web']))
         if random.random() < self.confuse_chance:
             time.sleep(1)
             reply('it hurt itself in its confusion!')
     else:
         s = ret['output'].splitlines()
         web = short_url(ret['web'])
         if len(s) == 1:
             reply('%s (%s)' % (s[0], web))
         else:
             for part in s:
                 reply(part)
             reply('(%s)' % web)
Ejemplo n.º 4
0
    def do_command(self, name, reply):
        allposts = self.get_posts(name)

        try:
            posts = []
            for p in allposts:
                p = p['data']
                if p['over_18'] and not self.nsfw:
                    continue
                if p['spoiler'] and not self.spoilers:
                    continue
                if p['stickied'] and not self.stickies:
                    continue
                if p['is_self'] and not self.selfposts:
                    continue
                posts.append(p)

            post = random.choice(posts)
            selfurl = self.URLFORMAT.format(**post).lower()
            url = post['url']
            title = post['title']
            if post['is_self'] or post['is_video']:
                reply(u'{0}: {1}'.format(title, selfurl).encode('ascii', errors='replace'))
            else:
                reply(u'{0}: {1} <{2}>'.format(title, short_url(url), selfurl).encode('ascii', errors='replace'))
        except Exception, e:
            self.log_debug('error : {0}'.format(repr(e)))
            reply('no {0} today :('.format(name))
Ejemplo n.º 5
0
    def trope_command(self, chans, name, match, direct, reply):
        self.log_debug('searching google for trope: ' + match.group(1))
        try:
            results = GoogleSearch().search(self.QUERY % (match.group(1),), prefetch_pages=False, prefetch_threads=1, num_results=1)
        except Exception:
            reply('trope not found :(')
            return
        if not results.results:
            reply('trope not found :(')
            return
        url = results.results[0].url
        m = self.URLMATCH.match(url)
        if not m:
            reply('trope not found :(')
            return

        subwiki = m.group(1)
        title = m.group(2)

        desc = self.get_info('Laconic', title)
        if not desc:
            desc = self.get_info(subwiki, title)

        surl = short_url(url)
        reply((desc + ' ' + surl).encode('ascii', errors='replace'))
Ejemplo n.º 6
0
 def list_command(self, chans, name, match, direct, reply):
     enc_query = urllib.quote_plus(match.group(1))
     url = short_url("http://www.google.com/search?q=" + enc_query)
     reply('"%s": %s' % (match.group(1), url))