Comment on Does anyone know any frontends that allow banning users without a post or comment?
You are viewing one comment and its replies. View all comments · View the comment above
You are viewing one comment and its replies. View all comments · View the comment above
Comments
What is the terminal-based method? I don’t host my own instance, if that’s relevant.
Lemmy: Ban a User Who Has Not Posted or Commented
These instructions use Lemmy API v3, documented for Lemmy 0.19.x. No post or comment from the target user is required.
Requirements: Bash, curl, and jq. Run the commands locally. Never share the moderator password or login token.
VERSION NOTE These commands use the v3 API’s remove_data field. Newer API documentation uses remove_or_restore_data; do not mix the two schemas.
In a Bash terminal, run the following. At the first prompt, enter the full HTTPS address of the instance where the moderator’s account lives, without a trailing slash.
read -r -p “Your account’s instance address (including https://): " INSTANCE INSTANCE=”${INSTANCE%/}"
read -r -p "Moderator username: " MOD_USER read -r -s -p "Moderator password: " MOD_PASSWORD printf ‘\n’ read -r -p "Current 2FA code, or Enter if not enabled: " TWO_FA
LOGIN_RESPONSE=$( jq -n
–arg username “$MOD_USER”
–arg password “$MOD_PASSWORD”
–arg otp “$TWO_FA”
‘{username_or_email: $username, password: $password} + (if $otp == “” then {} else {totp_2fa_token: $otp} end)’ | curl -sS --fail-with-body
-H ‘Content-Type: application/json’
–data-binary @-
“$INSTANCE/api/v3/user/login” )
unset MOD_PASSWORD TWO_FA TOKEN=$(printf ‘%s’ “$LOGIN_RESPONSE” | jq -er ‘.jwt // empty’) unset LOGIN_RESPONSE
If this produces an error or no token, STOP rather than continuing.
Login documentation: https://lemmy.readme.io/reference/post_user-login.md
Enter their fully qualified account name, in the form @username@instance-domain.
read -r -p "Account to ban (@username@instance-domain): " TARGET_USER
curl -sS --fail-with-body --get
“$INSTANCE/api/v3/resolve_object”
-H “Authorization: Bearer $TOKEN”
–data-urlencode “q=$TARGET_USER” | jq ‘.person.person | {id, name, actor_id}’
Check that actor_id identifies the intended account, then note the numeric id.
Enter its fully qualified name, in the form !community@instance-domain.
read -r -p "Community (!community@instance-domain): " TARGET_COMMUNITY
curl -sS --fail-with-body --get
“$INSTANCE/api/v3/resolve_object”
-H “Authorization: Bearer $TOKEN”
–data-urlencode “q=$TARGET_COMMUNITY” | jq ‘.community.community | {id, name, actor_id}’
Check the community’s identity and note its numeric id.
Both IDs must come from the same instance receiving the ban request. Do not copy a user ID from their home server and combine it with a community ID from another server. The lookup above avoids that problem.
Object-resolution documentation: https://lemmy.readme.io/reference/get_resolve-object.md
This is the step that actually bans the account. Enter the IDs obtained above.
read -r -p "Target person’s numeric ID: " PERSON_ID read -r -p "Community’s numeric ID: " COMMUNITY_ID read -r -p "Ban reason: " BAN_REASON
jq -n
–argjson person_id “$PERSON_ID”
–argjson community_id “$COMMUNITY_ID”
–arg reason “$BAN_REASON”
‘{ community_id: $community_id, person_id: $person_id, ban: true, remove_data: false, reason: $reason }’ | curl -sS --fail-with-body
“$INSTANCE/api/v3/community/ban_user”
-H “Authorization: Bearer $TOKEN”
-H ‘Content-Type: application/json’
–data-binary @- | jq .
This requests a ban with no expiry and leaves existing content untouched. Check the response for errors and confirm the ban in the community’s moderation log.
Community-ban documentation: https://lemmy.readme.io/reference/post_community-ban-user
REMOVING EXISTING DOWNVOTES
The example deliberately uses remove_data: false.
PR #5810: https://github.com/LemmyNet/lemmy/pull/5810
unset TOKEN
Thanks!