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 b80a997 commit 1e7ab77
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
Expand All @@ -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"]
}
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
26 changes: 12 additions & 14 deletions server/botserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1e7ab77

Please sign in to comment.