Exemplo n.º 1
0
def handle_wowwiki(bot, ievent):
    """ wikipedia <what> .. search wikipedia for <what> """
    if not ievent.rest:
        ievent.missing('<what>')
        return
    what = ""
    lang = 'en'
    for i in ievent.rest.split():
        first = i[0].upper()
        rest = i[1:]
        if i.startswith('-'):
            if len(i) != 3:
                ievent.reply('invalid option')
                return
            lang = i[1:]
            continue
        what += "%s%s " % (first, rest)
    what = what.strip().replace(' ', '_')
    url = 'http://wowwiki.com/wiki/Special:Export/%s' % quote(what.encode('utf-8'))
    url2 = 'http://wowwiki.com/wiki/%s' % quote(what.encode('utf-8'))
    txt = getwikidata(url, ievent)
    if not txt:
        return
    if '#REDIRECT' in txt or '#redirect' in txt:
        redir = ' '.join(txt.split()[1:])
        url = 'http://wowwiki.com/wiki/Special:Export/%s' % quote(redir.encode('utf-8'))
        url2 = 'http://wowwiki.com/wiki/%s' % quote(redir.encode('utf-8'))
        txt = getwikidata(url, ievent)
    if not txt:
        return
    res = ['%s ===> ' % url2, ]
    res += splittxt(striphtml(txt).strip())
    ievent.reply(res)
Exemplo n.º 2
0
def handle_wikipedia(bot, ievent):
    """ wikipedia <what> .. search wikipedia for <what> """
    if not ievent.rest:
        ievent.missing('<what>')
        return
    res = searchwiki(ievent.rest)
    if not res:
        ievent.reply('no result found')
        return
    txt, url = res
    res = ['%s ===> ' % url, ]
    res += splittxt(striphtml(txt).strip())
    ievent.reply(res)
Exemplo n.º 3
0
def handle_wowwiki(bot, ievent):
    """ wikipedia <what> .. search wikipedia for <what> """
    if not ievent.rest:
        ievent.missing('<what>')
        return
    what = ""
    lang = 'en'
    for i in ievent.rest.split():
        first = i[0].upper()
        rest = i[1:]
        if i.startswith('-'):
            if len(i) != 3:
                ievent.reply('invalid option')
                return
            lang = i[1:]
            continue
        what += "%s%s " % (first, rest)
    what = what.strip().replace(' ', '_')
    url = 'http://wowwiki.com/wiki/Special:Export/%s' % quote(
        what.encode('utf-8'))
    url2 = 'http://wowwiki.com/wiki/%s' % quote(what.encode('utf-8'))
    txt = getwikidata(url, ievent)
    if not txt:
        return
    if '#REDIRECT' in txt or '#redirect' in txt:
        redir = ' '.join(txt.split()[1:])
        url = 'http://wowwiki.com/wiki/Special:Export/%s' % quote(
            redir.encode('utf-8'))
        url2 = 'http://wowwiki.com/wiki/%s' % quote(redir.encode('utf-8'))
        txt = getwikidata(url, ievent)
    if not txt:
        return
    res = [
        '%s ===> ' % url2,
    ]
    res += splittxt(striphtml(txt).strip())
    ievent.reply(res)
Exemplo n.º 4
0
            handle_exception()

    def out(self, printto, what, who=None, how='msg', fromm=None, speed=5):
        """ output the first 375 chars .. put the rest into cache. """

        # convert the data to the encoding
        try:
            what = toenc(what.rstrip())
        except Exception, ex:
            rlog(10, self.name, "can't output: %s" % str(ex))
            return
        if not what:
            return

        # split up in parts of 375 chars overflowing on word boundaries
        txtlist = splittxt(what)
        size = 0

        # send first block
        self.output(printto, txtlist[0], how, who, fromm)

        # see if we need to store output in less cache
        result = ""
        if len(txtlist) > 2:
            if not fromm:
                self.less.add(printto, txtlist[1:])
            else:
                self.less.add(fromm, txtlist[1:])
            size = len(txtlist) - 2
            result = txtlist[1:2][0]
            if size:
Exemplo n.º 5
0
         print '\n    :examples:'
         for i in data['examples'][command]:
             if not i:
                 continue
             print '\n    ::\n\n        <user> !%s' % i.strip()
             output = None
             try:
                 config['loglevel'] = 1000
                 output = bot.test(i.strip(), 16)
                 if not output:
                     print "        <output> none"
                     continue
                 result = ' .. '.join(output)
                 result = result.replace('\002', '')
                 teller2 = 1
                 for j in splittxt(result, 50):
                     if teller2 > 10:
                         print '         - output trunked -'
                         break
                     print '        <output> %s' % j
                     teller2 += 1
                 print '\n'
             except Exception, ex:
                 handle_exception(short=True)
     teller += 1
 if not data['commands']:
     print "no commands in this plugin"
 if relist:
     print "\nregular expressions"
     print "-------------------"
     print "| \n"
Exemplo n.º 6
0
         print "\n    :examples:"
         for i in data["examples"][command]:
             if not i:
                 continue
             print "\n    ::\n\n        <user> !%s" % i.strip()
             output = None
             try:
                 config["loglevel"] = 1000
                 output = bot.test(i.strip(), 16)
                 if not output:
                     print "        <output> none"
                     continue
                 result = " .. ".join(output)
                 result = result.replace("\002", "")
                 teller2 = 1
                 for j in splittxt(result, 50):
                     if teller2 > 10:
                         print "         - output trunked -"
                         break
                     print "        <output> %s" % j
                     teller2 += 1
                 print "\n"
             except Exception, ex:
                 handle_exception(short=True)
     teller += 1
 if not data["commands"]:
     print "no commands in this plugin"
 if relist:
     print "\nregular expressions"
     print "-------------------"
     print "| \n"
Exemplo n.º 7
0
    def out(self, printto, what, who=None, how='msg', fromm=None, speed=5):

        """ output the first 375 chars .. put the rest into cache. """

        # convert the data to the encoding
        try:
            what = toenc(what.rstrip())
        except Exception, ex:
            rlog(10, self.name, "can't output: %s" % str(ex))
            return
        if not what:
            return

        # split up in parts of 375 chars overflowing on word boundaries
        txtlist = splittxt(what)
        size = 0

        # send first block
        self.output(printto, txtlist[0], how, who, fromm)

        # see if we need to store output in less cache
        result = ""
        if len(txtlist) > 2:
            if not fromm:
                self.less.add(printto, txtlist[1:])
            else:
                self.less.add(fromm, txtlist[1:])
            size = len(txtlist) - 2
            result = txtlist[1:2][0]
            if size: