Skip to content

surlydev/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). Currently only testing the various handlers.

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 in development. 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 (you only need the data service at this point, but you should probably add query/index, and you will need eventing for the experimental stuff).

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

Startup.cs

Notice the app.UseWhen statement. This is part of the experimental eventing stuff. Feel free to remove that if you aren’t doing that.

Administrating

Right now, there are only two pages:

About

Yet another Twitch chat bot

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 72.7%
  • JavaScript 16.5%
  • CSS 5.3%
  • Shell 2.9%
  • HTML 2.2%
  • Dockerfile 0.4%