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
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)
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)
def sanitize(text): """Sanitize text extracted from HTML""" return normalize_whitespace(text).strip()