Example #1
0
File: bot.py Project: gflerm/seejoo
    def _handle_command(self, cmd, args):
        ''' Handles a bot-level command. Returns its result. '''
        if cmd == 'help':
            if not args:
                return "No help found."

            doc = ext._get_command_doc(args)
            if doc:
                if config.cmd_prefix:
                    args = config.cmd_prefix + args
                doc = normalize_whitespace(doc)
                doc = doc.strip()
                return "%s -- %s" % (args, doc)
            else:
                return "No help found for '%s'" % args
Example #2
0
    def command(self, bot, user, cmd, args):
        '''
        Called when user issues a command.
        '''
        if cmd == 't':
            
            url = args or self.last_url
            if not url: return "I don't recall anything that looks like an URL."

            # Download the page
            site = download(url)     
            if not site:    return "(Could not retrieve page)"
            
            # Find the title and return it
            m = TITLE_RE.search(site)
            if not m:   return "(Untitled)"
            title = m.group('title')
            return normalize_whitespace(title)
Example #3
0
 def _handle_command(self, cmd, args):
     '''
     Handles a bot-level command. Returns its result.
     '''
     if cmd == 'help':
         
         if not args:
             return "No help found."
         
         doc = ext._get_command_doc(args)
         if doc:
             if config.cmd_prefix:
                 args = config.cmd_prefix + args
             doc = normalize_whitespace(doc)
             doc = doc.strip()
             return "%s -- %s" % (args, doc)
         else:
             return "No help found for '%s'" % args
Example #4
0
    def command(self, bot, user, cmd, args):
        '''
        Called when user issues a command.
        '''
        if cmd == 't':

            url = args or self.last_url
            if not url:
                return "I don't recall anything that looks like an URL."

            # Download the page
            site = download(url)
            if not site: return "(Could not retrieve page)"

            # Find the title and return it
            m = TITLE_RE.search(site)
            if not m: return "(Untitled)"
            title = m.group('title')
            return normalize_whitespace(title)
Example #5
0
    def command(self, bot, channel, user, cmd, args):
        '''
        Called when user issues a command.
        '''
        if not channel:
            return
        if cmd != 't':
            return

        url = args or self.urls.get(channel)
        if not url:
            return "I don't recall anything that looks like an URL."

        site = download(url)
        if not site:
            return "(Could not retrieve page)"

        m = TITLE_RE.search(site)
        if not m:
            return "(Untitled)"
        title = m.group('title')
        return normalize_whitespace(title)
Example #6
0
def sanitize(text):
    """Sanitize text extracted from HTML"""
    return normalize_whitespace(text).strip()