Skip to content

Commit

Permalink
Add unwatch Slack command
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed Jan 7, 2022
1 parent 15bfd9e commit f839011
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
25 changes: 25 additions & 0 deletions api/views/slack_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,30 @@ def process_watch(channel: str, message: str) -> None:
client.chat_postMessage(channel=channel, text=msg)


def process_unwatch(channel: str, message: str) -> None:
"""Set the transcription checks back to automatic."""
parsed_message = message.split()

if len(parsed_message) == 1:
# they didn't give a username
msg = i18n["slack"]["errors"]["missing_username"]
elif len(parsed_message) == 2:
username = clean_links(parsed_message[1])
if user := BlossomUser.objects.filter(username__iexact=username).first():
# Set the check percentage back to automatic
user.overwrite_check_percentage = None
user.save()

msg = i18n["slack"]["unwatch"]["success"].format(user=user.username)
else:
msg = i18n["slack"]["errors"]["unknown_username"]

else:
msg = i18n["slack"]["errors"]["too_many_params"]

client.chat_postMessage(channel=channel, text=msg)


def dadjoke_target(channel: str, message: str, use_api: bool = True) -> None:
"""Send the pinged user a dad joke. Or just send everybody a joke."""
parsed_message = message.split()
Expand Down Expand Up @@ -372,6 +396,7 @@ def process_message(data: Dict) -> None:
"info": send_info,
"blacklist": process_blacklist,
"watch": process_watch,
"unwatch": process_unwatch,
"dadjoke": dadjoke_target,
}

Expand Down
7 changes: 6 additions & 1 deletion blossom/strings/en_US.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Get information about a user: `@blossom info {username}`
Get general server information: `@blossom info`
Blacklist / unblacklist user: `@blossom blacklist {username}`
Toggle CoC status of user: `@blossom reset {username}`
Overwrite check percentage: `@blossom watch {username} {percentage}`, where {percentage} is a number between 0 and 100
Reset check percentage: `@blossom unwatch {username}`
Render this message: `@blossom help`
"""

Expand Down Expand Up @@ -80,7 +82,10 @@ github_sponsor_update="{0} GitHub Sponsors: [{1}] - {2} | {3} {0}"

[slack.watch]
invalid_percentage="{percentage} is an invalid percentage. Please provide a number between 0 and 100, such as '50%' or '75'."
success="The transcriptions of {user} now have a {percentage}% chance to be checked."
success="The transcriptions of {user} now have a {percentage}% chance to be checked.\nUse `unwatch {user}` to undo this."

[slack.unwatch]
success="The chance to check transcriptions of {user} is now determined automatically."

[slack.dadjoke]
message = "Hey {0}! {1}"
Expand Down

0 comments on commit f839011

Please sign in to comment.