diff --git a/channel_util.py b/channel_util.py index 848f2c1..00923ed 100644 --- a/channel_util.py +++ b/channel_util.py @@ -8,8 +8,6 @@ COMMAND_CENTER_ID = "GCR631LQ1" SLAVES_TO_THE_MACHINE_ID = "C9WUQBYNP" BOTZONE = "C3BF2MFKM" -NOT_ALLOWED_HERE = "There's a time and place for everything, but not here!" - # Callback for telling what channel we in def channel_check_callback(slack, msg, match): diff --git a/job_nagger.py b/job_nagger.py index 3c90bcd..354361f 100644 --- a/job_nagger.py +++ b/job_nagger.py @@ -20,38 +20,34 @@ class Job(object): def nag_callback(slack, msg, match): - # Only allow in command center - if msg["channel"] != channel_util.COMMAND_CENTER_ID: - response = channel_util.NOT_ALLOWED_HERE - else: - # Get the day - day = match.group(1).lower().strip() + # Get the day + day = match.group(1).lower().strip() - # Get the spreadsheet section - eight_jobs = google_api.get_sheet_range(SHEET_ID, eight_job_range) - ft_jobs = google_api.get_sheet_range(SHEET_ID, fiftythree_job_range) + # Get the spreadsheet section + eight_jobs = google_api.get_sheet_range(SHEET_ID, eight_job_range) + ft_jobs = google_api.get_sheet_range(SHEET_ID, fiftythree_job_range) - # Turn to job objects - eight_jobs = [Job("8", *r) for r in eight_jobs] - ft_jobs = [Job("53", *r) for r in ft_jobs] - jobs = eight_jobs + ft_jobs + # Turn to job objects + eight_jobs = [Job("8", *r) for r in eight_jobs] + ft_jobs = [Job("53", *r) for r in ft_jobs] + jobs = eight_jobs + ft_jobs - # Filter to day - jobs = [j for j in jobs if j.day == day] + # Filter to day + jobs = [j for j in jobs if j.day == day] - # Nag each - response = "Do yer jerbs! They are as follows:\n" - for job in jobs: - response += "({}) {} -- ".format(job.house, job.job_name) - ids = job.lookup_brother_slack_id() - if ids: - for slack_id in ids: - response += "<@{}> ".format(slack_id) - else: - response += "{} (scroll missing. Please register for @ pings!)".format(job.brother_name) - response += "\n" + # Nag each + response = "Do yer jerbs! They are as follows:\n" + for job in jobs: + response += "({}) {} -- ".format(job.house, job.job_name) + ids = job.lookup_brother_slack_id() + if ids: + for slack_id in ids: + response += "<@{}> ".format(slack_id) + else: + response += "{} (scroll missing. Please register for @ pings!)".format(job.brother_name) + response += "\n" slack_util.reply(slack, msg, response, in_thread=False, to_channel=channel_util.GENERAL) -nag_hook = slack_util.Hook(nag_callback, pattern=r"nagjobs\s*(.*)") +nag_hook = slack_util.Hook(nag_callback, pattern=r"nagjobs\s*(.*)", channel_whitelist=[channel_util.COMMAND_CENTER_ID]) diff --git a/management_commands.py b/management_commands.py index 8cedd93..57824d8 100644 --- a/management_commands.py +++ b/management_commands.py @@ -13,18 +13,11 @@ def list_hooks_callback_gen(hooks): # Gracefully reboot to reload code changes # noinspection PyUnusedLocal def reboot_callback(slack, msg, match): - if msg["channel"] != channel_util.COMMAND_CENTER_ID: - response = channel_util.NOT_ALLOWED_HERE - reboot = False - else: - response = "Ok. Rebooting..." - reboot = True - + response = "Ok. Rebooting..." slack_util.reply(slack, msg, response) - if reboot: - exit(0) + exit(0) # Make hooks bot_help_pattern = r"bot help" # Can't init this directly, as it relies on us knowing all other hooks. handle in main -reboot_hook = slack_util.Hook(reboot_callback, pattern=r"reboot") +reboot_hook = slack_util.Hook(reboot_callback, pattern=r"reboot", channel_whitelist=[channel_util.COMMAND_CENTER_ID])