Skip to content

mgroves/MattsTwitchBot

Repository files navigation

Matt’s Twitch Bot

This is the Twitch bot I use for https://twitch.tv/matthewdgroves. It’s a tool for making the channel more useful and enjoyable, but it’s also a tool for me to dogfood Couchbase Server (as well as ASP.NET/C# stuff).

Here’s a breakdown of each project

MattsTwitchBot.Core

This project has a class MattsChatBotHostedService. This implements IHostedService, which means it’s designed to be run as a hosted service in an ASP.NET Core project. However, MattsTwitchBot.Core is not, itself, an ASP.NET Core project.

MattsChatBotHostedService uses the TwitchLib API to listen for incoming messages. A message will instantiate some Request object, which will then be given to Mediatr to handle.

What you need to know to get it to work: put your Twitch OAuth key and ApiClientId/Secret into appsettings.Development.json. I use my own Twitch user account as the bot, but it should still work fine if you are using a separate bot account.

MattsTwitchBot.Web

This is an ASP.NET Core 3 project. It does up to three things:

  • Start and host the MattsChatBotHostedService service from the Core library.

  • Provide a home page that will receive messages from a SignalR hub. This home page can be used from within your OBS setup. You can just open it directly in Chrome if you’d like (which is what I do for now). It is responsible for popups, sound effects, anything that I want to be seen/heard on the stream.

  • (Experimental) Receive notifications about documents being updated in Couchbase to the Couchbase Notify endpoint. This currently doesn’t do anything, it’s experimental, but it’s part of my dogfooding goals.

MattsTwitchBot.Tests

These are unit tests (and supporting fakes).

Getting set up

appsettings.Development.json

Create your own appsetting.Development.json file. You can just rename the sample appsetting.DevelopmentTemplate.json.

Put your various Twitch tokens, Couchbase connection/credentials information in here. Also enter a "bearer token" for authorization purposes. Only you will need to know this token. Make it something secure in production, something easy if you are doing some local coding work. Once the bearer token is validated, it will be put into a cookie, so you don’t need to use it with every single HTTP request.

Couchbase

Currently you still need to do some manual setup of the Couchbase node. You will need to setup the cluster with data, query, index services enabled.

Create a bucket called "twitchchat" (or change the name in appsettings if you want something different).

You will also need to create an index: CREATE INDEX ix_type ON twitchchat (type) WHERE type IS NOT MISSING;

Administrating

Here are the pages:

  • / (home) - this is the page meant to be displayed on Twitch (put a url into OBS like http://foo/?token=mytoken)

  • /dashboard - this is a management/configuration screen to control static commands, social media badges

  • /profile/<twitchusername>` - this is the page to edit a user profile (for instance https://foo/profile/calvinaallen?token=mytoken) - you can go directly here, or access it from the dashboard

About

Yet another Twitch chat bot

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published