{"id":27918569,"url":"https://github.com/kernferm/twitch-viewbot-protection","last_synced_at":"2025-05-06T18:23:23.484Z","repository":{"id":291653404,"uuid":"978321364","full_name":"KernFerm/twitch-viewbot-protection","owner":"KernFerm","description":"Lightweight, open‑source Node.js service that detects and separates organic vs artificial viewers on a Twitch stream.","archived":false,"fork":false,"pushed_at":"2025-05-05T20:55:52.000Z","size":55,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-05T21:34:43.058Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KernFerm.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-05T20:02:50.000Z","updated_at":"2025-05-05T20:55:55.000Z","dependencies_parsed_at":"2025-05-05T21:34:44.940Z","dependency_job_id":null,"html_url":"https://github.com/KernFerm/twitch-viewbot-protection","commit_stats":null,"previous_names":["kernferm/twitch-viewbot-protection"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernFerm%2Ftwitch-viewbot-protection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernFerm%2Ftwitch-viewbot-protection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernFerm%2Ftwitch-viewbot-protection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernFerm%2Ftwitch-viewbot-protection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KernFerm","download_url":"https://codeload.github.com/KernFerm/twitch-viewbot-protection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252741995,"owners_count":21797127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-06T18:23:23.045Z","updated_at":"2025-05-06T18:23:23.467Z","avatar_url":"https://github.com/KernFerm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twitch Viewbot Protection\r\n\r\nLightweight, open‑source Node.js service that detects and separates **organic** vs **artificial** viewers on a Twitch stream.\r\n\r\n---\r\n\r\n## 🚀 Getting Started\r\n\r\n## Make sure to have `NODEJS` installed.\r\n- I recommend `LTS`\r\n- [https://nodejs.org/en](https://nodejs.org/en)\r\n\r\n### 1. Install dependencies\r\n\r\n```bash\r\nnpm install\r\n```\r\n\r\n### 2. Configure `.env`\r\n\r\nOpen the included `.env` file and fill in **your** Twitch credentials and settings. It already lives in the repo—no copying needed.\r\n\r\n```ini\r\n# Twitch API credentials\r\nTWITCH_CLIENT_ID=YOUR_CLIENT_ID\r\nTWITCH_CLIENT_SECRET=YOUR_CLIENT_SECRET\r\nTWITCH_ACCESS_TOKEN=YOUR_OAUTH_TOKEN  # optional; auto-refreshes if blank\r\n\r\n# The channel you moderate (no leading #)\r\nTWITCH_CHANNEL=your_channel_name\r\n\r\n# Chatters-per-organic-view threshold\r\nTHRESHOLD=2\r\n\r\n# Server \u0026 polling settings\r\nPORT=3000\r\nPOLL_INTERVAL=15000    # in milliseconds (default: 15000 = 15s)\r\n```\r\n\r\n---\r\n\r\n## ▶️ Run the Service\r\n\r\n```bash\r\nnpm start\r\n# (runs `node src/index.js`)\r\n```\r\n\r\nYou’ll see console logs like:\r\n\r\n```\r\n✔️ Connected to #your_channel_name chat\r\n🚀 Running on http://localhost:3000/stats\r\nViewers: 120, Chatters: 30\r\n```\r\n\r\n---\r\n\r\n## 📊 Stats Endpoint\r\n\r\nOnce running, request:\r\n\r\n```\r\nGET http://localhost:3000/stats\r\n```\r\n\r\nReturns JSON:\r\n\r\n```json\r\n{\r\n  \"total_viewers\": 120,\r\n  \"unique_chatters\": 30,\r\n  \"organic_viewers\": 60,\r\n  \"artificial_viewers\": 60\r\n}\r\n```\r\n\r\n* **organic\\_viewers** = `min(total_viewers, unique_chatters × THRESHOLD)`\r\n* **artificial\\_viewers** = `total_viewers − organic_viewers`\r\n\r\n---\r\n\r\n## 🔧 How It Works\r\n\r\n1. **Chat Listener**\r\n   Uses `tmi.js` to collect unique chatter usernames each interval.\r\n\r\n2. **Helix API Polling**\r\n   Uses your `CLIENT_ID` \u0026 `CLIENT_SECRET` to get an app token, then fetches `viewer_count` for `TWITCH_CHANNEL` every `POLL_INTERVAL`.\r\n\r\n3. **Calculation**\r\n\r\n   ```js\r\n   organic    = Math.min(viewer_count, unique_chatters * THRESHOLD)\r\n   artificial = viewer_count - organic\r\n   ```\r\n\r\n4. **JSON API**\r\n   Exposes `/stats` on the port you choose.\r\n\r\n---\r\n\r\n## ⚙️ Environment Variables\r\n\r\n| Name                   | Description                                |\r\n| ---------------------- | ------------------------------------------ |\r\n| `TWITCH_CLIENT_ID`     | Your Twitch Developer App Client ID        |\r\n| `TWITCH_CLIENT_SECRET` | Your Twitch Developer App Client Secret    |\r\n| `TWITCH_ACCESS_TOKEN`  | (Optional) App Access Token; auto-refresh  |\r\n| `TWITCH_CHANNEL`       | Channel name you moderate (no leading `#`) |\r\n| `THRESHOLD`            | Chatters-per-organic-view multiplier       |\r\n| `POLL_INTERVAL`        | Poll interval in ms (default: `15000`)     |\r\n| `PORT`                 | HTTP port for the `/stats` endpoint        |\r\n\r\n---\r\n\r\n## 🔄 Customization\r\n\r\n* Tweak **THRESHOLD** for stricter/looser “organic” detection.\r\n* Adjust **POLL\\_INTERVAL** for more/less frequent updates.\r\n* Extend `src/index.js` with follower‑spike detection, geo‑filters, dashboards, or webhook alerts.\r\n\r\n---\r\n\r\n## 🛡️ Security\r\n\r\n* Keep your `.env` credentials private.\r\n* Rotate tokens and secrets regularly.\r\n\r\n---\r\n## 📄 License\r\n\r\nMIT © `Bubbles The Dev`\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkernferm%2Ftwitch-viewbot-protection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkernferm%2Ftwitch-viewbot-protection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkernferm%2Ftwitch-viewbot-protection/lists"}