Skip to content

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

Comments

  • @schwim@piefed.zip

    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.

    1. LOG IN AS THE MODERATOR

    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

    1. LOOK UP THE TARGET USER’S ID

    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.

    1. LOOK UP THE COMMUNITY’S 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

    1. SUBMIT THE COMMUNITY BAN

    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.

    • To request data removal, change it to true before submitting.
    • On versions containing PR #5810, banning with data removal also removes that person’s existing upvotes and downvotes in the community, not only downvotes.
    • It also removes their posts and comments in that community, if any.
    • Do not assume an older 0.19.x installation includes that change. A merge into the development branch does not establish that it is installed on a particular server.

    PR #5810: https://github.com/LemmyNet/lemmy/pull/5810

    1. CLEAR THE TOKEN WHEN FINISHED

    unset TOKEN

    1

This post is locked. It takes no new comments.