{"_rev":"2-78e47302d6a3850bf65845826f9c6a9e","time":{"created":"2024-10-24T15:20:26.556Z","modified":"2024-10-24T15:20:27.175Z","1.0.0":"2024-10-23T04:08:51.686Z","1.0.1":"2024-10-24T15:20:26.867Z"},"_id":"4chan-bot","name":"4chan-bot","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"4chan-bot","version":"1.0.1","main":"src/index.js","scripts":{"build":"tsc"},"keywords":["4chan","4chan bot","4chan-bot","esm"],"author":{"name":"konZat"},"license":"MIT","description":"4chan bot for automatically replying to or creating threads","type":"module","dependencies":{"@types/user-agents":"1.0.4","puppeteer":"23.6.0","puppeteer-real-browser":"1.3.16","sharp":"0.33.5","typescript":"5.6.3","user-agents":"1.1.329"},"repository":{"type":"git","url":"git+https://github.com/konZat/4chan-bot.git"},"_id":"4chan-bot@1.0.1","gitHead":"d67de9a2cb945ef99d432b85d18c8076d8a0e28d","types":"./src/index.d.ts","bugs":{"url":"https://github.com/konZat/4chan-bot/issues"},"homepage":"https://github.com/konZat/4chan-bot#readme","_nodeVersion":"22.1.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-/oX4vk8QK7Ld0UvBdDfydSuhkXPUQhJIp5QMXhZv6VFdkCAk3VXlyiajmoIsF6/2CDeDEcd6omuh1uWy5NndAw==","shasum":"35f723d2ad37fae5331d0a5cad9abe45c76533fe","tarball":"https://registry.npmjs.org/4chan-bot/-/4chan-bot-1.0.1.tgz","fileCount":16,"unpackedSize":9256787,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDUDqC2heyIzAZcbbTM0Ptel3KMWGlMa7lQbTb5ZB09WQIgIQlEG1kqKmDbl7s0FwXwh5o4gRNZEPx2BbP7OYGeBpg="}]},"_npmUser":{"name":"konzat","email":"zeepaazeepaa@gmail.com"},"directories":{},"maintainers":[{"name":"konzat","email":"zeepaazeepaa@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/4chan-bot_1.0.1_1729783226556_0.07544399493350151"},"_hasShrinkwrap":false}},"maintainers":[{"name":"konzat","email":"zeepaazeepaa@gmail.com"}],"description":"4chan bot for automatically replying to or creating threads","homepage":"https://github.com/konZat/4chan-bot#readme","keywords":["4chan","4chan bot","4chan-bot","esm"],"repository":{"type":"git","url":"git+https://github.com/konZat/4chan-bot.git"},"author":{"name":"konZat"},"bugs":{"url":"https://github.com/konZat/4chan-bot/issues"},"license":"MIT","readme":"# 4chan-bot\r\n[![npm](https://img.shields.io/npm/v/4chan-bot)](https://www.npmjs.com/package/4chan-bot)\r\n[![npm download count](https://img.shields.io/npm/dm/4chan-bot)](https://www.npmjs.com/package/4chan-bot)\r\n[![MIT License](https://img.shields.io/npm/l/4chan-bot.svg)](#license)\r\n![Stargazers](https://img.shields.io/github/stars/konZat/4chan-bot?style=social)\r\n![Forks](https://img.shields.io/github/forks/konZat/4chan-bot?style=social)\r\n\r\nA 4chan bot for automatically replying to and creating threads using puppeteer.\r\n\r\n## Table of Contents\r\n\r\n- [Important Notes](#important-notes)\r\n- [Features](#features)\r\n- [How It Works](#how-it-works)\r\n- [Installation](#installation)\r\n- [Usage](#usage)\r\n- [API Reference](#api-reference)\r\n- [Example](#headful-example)\r\n- [TODO](#todo)\r\n- [License](#license)\r\n\r\n## Important Notes\r\n- Captcha solving is dependant upon [4chan-captcha-solver](https://github.com/drunohazarb/4chan-captcha-solver). If 4chan changes the captcha and the solver no longer works, then this package will not work until 4chan-captcha-solver and this package are updated.\r\n- The package works without proxies, but if you are using multiple bots at the same time it is recommended to use proxies. \r\n  - It is highly reccomended to use a rotating residential proxy, as it allows you to easily run many bots and negates bans.\r\n    - It is worth noting that 4chan is strict with the IPs they allow to post. I have tried several different proxy providers and only found one that works. Even then, some of the IPs get flagged and stuck in an infinite cloudflare loop or are already banned.\r\n- This package is dependant upon the current layout of 4chan, and the steps required to post. If these change, the bot will not work until it is updated.\r\n  - Ex. The way Cloudflare turnstile works changes, or layout / important element IDs change\r\n- Each bot instance is a seperate browser, that uses about ~150-300 MB RAM\r\n- The package is a bit thrown together, so you may encounter other issues.\r\n\r\n### New Antispam\r\n4chan has recently ~~been rolling out new antispam rules to some boards~~ rolled out new antispam rules to all boards. These rules require that the user either wait 15 minutes to make their first post, or verify their email (or buy a pass). \r\n\r\nThere are several possible ways to handle this:\r\n- Just wait 15 minutes. \r\n  - There is no cooldown after the 15 minutes is up. This means that the initial cooldown for threads is only increased by 3x (from 5 min to 15 min), and 15x for replies (1 min to 15 min).\r\n  - If your usecase isn't spam, then this doesn't matter much if you expect to make many posts before being banned (As you only need to wait the 15 minutes once, future threads/replys have the normal 300s / 60s cooldown).\r\n  - If you need to rapdily post, wait 15 minutes with many bot instances open.\r\n    - Ex. 50 headless bots at once with a rotating residential proxy\r\n- Run many browser instances specifically to 'farm' lots of bypassed cookies in advance of when you need to rapidly post.\r\n  - Ex. Reply to a random post on a board such as /b/ (waiting the 15 minutes), then save the cookies and destroy the bot. When you're ready to post on a board with antispam, import the cookies and you should be able to post without the antispam cooldown.\r\n- Use a temporary email service that supports gmail (or another whitelisted email domain) like [Emailnator](https://www.emailnator.com/), and a service like [2Captcha](https://2captcha.com/) to solve the hcaptcha, to complete the email verification automatically.\r\n  - After verification, the time since starting the antispam cooldown is subtracted from post cooldown. This means that if you complete the verification in 60s, then after you verify the thread creation cooldown will only be 4 minutes, and the reply cooldown will be complete. So, you can have the same post throughput as before the antispam.\r\n   - However, it may only be a temporary solution as many of the emails generated by these sites seem to follow a pattern, which 4chan may catch onto and then block.\r\n   - Emails aren't sent out immeadiately, and appear to get added to a delayed queue. So this may add time, depending on how long the delay is.\r\n\r\n~~Currently, neither of the latter options are implemented, and the bot will wait for the extended cooldown without any additional configuration required.~~\r\n\r\nCurrently, you can either wait the 15 minutes or import/export cookies.\r\n<br><br>\r\nI would recommend exporting the cookies of your bots after you are done, so you can reuse them in future to avoid the 15 minute cooldown, provided they don't get banned.\r\n\r\n## Features\r\n\r\n- Create new threads\r\n- Reply to existing threads\r\n- Handle Cloudflare challenges automatically\r\n- Solve 4chans captcha automatically (reliant on [4chan-captcha-solver](https://github.com/drunohazarb/4chan-captcha-solver))\r\n- Random useragents\r\n- Proxy support\r\n- Randomizes file names to mimic [4chan-x](https://github.com/ccd0/4chan-x)\r\n- Randomizes image MD5 to circumvent antispam\r\n- Set username, memeflag, etc.\r\n- Run in headless or headful chrome\r\n\r\n## How It Works\r\n\r\n### Replying to threads\r\n1. Browser is initialized with random useragent (and proxy if configured) if not already\r\n2. Navigates to thread URL\r\n3. If cloudflare challenge hasn't been solved, opens it in a new tab and solves it. (Required to do it once if posting on a fresh cookie)\r\n4. Click the `Get captcha` button and waits 60s for the cooldown.\r\n5. Click the `Get captcha` button again and waits for the captcha to load\r\n6. Captcha gets automatically solved with [4chan-captcha-solver](https://github.com/drunohazarb/4chan-captcha-solver)\r\n7. Uploads image if specified, fills in reply text / username etc.\r\n8. Posts the reply. If the captcha is incorrect, the bot will retry it.\r\n\r\n### Creating threads\r\n1. Browser is initialized with random useragent (and proxy if configured) if not already\r\n2. Navigates to catalog URL\r\n3. If cloudflare challenge hasn't been solved, opens it in a new tab and solves it. (Required to do it once if posting on a fresh cookie)\r\n4. Click the `Get captcha` button and waits 5m for the cooldown.\r\n5. Click the `Get captcha` button again and waits for the captcha to load\r\n6. Captcha gets automatically solved with [4chan-captcha-solver](https://github.com/drunohazarb/4chan-captcha-solver)\r\n7. Uploads image, fills in thread text / username etc.\r\n8. Posts the thread. If the captcha is incorrect, the bot will retry it.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install 4chan-bot\r\n```\r\n\r\n## Usage\r\n\r\nBasic example, without any additional configuration:\r\n\r\n```javascript\r\nimport Bot from '4chan-bot';\r\n\r\nconst bot = new Bot();\r\n\r\n(async () => {\r\n  const thread = await bot.makeThread('Hello, 4chan!', 'path/to/image.jpg', 'b');\r\n\r\n  if (thread) {\r\n    console.log(`Thread created succesfully! Thread ID: ${thread}`);\r\n  } else {\r\n    console.log(`Failed to create thread. Fail reason: ${bot.cantPostReason}`);\r\n  }\r\n})();\r\n```\r\n\r\nRefer to the [API Reference](#api-reference) to see configuration options.\r\n\r\n## API Reference\r\n\r\n### Config\r\nAll config methods are optional.\r\n\r\n- `constructor()`: Initialize a new bot instance\r\n- `setMaxCloudflareAttempts(maxAttempts: number)`: Set the maximum number of Cloudflare turnstile solving attempts\r\n  - defaults to 10\r\n- `setHeadless(headless: boolean)`: Set whether to run in headless mode\r\n  - defaults to `true`\r\n- `setMaxCaptchaAttempts(maxAttempts: number)`: Set the maximum number of 4chan CAPTCHA solving attempts\r\n  - defaults to 3\r\n  - cooldown increases with every failed attempt\r\n- `setUsername(username: string)`: Set the username for posts\r\n- `setMemeflag(memeFlagId: string)`: Set a meme flag for posts\r\n  - Find the ID by using inspect element or similar tool on the memeflag dropdown\r\n  - Ex. `NZ` or `GY`\r\n- `setProxy(proxy: ProxyOptions)`: Set a proxy for the bot to use\r\n  - Type: `{ host: string, port: number, username: string, password: string }`\r\n  - Can't be changed after the browser is initialized\r\n- `setId(id: string)`: Set a unique identifier for the bot instance\r\n- `async setCookies(cookies: Cookies[])`: sets cookies\r\n\r\n### Bot\r\n- `replyToThread(message: string, threadId: number, board: string, imagePath?: string)`: Reply to an existing thread\r\n  - `board` is the abbreviation, such as `vt`, or `pol`\r\n  - returns `true` if posting doesn't give an error (note that the reply may still be blackholed due to incorrect captcha or other reason)\r\n  - returns `false` if there is an error posting, view the error on the `cantPostReason` property.\r\n    - If the error is due to an incorrect captcha, it will retry the captcha up to `MaxCaptchaAttempts` times.\r\n- `makeThread(message: string, imagePath: string, board: string)`: Create a new thread\r\n  - `board` is the abbreviation, such as `vt`, or `pol` \r\n  - returns the thread ID (string) if the post is successful\r\n  - returns `false` if there is an error posting, view the error on the `cantPostReason` property.\r\n    - If the error is due to an incorrect captcha, it will retry the captcha up to `MaxCaptchaAttempts` times.\r\n   \r\n- `destroyBot()`: Destroys the bot / closes the browser\r\n\r\n### Other\r\n- `canPost: boolean`: whether or not the bot can post\r\n  - false if its encountered some error\r\n- `cantPostReason: string`: reason for the bot being unable to post (if `canPost` is false)\r\n  - examples include ban, range ban etc.\r\n- `isDestroyed: boolean`: whether or not `destroyBot()` has been called\r\n- `id?: string`: the id, set by `setId()`\r\n- `getCookies()`: returns array of cookies\r\n\r\n## Headful Example\r\n\r\n<p align=\"center\">\r\n  <video src='https://github.com/user-attachments/assets/5adb8ead-b092-4649-bc2a-c5de59e47fc1' width=600></video>\r\n  <br/>\r\n  <sub>Posting a reply + thread in headful mode</sub>\r\n</p>\r\n\r\n## TODO\r\n- [ ] Fix cookies, cooldown not bypassed with new antispam update\r\n- [ ] 4chan pass support\r\n- [ ] Fix memeflags\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the [LICENSE](/LICENSE) file for details.","readmeFilename":"README.md"}