• Hello

    Welcome to StevoTVR.com. This is where I attempt to articulate my thoughts into words. Feel free to wander aimlessly...

Creating a Twitch Chat Bot

Posted Aug 20, 2020 at 2:44 pm

This tutorial will show you an easy way to create your own Twitch chat bot for your channel. We will be writing this in JavaScript using NodeJS. This is how I created the chat bot component of Stevelabs.

The completed tutorial files are available on GitHub.

Prerequisites

  • NodeJS (get)
  • Your favorite text editor or IDE
  • Your Twitch OAuth password (get)

I will leave the setup of the above to you.

Live Tutorial

Create Your Project

Open a terminal and navigate to an empty directory. Initialize a new NodeJS project using this command:

npm init

It will ask you some questions. The defaults will work fine, but feel free to add your own personalized information. After you answer the questions and confirm the results, NPM will create your package.json file.

Since we will be using the tmi.js package, we must install it to our project using this command:

npm install tmi.js --save

Note that --save will automatically update your package.json file.

Create Your Configuration File

Create a new text file in your project directory called config.json.

{
    "username": "CHANNEL_USERNAME",
    "password": "OAUTH_PASSWORD"
}

Replace CHANNEL_USERNAME with your Twitch channel username and OAUTH_PASSWORD with your channel’s OAuth password.

Create Your Application

Create a new text file in your project directory called index.js. This is your main application file.

Include Your Configuration

const config = require('./config.json');

This will include your configuration JSON as an object assigned to the variable named config.

Include The tmi.js Library

const tmi = require('tmi.js');

This will include the tmi.js library and assign it to the variable named tmi. As you may have noticed, require can be used to include your own files as well as installed packages.

Create Your Client

The client is what you will use to listen to events in your Twitch channel chat, as well as send messages to it.

const client = new tmi.Client({
    connection: {
        secure: true,
        reconnect: true
    },
    identity: {
        username: config.username,
        password: config.password
    },
    channels: [
        config.username
    ]
});

Now you can access the client using the variable called client. The constructor of the Client class accepts an object containing your configuration. See the documentation for an explanation of all the available options.

Connect Your Bot To Chat

You’ve created your client, so now it is time to connect to Twitch.

client.connect()
    .then(() => {
        console.log('connected to Twitch chat');
    })
    .catch(err => {
        console.warn('failed to connect to Twitch chat');
        console.log(err);
    });

The connect method takes no arguments and returns a Promise. You can chain then and catch method calls to a promise to handle the results. This is a common pattern in asynchronous JavaScript.

Put code you want to run when the connection is successful within the then callback and handle any errors within the catch callback. Here, we are writing messages to the console.

Respond To Chat Messages

Let’s start interacting with chat! In this example we will respond to “!hello” with “Hello, user!”

client.on('chat', (channel, userstate, message, self) => {
    if (message.trimLeft().startsWith('!hello')) {
        client.say(channel, `Hello, ${userstate['display-name']}!`);
    }
});

The on method of your client is used to start listening for events. It accepts two arguments: the name of the event and a callback function to run when the event happens. See the documentation for a list of available events.

The “chat” event sends back the following data as arguments to the callback function:

  • The name of the channel (channel)
  • Information about the user (userstate)
  • The message that was sent (message)
  • Whether the message was sent by the client (self)

Note that we are using client.say to send a message to the chat. It takes two arguments: the name of the channel to which to send and the message text to send.

The userstate argument is an object containing a lot of useful information. You can use console.log(userstate) to explore the available data.

In many cases you will want to check the self boolean to ignore messages sent by your bot to avoid an infinite loop!

Respond To More Events

Here is another example showing how to respond to cheer events:

client.on('cheer', (channel, userstate, message) => {
    console.log(`${userstate.username} cheered ${userstate.bits} bits with message: ${message}`);
});

This example simply logs the event to the console, but you can do anything you want here. Notice that userstate.bits contains the number of bits cheered. Some of the events add some data to the userstate object.

For more examples, see the documentation. The only event that is missing is new followers. You must use a webhook for that, but that is for another tutorial.

Run Your Application

To run your bot, run this command from within your project directory:

node .\index.js

If everything is correct, you should see “connected to Twitch chat.” Otherwise you will see an error.

Now, if you go type “!hello” in your Twitch channel chat, your bot should respond. If it does, then congratulations, it’s alive!

The End

You have reached the end of the written tutorial. Thank you for reading and I hope you found it useful. Feel free to post a comment here if you run into any problems.

Motion Tracking in DaVinci Resolve

Posted Aug 19, 2020 at 3:28 pm

Nutopia: The Meeting

Posted Aug 5, 2020 at 12:00 am

New PC 2020

Posted Apr 30, 2020 at 4:15 pm

For me, the challenge of building a custom PC is finding someone to put it all together. I know what parts to get and how to put it all together, but I can’t physically do the work, so I have to talk someone else through the process. Troubleshooting the problems that inevitably come up is also hindered by my inability to physically manipulate the hardware.

This time, however, I decided to try my luck at ordering a fully assembled system. I ordered a custom PC from CyberPowerPC. Here are the specs:

  • MB: ASUS ROG Strix Z390-E Gaming
  • CPU: Intel Core i9 9900K @ 4.7GHz
  • RAM: 32GB (2x16GB) G.SKILL Ripjaws V DDR4 3200MHz
  • GPU: MSI Geforce RTX 2080 Ti 11GB
  • Storage: 1TB Samsung 970 EVO Plus NVMe M.2 SSD
  • PSU: EVGA 850W GQ 80+ Gold
  • Case: Corsair Carbide Series 678C
  • CPU Cooler: Corsair Hydro H115i PRO RGB 280mm Liquid CPU Cooler
  • OS: Microsoft Windows 10 Professional

It took about two weeks to arrive after placing the order. It was packaged very well (I ordered the enhanced packaging) and everything was in perfect condition. It worked right out of the box. They did a great job with cable management with most of the wires out of sight and neatly bundled with zip ties.

We had to transfer some drives and the capture card from my old system, so some of the zip ties had to be cut and cable management disturbed. The M.2 cards are secured to the motherboard by the heat sinks rather than mounting screws. I don’t know if that is how it’s supposed to be but that is how it came. That caused an issue where the main drive was not detected and we had to re-mount it. Other than that, everything went as planned.

I have a few minor complaints. The GPU I ordered was an Nvidia RTX 2080 Ti, but the one that I got was an MSI RTX 2080 Ti, but those are equivalent as far as I am concerned. I was also supposed to get a free 2TB 7200 RPM hard drive but I got a 5400 RPM drive, but I can’t really complain about a free hard drive. I also would have preferred that the boot drive be installed in the M.2 slot farther from the CPU, but that is a very minor complaint (in hindsight, we could have easily swapped the M.2 cards when we had it open).

In conclusion, the overall experience was good and I would use CyberPowerPC in the future. I also considered iBuyPower but I decided to go with CyberPowerPC because I was able to get a better GPU for the same price.

Anyway, please enjoy this photo of the inside of the case. The AVerMedia capture card and the Blu-ray drive were supplied by me. Also there are a few untamed SATA cables that were not there originally.

Streaming

Posted Mar 23, 2019 at 2:48 pm

I recently started streaming on my Twitch channel. I invested so much in quality audio recording equipment for my animation, so I thought I would put it to good use and do some broadcasting. That was actually my main inspiration.

I’ve been streaming several different games on different days of the week and it’s been pretty fun so far. I may decide to change this format in the future. I also need to work on the branding and graphics, but for now I am keeping it simple.

Come check it out if you are in to this kind of thing…

https://www.twitch.tv/stevotvr

Controlling Game Consoles From A PC

Posted Feb 25, 2019 at 4:25 pm

This post is a continuation of my previous post Playing Games With One Hand. The setup described in that post works great for PC games, but it is useless if you want to play console games. In order to do that, you need a way to connect the PC to the console and emulate a controller.

After searching for a bit, I found a product that can do that, called the Titan One. This little device allows you to use different controllers with different consoles, and most importantly, keyboard/mouse via the MaxAim DI plugin.

The MaxAim DI plugin maps keyboard and mouse (buttons and movement) input to buttons on a controller. When you plug the program cable into the PC, the virtual controller is able to send input to the console. It supports many controller types.

I am using this with a Nintendo Switch, which requires a little bit of setup. First, since this is a wired device, the System Settings > Controllers and Sensors > Pro Controller Wired Communication setting must be enabled. I am using the XBox 360 controller layout in the MaxAim DI plugin.

So far I have been playing Super Mario Odyssey fairly effectively. This device works very well. I also tried the Pokémon: Let’s Go Demo, but found out the game doesn’t support the Pro Controller, so that doesn’t work. I can’t comment on any other games or consoles yet, but maybe I will update this post after I try more of them.

A Perfect Circle 11/17/18 Anaheim

Posted Nov 18, 2018 at 7:48 pm

It’s been a while since I’ve done a concert review, so here is a fresh one. Last night I saw A Perfect Circle at The Honda Center in Anaheim, CA. Overall, it was a great show with a good mix of material from the new and previous albums. I was not expecting an opening act, but they had two openers, Night Club and Tricky.

The show was visually stunning, with lots of colored lights and a cool rear projected video to go along with the music. The players are all pretty much silhouettes throughout the show, so that’s the downside if you like to see the band members clearly.

The venue isn’t known to have very good sound quality, so some of the louder songs didn’t sound great but the rest of the songs were decent. My favorite section of the set was Peace, Love and UnderstandingVanishingThe Noose.

Making Cartoons

Posted Jun 20, 2018 at 9:35 pm

I decided to try to learn how to create animated videos. So, I got a subscription to the Adobe Creative Cloud and Skillshare to learn via video tutorials. I also bought a condenser microphone for recording dialog. After watching a few classes, I started working on the first video.

The first video is called Bob’s Robot. I drew the backgrounds and characters in Photoshop, recorded and edited dialogue in Audition, and animated everything in Character Animator. Here is the result:

The second video is called Good Advice Unicorn. This time I drew backgrounds in Photoshop, characters in Illustrator, and animated using After Effects. Here it is:

The third (and latest as of writing this) video is called Nutopia 2: Attack of the Legumes. I used the same workflow as the previous video, except I used an inverse kinematics plugin to rig and animate the characters. I also recruited some guest voices, which was tricky but worth the effort. This one is significantly longer than the previous videos, and I think the quality is significantly better. Here it is:

The YouTube channel is called VideoStove. You can find a link to it on the amazing website I created for it.

Anyway, that is what I have been spending my time on lately. Enjoy!

Nutopia

Posted at 10:00 am

Good Advice Unicorn

Posted Apr 2, 2018 at 12:00 pm