def message_processor(bot, user, text): """ Dump a message to the db in the bot's root, if it has a url. """ urls = [token for token in text.split() if is_url(token)] if len(urls) == 0: return entries = [] for url in urls: content = _get_parsed_content(url) entry = { 'url': url, 'title': _get_title(content) or url, 'description': _get_description(content), 'user': user, 'timestamp': datetime.datetime.now().isoformat() } entries.append(entry) path = join(bot.root, DB_NAME) bot.lock.acquire() _save_entries(path, entries) bot.lock.release() return
def add(self, user, args): """ Define a bot command, or other hooks from chat. This command lets extend the bot, by adding bot commands, or other hooks through the chat interface. New commands can be added as shown below :: ,add command_name def main(): ''' Clears the screen! This command is intended to be used when you want to divert attention of the users from the previous discussion. ''' print '\\n' * 80 The commands can be added to a gist and the *raw* url can be passed to this command, like so :: ,add <raw-gist-url> For more information, look at http://punchagan.github.io/childrens-park/plugins.html#plugins """ if not args: return "Didn't get any arguments for the command!" # Check if first word in args is a URL. first_arg = args.split()[0] if is_url(first_arg): url = first_arg code = get_code_from_url(url) name = basename(url) else: name = first_arg code = args[len(name):].strip() path = self._save_code_to_plugin(name, code) if path is not None: self._load_plugin_from_path(path) self.message_queue.append('%s registered command %s' % (user, name)) return