Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadow-ban command #57

Merged
merged 6 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist
doc/build
__pycache__
.vscode/
env/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ python3 setup.py install
* [x] `user password <user id>`
* [x] `user membership <user id>`
* [x] `user whois <user id>`
* [ ] `user shadow_ban <user id>`
* [x] `user shadow_ban <user id>`
* [x] `user media -u <user id>` (also available as `media list -u <user id>`)
* [x] `user login <user id>`
* [ ] Additional commands and aliases around user management
Expand Down
13 changes: 13 additions & 0 deletions synadm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,3 +1063,16 @@ def regtok_delete(self, token):

"""
return self.query("delete", f"v1/registration_tokens/{token}")

def user_shadow_ban(self, user_id, unban):
""" Shadow-ban or unban a user.

Args:
user_id (string): The user to be banned/unbanned.
unban (boolean): Unban the specified user.
"""
if unban:
method = "delete"
else:
method = "post"
return self.query(method, f"v1/users/{user_id}/shadow_ban")
31 changes: 31 additions & 0 deletions synadm/cli/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,34 @@ def user_login_cmd(helper, user_id, expire_days, expire, expire_ts,
raise SystemExit(1)
else:
helper.output(user_login)

@user.command(name="shadow-ban")
@click.argument("user_id", type=str)
@click.option(
"-u", "--unban", is_flag=True, default=False, show_default=False,
help="Unban the specified user"
)
@click.pass_obj
def user_shadow_ban(helper, user_id, unban):
"""Shadow-ban or unban a user.

Useful for moderating malicious or egregiously abusive users.

A shadow-banned user will not receive any notification, but still will be
unable to contact anyone on the server. Use this as a tool of last resort
since it may lead to confusing or broken behaviour for the client.

Generally, it is more appropriate to ban or kick abusive users.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some redundant spaces.

"""
user_ban = helper.api.user_shadow_ban(user_id, unban)
if user_ban is None:
click.echo("Failed to shadow-ban: {}".format(user_id))
raise SystemExit(1)
if helper.output_format == "human":
if user_ban:
click.echo("Failed to shadow-ban the user: {}".format(user_id))
helper.output(user_ban)
else:
click.echo("Successfully shadow-banned user: {}".format(user_id))
else:
helper.output(user_ban)