Example #1
0
 def host(self, c, e, args):
     try:
         result = self.shodan.host(args[0])
         if result:
             c.privmsg(get_target(c, e),
                       'Available ports: {' + ', '.join([str(n['port']) for n in result['data']]) + '}.')
     except APIError as er:
         c.privmsg(get_target(c, e), '\x02Error:\x0f {}'.format(er.value))
Example #2
0
 def run(self, c, e, args):
     cmd = ' '.join(args).split(';')[0]
     try:
         c.privmsg(get_target(c, e),
                   subprocess.check_output(['python', '-c', 'print({})'.format(cmd)]).decode('utf-8').replace('\n',
                                                                                                              ''))
     except subprocess.CalledProcessError as ex:
         c.privmsg(get_target(c, e),
                   'Exception running python code: {}'.format(ex.output.decode('utf-8').replace('\n', ' ')))
Example #3
0
 def search(self, c, e, args):
     url = self._base_url.format(parse.urlencode({'q': ' '.join(args)}))
     raw = request.urlopen(url)
     results = simplejson.loads(raw.read())['responseData']['results']
     if len(results) > 0:
         c.privmsg(get_target(c, e), '\x02{}\x0f - {}'.format(
             results[0]['titleNoFormatting'], results[0]['url']
         ))
     else:
         c.privmsg(get_target(c, e),
                   'Sorry {}, couldn\'nt find anything for \'{}\' on Google.'.format(e.source.nick, ' '.join(args)))
     pass
Example #4
0
 def log(self, c, e):
     if get_target(c, e) != e.target:
         return
     if not isinstance(e.source, NickMask):
         e.source = NickMask(e.source)
     if e.type in ['part', 'quit'] and len(e.arguments) is 0:
         data = [datetime.now().strftime('%H:%M:%S'), e.source.nick, 'Unknown reason']
     elif e.type == 'nick':
         data = [datetime.now().strftime('%H:%M:%S'), e.source.nick, e.target]
     elif e.type == 'mode':
         data = [datetime.now().strftime('%H:%M:%S'), e.source.nick, ' '.join(e.arguments)]
     else:
         data = [datetime.now().strftime('%H:%M:%S'), e.source.nick] + e.arguments
     print(self.to_html.parse('{} - {}'.format(get_target(c, e), self.formats[e.type].format(*data))))
Example #5
0
    def watch(self, c, e, args):
        msg = "Setup watches for: "
        if len(args) > 0:
            cursor = self.sqlite.cursor()
            for watch in args:
                cursor.execute('SELECT id FROM watches WHERE watch=? AND watcher=?', (watch, get_target(c, e)))
                if cursor.rowcount == 0:
                    cursor.execute('INSERT INTO watches (watch, watcher) VALUES (?,?)', (watch, get_target(c, e)))
                    msg += "{}, ".format(watch)

            cursor.close()
            c.privmsg(get_target(c, e), msg)
        else:
            c.privmsg(get_target(c, e), '{}: you need to give me names of people to watch!'.format(e.source.nick))
Example #6
0
 def handle_msg(self, c, e):
     msg = e.arguments[0]
     m = self.re_quote.match(msg)
     if m:
         if get_target(c, e) in self.buffer.keys() and m.group(1) in self.quote_commands.keys():
             msg = self.quote_commands[m.group(1)](get_target(c, e), m)
             if msg:
                 c.privmsg(get_target(c, e), msg)
     else:
         if get_target(c, e) in self.buffer.keys():
             self.buffer[get_target(c, e)] = [(e.source.nick, msg)] + self.buffer[get_target(c, e)]
             if len(self.buffer[get_target(c, e)]) > 100:
                 self.buffer[get_target(c, e)] = self.buffer[get_target(c, e)][:100]
         else:
             self.buffer.update({get_target(c, e): [(e.source.nick, msg)]})
Example #7
0
    def random(self, c, e, args):
        try:
            for i in range(len(args)):
                current = args[i]
                args[i] = int(current)
        except ValueError as e:
            c.privmsg(get_target(c, e), "")

        if len(args) == 1:
            val = random.randint(0, args[0])
        elif len(args) == 2:
            if args[0] > args[1]:
                (args[0], args[1]) = (args[1], args[0])
            val = random.randint(args[0], args[1])
        c.privmsg(get_target(c, e), "I choose \x02{}\x0f!".format(val))
Example #8
0
 def search_lang(self, c, e, args):
     wikipedia.set_lang(args[0])
     p = wikipedia.page(' '.join(args[1:]))
     if p:
         c.privmsg(get_target(c, e),
                   '\x02{}\x0f - {} [ {} ]'.format(p.title, smart_truncate(p.summary.replace('\n', ' ')), p.url))
     wikipedia.set_lang(self.bot.config.get('wikipedia', 'lang'))
Example #9
0
 def get_title(self, c, e):
     m = self.re_title.search(e.arguments[0])
     if m:
         try:
             url = request.urlopen(m.group(1))
         except HTTPError as ex:
             c.privmsg(get_target(c, e), "Error: {} {}".format(ex.code, ex.reason))
             return
         data = url.read(1024)
         info = magic.from_buffer(data).decode("utf-8")
         if "HTML document" in info:
             t = self.re_html.search(data.decode("utf-8"))
             if t:
                 c.privmsg(get_target(c, e), "[ {} ]".format(t.group(1)))
         else:
             c.privmsg(get_target(c, e), "[ {} ]".format(info))
Example #10
0
 def imgur(self, c, e, args):
     while True:
         url = "http://i.imgur.com/" + "".join(random.sample(string.ascii_letters + string.digits, 5)) + ".png"
         r = request.urlopen(url)
         if r.geturl() != "http://i.imgur.com/removed.png":
             c.privmsg(get_target(c, e), "Random Imgur (might be NSFW!): {}".format(url))
             break
Example #11
0
 def get_auth_level(self, c, e):
     try:
         auth = self.bot.get_module('Auth')
         return auth.get_level(c, e)
     except SakariException as ex:
         c.privmsg(get_target(c, e), "Couldn't fetch auth level. Error: {}".format(ex.error))
         return None
Example #12
0
 def random(self, c, e, args):
     while True:
         try:
             p = wikipedia.page(wikipedia.random())
             if p:
                 c.privmsg(get_target(c, e),
                           '\x02{}\x0f - {} [ {} ]'.format(p.title, smart_truncate(p.summary.replace('\n', ' ')),
                                                           p.url))
                 break
         except DisambiguationError:
             pass
Example #13
0
 def solve(self, c, e, args):
     try:
         c.privmsg(get_target(c, e), '{}: {}'.format(e.source.nick, solve(' '.join(args))))
     except:
         c.privmsg(get_target(c, e),
                   "Syntax error, please try again. Don't forget that the solver adds =0 automatically!")
Example #14
0
 def simplify(self, c, e, args):
     try:
         c.privmsg(get_target(c, e), '{}: {}'.format(e.source.nick, simplify(' '.join(args))))
     except:
         c.privmsg(get_target(c, e), "Syntax error; did you mean 'solve'?")
Example #15
0
 def excuse(self, c, e, args):
     c.privmsg(get_target(c, e), self.excuses[random.randint(0, len(self.excuses))])
Example #16
0
 def query(self, c, e, args):
     try:
         result = self.shodan.count(' '.join(args))
         c.privmsg(get_target(c, e), 'Found {} results.'.format(result))
     except APIError as er:
         c.privmsg(get_target(c, e), '\x02Error:\x0f {}'.format(er.value))
Example #17
0
 def lulz(self, c, e):
     if e.arguments[0] == 'Sakari?':
         c.privmsg(get_target(c, e), 'WHAT?')
Example #18
0
 def choose(self, c, e, args):
     if not len(args) > 0:
         c.privmsg(get_target(c, e), "I need arguments to choose from!")
     else:
         ch = random.choice(args)
         c.privmsg(get_target(c, e), "I choose \x02{}\x0f!".format(ch))
Example #19
0
 def search(self, c, e, args):
     p = wikipedia.page(' '.join(args))
     if p:
         c.privmsg(get_target(c, e),
                   '\x02{}\x0f - {} [ {} ]'.format(p.title, smart_truncate(p.summary.replace('\n', ' ')), p.url))
Example #20
0
 def test(self, c, e, args):
     c.privmsg(get_target(c, e), 'pong')
     pass