Giter Club home page Giter Club logo

twitchmonitor's Introduction

Twitch Monitor

๐Ÿค– A simple Discord bot that maintains a list of live Twitch streams in a Discord channel.

This readme was originally written for use with the Heroku free tier, however as Heroku has gotten rid of it, it's been repurposed for any generic server (I use Ubuntu).

Many bots simply post to a Discord channel when a streamer has gone live, the post gives you no indication as to whether the streamer is still live or what their status is, leading to the information in the channel becoming stale quickly.

This bot creates a card in the channel which updates throughout the duration of the streamer's stream, with uptime, viewcount, and a screenshot of their stream.

Once the streamer goes offline, the bot deletes the card, ensuring that the posts in your discord channel are all up-to-date and only referring to streamers who are live right now.

Multiple streamers can be added to the watch list, at your (or any server admin's) discretion.

Features

  • Maintains a real-time list of live streamers.
  • No annoying @everyone mentions.
  • Monitors Twitch streamers and posts on discord when they're live.
  • Continously updates streamer card in the channel with uptime/game changes + screenshot.
  • Deletes streamer card from channel when streamer goes offline.
  • Discord commands to add/remove/list watched streamers (`add / `del / `list).

Installation

This is written for beginners, but it is expected that you at least know how to use basic unix shell commands.

Requirements

A server (this guide uses Ubuntu) where you have sudo.

Instructions

  1. Install Node
    1. Here's a decent guide on how to install node. I recommend using NVM (Option 3). This bot was built in node v18 so any LTS in v18 should be fine.
  2. Install a Node Process Manager
    1. I use PM2 npm install pm2@latest -g
  3. Install PostgreSQL
    1. sudo apt update
    2. Install PostgreSQL sudo apt install postgresql postgresql-contrib
    3. Run PostgreSQL sudo systemctl start postgresql.service
    4. Create a user sudo -u postgres createuser --interactive
      1. Enter a name of your choice (the easiest is to use the same name as your unix username)
      2. Superuser: Y
    5. Set a psql password for the user
      1. psql
      2. Enter and remember a password for the user. \password
      3. Quit psql \q
    6. Create a DB sudo -u postgres createdb twitchmon
  4. Get the Bot
    1. Clone the repo into a folder on the server git clone https://github.com/brofar/TwitchMonitor.git
    2. Rename .env.sample to .env.
    3. Set the DATABASE_URL to postgres://[username]:[password]@localhost:5432/twitchmon.
      1. Swap [username] with the psql username you created above.
      2. Swap [password] with the psql password you set above.
  5. Get a Discord Token
    1. Generate a Discord bot token by following this guide.
    2. Copy the token into DISCORD_BOT_TOKEN in your .env file.
  6. Get a Twitch Token
    1. Create a Twitch app on the Twitch Developer Console (When it asks, set the OAuth Redirect URL to http://localhost)
    2. Copy the Twitch Client ID into the TWITCH_CLIENT_ID in your .env file.
    3. Copy the Twitch Client Secret into the TWITCH_CLIENT_SECRET in your .env file.
  7. Start the Bot
    1. cd into the bot's directory
    2. pm2 start app.js --name twitch-monitor
  8. Invite the Bot to your Discord Server
    1. Go to https://discord.com/api/oauth2/authorize?client_id=[BOT_CLIENT_ID]&permissions=8&scope=bot
      • Swap [BOT_CLIENT_ID] in the URL above for your Discord app's client id.
      • If you want to lock down the announcement channel so nobody but the bot can post, ensure that the bot has permissions at minimum to Send Messages, Manage Messages, and Embed Links.
    2. Start by issuing the `channel command ( `channel #live-now) to tell the bot where to post its messages.
    3. Add streamers by issuing `add streamer1 streamer2 etc etc
    4. Remove streamers by issuing `del streamer1 streamer2 etc etc
    5. List followed streamers by issuing `list
    6. Change the bot's command prefix using `prefix ! (this would change the prefix from ` to !)

Commands

Assuming the default command prefix.

`channel

Sets the channel where the bot will announce streams.

Usage: `channel #live-now

`prefix

Changes the bot's command prefix.

Usage: `prefix !

`add

Adds a Twitch streamer to the watch list. You can specify multiple space-separated Twitch handles for quick addition.

Usage: `add user1 user2 user3

`del

Removes a Twitch streamer from the watch list. You can specify multiple space-separated Twitch handles for quick removal.

Usage: `del user1 user2 user3

`list

Lists all streamers the bot is currently watching.

Usage: `list

twitchmonitor's People

Contributors

brofar avatar

Stargazers

Reggie Jackson avatar Elliot avatar Ren Paczkowski avatar Nancy Situ avatar  avatar  avatar Rylea Stark avatar

Watchers

James Cloos avatar  avatar

Forkers

exdevlin

twitchmonitor's Issues

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

2021-12-25T23:06:08.123691+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-12-25T23:06:08.154362+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-12-25T23:06:08.174418+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2021-12-25T23:06:08.307136+00:00 heroku[web.1]: Process exited with status 22
2021-12-25T23:06:08.375730+00:00 heroku[web.1]: State changed from starting to crashed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.