~johanvandegriff/live.johanv.xyz

67055f6015a554522017da1eb449fa32ec80a0bc — Johan Vandegriff 1 year, 1 month ago e091476
pull and display dlive chat
3 files changed, 48 insertions(+), 21 deletions(-)

M index.html
M package.json
M server.js
M index.html => index.html +1 -1
@@ 84,7 84,7 @@
                        .append($('<span>').text(msg.name)
                            .css('color', colorHash.hex(msg.name+"...."))
                            .css('font-weight', 'bold'))
                        .append(": " + msg.text)
                        .append($('<span>').text(": " + msg.text))
                    );
                    
                    //scroll to the most recent message

M package.json => package.json +1 -0
@@ 10,6 10,7 @@
    "dependencies": {
        "@types/node": "^14.11.8",
        "color-hash": "^1.0.3",
        "dlivetv-api": "^2.1.21",
        "dotenv": "^8.2.0",
        "express": "^4.15.2",
        "jquery": "^3.5.1",

M server.js => server.js +46 -20
@@ 4,24 4,9 @@ const http = require('http');
const https = require('https');
const server = http.createServer(app);
const io = require('socket.io')(server);
const dotenv = require('dotenv'); //for storing secrets in an env file
const tmi = require('tmi.js'); //twitch chat https://dev.twitch.tv/docs/irc

require('dotenv').config({ path: '/srv/secret-twitch.env' }) //bot API key and other info
//the /srv/secret-twitch.env file should look like:
//BOT_USERNAME=jjvantheman (or create a second account for the bot)
//BOT_OATH_TOKEN=oauth:blah blah blah
//BOT_CHANNEL=jjvantheman

// Define configuration options
const opts = {
    identity: {
        username: process.env.BOT_USERNAME,
        password: process.env.BOT_OAUTH_TOKEN
    },
    channels: [process.env.BOT_CHANNEL]
};

//console.log("TWITCH SECRETS " + JSON.stringify(opts));
const Dlive = require('dlivetv-api'); //dlive chat https://github.com/lkd70/dlivetv-api

//expose js libraries to client so they can run in the browser
app.get('/', (req, res) => {res.sendFile(__dirname + '/index.html')});


@@ 61,6 46,23 @@ function iosend(name, text) {
}

//twitch chat stuff
dotenv.config({ path: '/srv/secret-twitch.env' }) //bot API key and other info
//the /srv/secret-twitch.env file should look like:
//TWITCH_BOT_USERNAME=jjvantheman (or create a second account for the bot)
//TWITCH_BOT_OATH_TOKEN=oauth:blah blah blah
//TWITCH_BOT_CHANNEL=jjvantheman

// Define configuration options
const opts = {
    identity: {
        username: process.env.TWITCH_BOT_USERNAME,
        password: process.env.TWITCH_BOT_OAUTH_TOKEN
    },
    channels: [process.env.TWITCH_BOT_CHANNEL]
};

//console.log("TWITCH SECRETS " + JSON.stringify(opts));

// Create a client with our options
const client = new tmi.client(opts);
// Register our event handlers (defined below)


@@ 132,7 134,31 @@ function rollDice () {
    return Math.floor(Math.random() * sides) + 1;
}


//dlive chat stuff
dotenv.config({ path: '/srv/secret-dlive.env' }) //bot API key and other info
//the /srv/secret-dlive.env file should look like:
//DLIVE_BOT_SECRET=blah blah blah
//DLIVE_BOT_CHANNEL=jjvantheman
// console.log("DLIVE_BOT_SECRET " + process.env.DLIVE_BOT_SECRET);
// console.log("DLIVE_BOT_CHANNEL " + process.env.DLIVE_BOT_CHANNEL);
const bot = new Dlive(process.env.DLIVE_BOT_SECRET, process.env.DLIVE_BOT_CHANNEL);

// Monitor for 'ChatText' events
bot.on('ChatText', msg => {
    // Log every message recieved to the console
    console.log(`[${msg.sender.displayname}]: ${msg.content}`);

    //copy dlive chat to socket chat
    iosend(msg.sender.displayname, msg.content);

    handleCommand(msg.content);

    //TODO bot.sendMessage is broken
    // If someone says "hello" in our stream, greet then with a message
    // if (msg.content.toLowerCase() === 'hello') {
    //     bot.sendMessage(`Hi there ${msg.sender.displayname}! Welcome to the stream`);
    // }
});

//start the http server
var default_port = 8080;


@@ 142,12 168,12 @@ server.listen(process.env.PORT || default_port, () => {

//TODO clean up the CSS, make text look good
//TODO add cards instead of links
//TODO pull dlive chat
//TODO pull youtube chat
//TODO only change nickname when email is provided
//TODO save nickname with cookies
//TODO add a README with setup instructions
//TODO add a README with setup instructions and change package name and version
//TODO favicon
//TODO use flexbox for CSS?
//TODO obs overlay
//TODO !carl command pass in the rest of the message to the CARL API
//TODO unify the commands