BarryCarlyon / twitch_discord_barrycarlyon_co_uk

A Super Simple Twitch to Discord Notification Tool

Home Page:https://twitch.discord.barrycarlyon.co.uk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is this

This repo contains the code for https://twitch.discord.barrycarlyon.co.uk, a Twitch Go Live Notification System for Discord

Languages

It's written in NodeJS

Documentation

It uses the following API reference documentation

What does it look like?

Example Discord Notification

Running it yourself

This system uses MySQL as a Database backend and Redis for session handling and message brokering between the two services

  • Import sql/barrys_discord_twitch.sql to your MySQL database

  • Copy .env.sample to .env

  • Revise the settings within, for your Discord Application and Twitch Applications.

  • Revise that database access settings

  • Make sure to update the URLs, and Twitch EventSub

  • npm install

It's expected to your PM2 as a process manager. So you can either use PM2 or run the two jobs another way

  • pm2 start app.json

or start the two jobs manually

  • node server.js
  • node utils/runner.js

Using TwitchCLI to test

You can use the Twitch-cli to test your Eventsub callback see https://github.com/twitchdev/twitch-cli/ and look under Events

Example:

twitch event verify-subscription stream.online -s "THESECRETISCOOL" -F "https://twitch.discord.barrycarlyon.co.uk/eventsub/"

You would naturally swap the URL to the URL for your instance of the project.

License

This project is Licensed under DO WHAT THE FUCK YOU WANT Image/logo assets remain the property/licensing of their resepective owners

OMGLIEKWUT OHMYGOODNESS U SO MUCH HELP

Thank you for the help I want to give you beer/coffee money -> Check the Funding/Sponsor details

Nginx and Cookie Security

This is an example, so doesn't contain all the best security practices. Since this uses cookies to manage logins you should change the session code to something like. And the paired app.user to sanity check/enforce the right domain for cookies to behave

app.use(session({
    store: new RedisStore({
        client: redis_client
    }),
    secret,
    resave: true,
    saveUninitialized: false,
    cookie: {
        secure: true,
        httpOnly: true,
        domain: config.server.domain
    },
    rolling: true
}));

app.use((req, res, next) => {
    if (req.hostname != config.server.domain) {
        res.redirect(`https://${config.server.domain}/${req.originalUrl}`);
        return;
    }

Change the domain as needed!

See also Production Best Practices: Security

If you are putting this nodeJS HTTP server beind NGINX, your NGINX declartion for the location will need additional fields:

server {
    listen IPv4:443;
    listen [::]:443;

    server_name example.com;
    root /some/path/to/files;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
        # Cookie Flags
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        # Cookie Flags
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        # Other

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;

        proxy_pass http://this_server_relay;
    }
}

upstream this_server_relay {
    server 127.0.0.1:5000;
    keepalive 8;
}

About

A Super Simple Twitch to Discord Notification Tool

https://twitch.discord.barrycarlyon.co.uk

License:Do What The F*ck You Want To Public License


Languages

Language:JavaScript 78.1%Language:Pug 21.2%Language:CSS 0.7%