Skip to content

Commit

Permalink
Make delete_watch_keywords a list
Browse files Browse the repository at this point in the history
  • Loading branch information
Grazfather committed Mar 29, 2021
1 parent 4b941ff commit ec533f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,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
```
{
"delete_watch_keywords" : "workon, reload, endctf"
"delete_watch_keywords" : ["workon", "reload", "endctf"]
}
2 changes: 1 addition & 1 deletion config/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions server/botserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,14 @@ def parse_slack_message(self, message_list):
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"))
Expand Down

0 comments on commit ec533f1

Please sign in to comment.