Moved admin stuff to its own file, thus priveledging reboot
This commit is contained in:
parent
43b2a13f90
commit
1bd0f272bb
20
main.py
20
main.py
|
|
@ -9,6 +9,7 @@ import identifier
|
||||||
import re
|
import re
|
||||||
import channel_util
|
import channel_util
|
||||||
import job_nagger
|
import job_nagger
|
||||||
|
import management_commands
|
||||||
from dummy import FakeClient
|
from dummy import FakeClient
|
||||||
|
|
||||||
# Read api token from file
|
# Read api token from file
|
||||||
|
|
@ -16,11 +17,6 @@ api_file = open("apitoken.txt", 'r')
|
||||||
SLACK_API = next(api_file).strip()
|
SLACK_API = next(api_file).strip()
|
||||||
api_file.close()
|
api_file.close()
|
||||||
|
|
||||||
# Read kill switch from file
|
|
||||||
kill_switch_file = open("killswitch.txt", 'r')
|
|
||||||
kill_switch = next(kill_switch_file).strip()
|
|
||||||
kill_switch_file.close()
|
|
||||||
|
|
||||||
# Enable to use dummy
|
# Enable to use dummy
|
||||||
DEBUG_MODE = False
|
DEBUG_MODE = False
|
||||||
|
|
||||||
|
|
@ -47,24 +43,18 @@ def main():
|
||||||
wrapper.add_hook(job_nagger.nag_pattern, job_nagger.nag_callback)
|
wrapper.add_hook(job_nagger.nag_pattern, job_nagger.nag_callback)
|
||||||
|
|
||||||
# Add kill switch
|
# Add kill switch
|
||||||
wrapper.add_hook(kill_switch, die)
|
wrapper.add_hook(management_commands.reboot_pattern, management_commands.reboot_callback)
|
||||||
|
|
||||||
# Add help
|
# Add help
|
||||||
def list_hooks(slack, msg, match):
|
help_callback = management_commands.list_hooks_callback_gen(wrapper.hooks.keys())
|
||||||
slack_util.reply(slack, msg, "\n".join(wrapper.hooks.keys()))
|
wrapper.add_hook(management_commands.bot_help_pattern, help_callback)
|
||||||
wrapper.add_hook("bot help", list_hooks)
|
|
||||||
|
|
||||||
wrapper.listen()
|
wrapper.listen()
|
||||||
|
|
||||||
|
|
||||||
# Callback to list command hooks
|
# Callback to list command hooks
|
||||||
|
|
||||||
|
|
||||||
# Callback to die
|
|
||||||
def die(*args):
|
|
||||||
print("Got kill switch")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
|
|
||||||
class ClientWrapper(object):
|
class ClientWrapper(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Init slack
|
# Init slack
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
import identifier
|
||||||
|
import scroll_util
|
||||||
|
import slack_util
|
||||||
|
import google_api
|
||||||
|
import channel_util
|
||||||
|
|
||||||
|
bot_help_pattern = r"bot help"
|
||||||
|
|
||||||
|
|
||||||
|
def list_hooks_callback_gen(hook_strings):
|
||||||
|
def callback(slack, msg, match):
|
||||||
|
slack_util.reply(slack, msg, "\n".join(hook_strings))
|
||||||
|
|
||||||
|
return callback
|
||||||
|
|
||||||
|
|
||||||
|
# Gracefully reboot to reload code changes
|
||||||
|
reboot_pattern = r"reboot"
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
slack_util.reply(slack, msg, response)
|
||||||
|
if reboot:
|
||||||
|
exit(0)
|
||||||
Loading…
Reference in New Issue