#138 Feature/takedown bot
*Feature*
• Use github app to create a takedown pull request, if gemini recognize a reply as second scam(二次詐騙) or sexual content.
• Query replies before `REVIEW_REPLY_BEFORE`(format: `{ "seconds":0, "minutes":10, "hours":0, "days":0}`).
• Filtered out known users that existed in pervious pr by parsing the pr title.
• List the ten more replies written by the suspicious user for the moderator to review and determine if they are a spammer.
• Created a `moderators` team for bot to assign pr reviewers(future work).
*Created PR*
<https://github.com/cofacts/takedowns/pull/141|#141>
We can directly copy the payload
<https://private-user-images.githubusercontent.com/6376572/394758609-98f1875f-b20e-4e59-a226-85b6f1b2b687.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzQ2NzIxNjcsIm5iZiI6MTczNDY3MTg2NywicGF0aCI6Ii82Mzc2NTcyLzM5NDc1ODYwOS05OGYxODc1Zi1iMjBlLTRlNTktYTIyNi04NWI2ZjFiMmI2ODcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MTIyMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDEyMjBUMDUxNzQ3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MDY5NWY4NzU0OTk0MjQxY2U2OTYwMzZiOTA5NDg4ZGVmOGFkMjg5NTdiOWFkMGFiODUwNmNiOTUzM2I3NzMxYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.7d20cW-hTsksJdkRkaKFM_W-KA70TJBWHwETlrkKWiI|takedown pr>
*Langfuse*
• `ENV` variable for langfuse to tag the generation content.
• Do nothing if `LANGFUSE_BASEURL` is not specified.
*Github action*
• Schedule run every ten minutes but also can be triggered manually
• Note: some <https://github.com/orgs/community/discussions/52477|job may be dropped> due to high load
• Environment: set `master` branch as production, others as staging
<https://private-user-images.githubusercontent.com/6376572/394762515-cfd90d9a-0e01-466a-bf7b-120bff370a32.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzQ2NzIxNjcsIm5iZiI6MTczNDY3MTg2NywicGF0aCI6Ii82Mzc2NTcyLzM5NDc2MjUxNS1jZmQ5MGQ5YS0wZTAxLTQ2NmEtYmY3Yi0xMjBiZmYzNzBhMzIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MTIyMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDEyMjBUMDUxNzQ3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MGJhNWZhNDE1NThiMzY2NzVkZWYyMmE1MDAxMmM3MmI0YTkxYmQ1OTY2NWIzMGE0N2M2MWJhMGFkMDRlM2Y4OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.jdhksIyWyS0VML8x_XcoY56_o43HjVv8gcbBpWvvJLo|environment>
*Takedown bot setting*
<https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app|https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app>
• <https://github.com/apps/cofacts-takedown|landing page>
• <https://github.com/organizations/cofacts/settings/apps/cofacts-takedown|settings>
• is <https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/making-a-github-app-public-or-private|private>
<https://private-user-images.githubusercontent.com/6376572/387290622-30b63dd4-ad32-4627-b418-b0f541644f7f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzQ2NzIxNjcsIm5iZiI6MTczNDY3MTg2NywicGF0aCI6Ii82Mzc2NTcyLzM4NzI5MDYyMi0zMGI2M2RkNC1hZDMyLTQ2MjctYjQxOC1iMGY1NDE2NDRmN2YucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MTIyMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDEyMjBUMDUxNzQ3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZDdjOGFlOTc1YjU0YWJjNTcwZmUyYzFkMjgyNGM3NDg4NmQ3N2U5ZDJlNjg0MzJjNjFiOWFmOTJjZjkyYTA4OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.SuZQ6W7QDhPVZN-pUqO7OQhiVEb_oJAn0IMYRE0amr8|截圖 2024-11-18 晚上11 45 49>
• only installed in cofacts/takedown repo
<https://private-user-images.githubusercontent.com/6376572/387289925-0d83a78c-21b3-461d-926e-bc65278d32f3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzQ2NzIxNjcsIm5iZiI6MTczNDY3MTg2NywicGF0aCI6Ii82Mzc2NTcyLzM4NzI4OTkyNS0wZDgzYTc4Yy0yMWIzLTQ2MWQtOTI2ZS1iYzY1Mjc4ZDMyZjMucG5nP1gtQW16LU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ZGIxMzUzYzk0ZDFmZTY4OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.tCSvj8Xoy8PYAa2cfrjmOj_qSzcV-yV1Gnh80jwa2ZY|截圖 2024-11-22 下午4 42 21>
*Authentication with <https://github.com/octokit/auth-app.js/tree/main?tab=readme-ov-file#usage-with-octokit|octokit>*
Three parameters needed
1. The ID of your GitHub app
2. A private key for your GitHub app
3. The ID of the installation that you want to authenticate as
See <https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation#using-octokitjs-to-authenticate-with-an-installation-id|Using Octokit.js to authenticate with an installation ID> for detail.
只是我們要開始努力看 takedown PR 並執行下架⋯⋯ XD
後來發現改成 `4-59/10 * * * *` 還是會掉 action,晚點再發一個新 pr 改用 lastScannedAt