diff --git a/README.md b/README.md index 32e1caf..bb32c4d 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ reaction_removed 2. Configure the git account, the local repo and the remote path, which should be used to access your git repository. Example: -``` +```json { "git_repopath" : "/home/ota_bot/OTA_Upload", "git_repouser" : "otabot", @@ -215,7 +215,7 @@ Note: If you configure the solvetracker this way, you need to make sure you are 5. Add a link to your repo, so people can look it up via `showlinkurl` Example: -``` +```json { "git_repo": "reponame/links", "git_branch": "gh-pages", @@ -232,7 +232,7 @@ To enable archive reminders set an offset (in hours) in _config/config.json_ for If active, the bot will create a reminder for every bot admin on `!endctf` to inform him, when the ctf was finished for the specified time and it should be archived. Example (for being reminded one week after the ctf has finished): -``` +```json { ... "archive_ctf_reminder_offset" : "168" @@ -241,11 +241,10 @@ Example (for being reminded one week after the ctf has finished): ## Log command deletion -To enable logging of deleting messages containing specific keywords, set `delete_watch_keywords` in _config/config.json_ to a comma separated list of keywords. -Clear or remove the setting to disable deletion logging. +To enable logging of deleting messages containing specific keywords, set `delete_watch_keywords` in _config/config.json_ to an array of strings to watch for. Example -``` +```json { - "delete_watch_keywords" : "workon, reload, endctf" + "delete_watch_keywords" : ["workon", "reload", "endctf"] } diff --git a/config/config.json.template b/config/config.json.template index 6959cc1..3ffdffc 100644 --- a/config/config.json.template +++ b/config/config.json.template @@ -8,7 +8,7 @@ "wolfram_app_id" : "", "archive_ctf_reminder_offset" : "168", "archive_everything": true, - "delete_watch_keywords" : "", + "delete_watch_keywords" : [], "intro_message" : "", "private_ctfs": false, "allow_signup": false, diff --git a/server/botserver.py b/server/botserver.py index 5a2a108..31d3c68 100644 --- a/server/botserver.py +++ b/server/botserver.py @@ -85,30 +85,28 @@ def parse_slack_message(self, message_list): if msg.get("type") == "message" and "subtype" not in msg: if self.bot_at in msg.get("text", ""): # Return text after the @ mention, whitespace removed - return msg['text'].split(self.bot_at)[1].strip(), msg['channel'], msg['thread_ts'] if 'thread_ts' in msg else msg['ts'], msg['user'] + return msg["text"].split(self.bot_at)[1].strip(), msg["channel"], msg["thread_ts"] if "thread_ts" in msg else msg["ts"], msg["user"] elif msg.get("text", "").startswith("!"): # Return text after the ! - return msg['text'][1:].strip(), msg['channel'], msg['thread_ts'] if 'thread_ts' in msg else msg['ts'], msg['user'] + return msg["text"][1:].strip(), msg["channel"], msg["thread_ts"] if "thread_ts" in msg else msg["ts"], msg["user"] # Check if user tampers with channel purpose elif msg.get("type") == "message" and msg["subtype"] == "channel_purpose" and msg["user"] != self.bot_id: - source_user = get_display_name(resolve_user_by_user_id(self.slack_wrapper, msg['user'])) - warning = "*User '{}' changed the channel purpose ```{}```*".format(source_user, msg['text']) - self.slack_wrapper.post_message(msg['channel'], warning) + source_user = get_display_name(resolve_user_by_user_id(self.slack_wrapper, msg["user"])) + warning = "*User "{}" changed the channel purpose ```{}```*".format(source_user, msg["text"]) + self.slack_wrapper.post_message(msg["channel"], warning) # Check for deletion of messages containing keywords elif "subtype" in msg and msg["subtype"] == "message_deleted": - log_deletions = self.get_config_option("delete_watch_keywords") + delete_keywords = self.get_config_option("delete_watch_keywords") - if log_deletions: - previous_msg = msg['previous_message']['text'] - delete_keywords = log_deletions.split(",") + previous_msg = msg["previous_message"]["text"] - if any(keyword.strip() in previous_msg for keyword in delete_keywords): - user_name = self.slack_wrapper.get_member(msg['previous_message']['user']) - display_name = get_display_name(user_name) - self.slack_wrapper.post_message(msg['channel'], "*{}* deleted : `{}`".format(display_name, previous_msg)) + if any(keyword in previous_msg for keyword in delete_keywords): + user_name = self.slack_wrapper.get_member(msg["previous_message"]["user"]) + display_name = get_display_name(user_name) + self.slack_wrapper.post_message(msg["channel"], "*{}* deleted : `{}`".format(display_name, previous_msg)) # Greet new users elif msg.get("type") == "im_created": - self.slack_wrapper.post_message(msg['user'], self.get_config_option("intro_message")) + self.slack_wrapper.post_message(msg["user"], self.get_config_option("intro_message")) return None, None, None, None