Exemple #1
0
    def execute(self):
        self.parser.set_defaults(user=self.nick, site=self.target[1:])

        try:
            pargs = self.parser.parse_args(shlex.split(plugins.to_utf8(self.args or "")))
            if self.parser.help_requested:
                return self.parser.format_help().strip()
            user = plugins.from_utf8(pargs.user)
            site = plugins.from_utf8(pargs.site).lower()
        except plugins.ArgumentParserError as e:
            return "Error: %s" % str(e)
        except (SystemExit, NameError, ValueError):
            return self.help(self.cmd)

        if not sitemap.has_key(site):
            return "Unknown site: %s" % site

        module = importlib.import_module("." + sitemap[site], path)
        globals()[module.__name__] = module
        return module.stats(user)
Exemple #2
0
    def execute(self):
        try:
            v = shlex.split(plugins.to_utf8(self.args or ""))
        except Exception as e:
            return str(e)

        if len(v) != 2:
            return self.help(self.cmd)

        term1, term2 = map(lambda x: plugins.from_utf8(x), v)
        hits1 = google_search(term1)[0]
        hits2 = google_search(term2)[0]
        h1 = locale.format("%d", hits1, 1)
        h2 = locale.format("%d", hits2, 1)

        return "%s %s %s %s %s" % (term1, h1, create_bar(hits1, hits2, 21), h2, term2)
Exemple #3
0
    def execute(self, connection, event, extra, dbconn):
        self.parser.set_defaults(user_or_rank=event.source.nick)
        self.parser.set_defaults(site=event.target[1:] if irc.client.
                                 is_channel(event.target) else event.target)

        try:
            pargs = self.parser.parse_args(extra["args"])
            if self.parser.help_requested:
                return self.parser.format_help().strip()
            user, rank = None, None
            if pargs.numeric:
                rank = int(pargs.user_or_rank)
            else:
                user = pargs.user_or_rank
            site = pargs.site.lower()
            glob = vars(pargs)["global"]
        except Exception as e:
            return u"Error: %s" % unicode(e)

        if glob:
            wcurl = "https://www.wechall.net/wechall.php?%s"
            username = str(rank) if rank else user
            query = urllib.urlencode({"username": plugins.to_utf8(username)})
            res = plugins.from_utf8(urllib2.urlopen(wcurl % query).read())
            return "\x0303[WeChall Global]\x03 " + res

        if not sitemap.has_key(site):
            return u"Unknown site: %s" % site

        try:
            module = importlib.import_module("." + sitemap[site], path)
            globals()[module.__name__] = module
            site = module.Site()
            site.settings = self.settings
        except Exception as e:
            print e
            return u"SiteImportError: %s" % site

        return self.stats(site, user, rank)