From a40f720482b7dcf7ce7eec644d67cf5a719df5c2 Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 27 Aug 2024 16:45:19 +0800 Subject: [PATCH] Delete spam/malware comments automatically (#2199) --- .github/workflows/delete-comments.yml | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/delete-comments.yml diff --git a/.github/workflows/delete-comments.yml b/.github/workflows/delete-comments.yml new file mode 100644 index 000000000..5ed94ae91 --- /dev/null +++ b/.github/workflows/delete-comments.yml @@ -0,0 +1,45 @@ +name: Delete Spam Comments + +on: + issue_comment: + types: [created] + +permissions: + issues: write + +jobs: + delete_comment: + runs-on: ubuntu-latest + steps: + - name: Check for specific strings in comment + id: check_comment + uses: actions/github-script@v7 + with: + script: | + const comment = context.payload.comment.body; + const triggerStrings = ['mediafire.com', 'download']; + return triggerStrings.some(triggerString => comment.includes(triggerString)); + + - name: Delete comment if it contains any of the specific strings + if: steps.check_comment.outputs.result == 'true' + uses: actions/github-script@v7 + with: + script: | + const commentId = context.payload.comment.id; + await github.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: commentId + }); + + - name: Block user if comment contains any of the specific strings + if: steps.check_comment.outputs.result == 'true' + uses: actions/github-script@v7 + with: + script: | + const userId = context.payload.comment.user.id; + await github.users.block({ + owner: context.repo.owner, + repo: context.repo.repo, + user_id: userId + });