new_config = PluginCfg.YTConfig(section.get("id"), message, report, delete) self.sections.append(new_config) logger.debug(f"Added {new_config}") def wiki_changed(sub, change): logger.debug("Wiki changed for yt, subreddit %s" % sub) cont = parse_wiki_content(change.content) wiki_config[sub.display_name] = PluginCfg(cont, change.author) wiki = hook.register_wiki_page( wiki_page="youtube", description="Send notifications on youtube channel posts.", documentation=plugin_documentation, wiki_change_notifier=wiki_changed) def format_message(message, submission=None, comment=None): if submission: message = message.replace(r"${AUTHOR}", submission.author.name) message = message.replace(r"${KIND}", "submission") message = message.replace(r"${LINK}", submission.shortlink) elif comment: message = message.replace(r"${AUTHOR}", comment.author) message = message.replace(r"${KIND}", "comment") message = message.replace(r"${LINK}", comment.url) return message
if "Setup" not in cont: logger.debug("Wiki does not contain Setup. Exit") # If it's a recent edit, notify the author if change.recent_edit: change.author.send_pm( "Error interpreting the updated wiki page on %s" % sub, "It does not contain the [Setup] section. Please read the documentation on how to configure it" ) return wiki_config[sub.display_name] = PluginCfg(cont["Setup"]) wiki = hook.register_wiki_page( wiki_page="word_notifier", description="Send modmail when a specified word is detected", documentation=plugin_documentation, wiki_change_notifier=wiki_changed) def check_words(text, config, author): if not author: return [] if author.name in config.ignore_users: return [] found_words = [] for word in config.word_list: if word in text: found_words.append(word)
logger.debug("Wiki changed for repost_detector, subreddit %s" % sub) cont = parse_wiki_content(change.content) if not cont: change.author.send_pm("Error parsing the updated wiki page on %s" % sub) return try: wiki_config[sub.display_name] = PluginCfg(cont["Setup"]) except: pass wiki = hook.register_wiki_page(wiki_page="webhook_streamer", description="Stream items to webhooks", documentation=plugin_documentation, wiki_change_notifier=wiki_changed) @hook.submission(wiki=wiki) def new_post(submission, subreddit_name): # If the subreddit was configured if subreddit_name not in wiki_config: return stype = None if submission.is_self: stype = "**Self post**" else: stype = "**Link post**"
if "Setup" not in cont: logger.debug("Wiki does not contain Setup. Exit") # If it's a recent edit, notify the author if change.recent_edit: change.author.send_pm( "Error interpreting the updated wiki page on %s" % sub, "It does not contain the [Setup] section. Please read the documentation on how to configure it" ) return wiki_config[sub.display_name] = RepostCfg(cont["Setup"]) wiki = hook.register_wiki_page( wiki_page="repost_detector", description= "Search for reposted articles and check for editorialized posts", documentation=plugin_documentation, wiki_change_notifier=wiki_changed) @hook.submission(wiki=wiki) def new_post(submission, storage, reddit, subreddit): if "subs" not in storage: storage["subs"] = {} # Get wiki configuration if subreddit.display_name not in wiki_config: logger.debug("[%s] Not in wiki config %s" % (submission.shortlink, subreddit.display_name)) return config = wiki_config[subreddit.display_name]
# Section setup needed if "Setup" not in cont: logger.debug("Wiki does not contain Setup. Exit") # If it's a recent edit, notify the author if change.recent_edit: change.author.send_pm( "Error interpreting the updated wiki page on %s" % sub, "It does not contain the [Setup] section. Please read the documentation on how to configure it" ) else: wiki_config[sub.display_name] = PluginCfg(cont["Setup"]) wiki = hook.register_wiki_page( wiki_page="changed_title", description="Check for posts that have titles different than the articles", documentation=plugin_documentation, wiki_change_notifier=wiki_changed) @hook.submission(wiki=wiki) def new_post(submission, reddit, subreddit): # Skip self posts if submission.is_self: return # Get wiki configuration if subreddit.display_name not in wiki_config: logger.debug("[%s] Not in wiki config %s" % (submission.shortlink, subreddit.display_name)) return
def wiki_changed(sub, change): logger.debug("Wiki changed for change_sidebar, subreddit %s" % sub) cont = parse_wiki_content(change.content) if not cont: change.author.send_pm("Error parsing the updated wiki page on %s" % sub) return else: if "Setup" in cont: wiki_config[sub.display_name] = PluginCfg(cont["Setup"]) wiki = hook.register_wiki_page(wiki_page="change_sidebar", description="Change sidebar pics", documentation=plugin_documentation, wiki_change_notifier=wiki_changed) def select_picture(sub_name, cfg, storage): # Select the next item by index next_item = 0 if sub_name in storage: next_item = storage[sub_name] + 1 if next_item >= len(cfg.items.keys()): next_item = 0 storage[sub_name] = next_item # Get name and link
from modbot import hook from modbot import utils from modbot.log import botlog start_date = utils.date() logger = botlog("audit") wiki = hook.register_wiki_page( wiki_page="bot_startup", description="Marks when the bot has started up (always enabled)", default_enabled=True, subreddits=[hook.subreddit_type.MASTER_SUBREDDIT]) @hook.on_start(wiki=wiki) def mark_startup(wiki_pages): page = wiki_pages["bot_startup"][0] page.update_content() new_content = page.content.split("\n") new_content.insert( 0, "Bot startup: %s; Plugin startup: %s\n" % (start_date, utils.date())) logger.info("Bot startup: %s; Plugin startup: %s\n" % (start_date, utils.date())) # Only upload the last 100 startups page.set_content("\n".join(new_content[:100]))