Skip to content

BrianMMcClain/reactive-bot-framework

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

reactive-bot-framework

This is a basic bot framework using Project Reactor, a reactive framework for Spring. This was built as a way to learn reactive programming on top of Spring, while implementing something useful.

Currently, the bot acts as a Twitch chat bot, expecting the following environment variables to be defined:

  • TWITCH_NICK: Your Twitch username
  • TWITCH_OAUTH: The Twitch IRC authentication requires that you use an OAuth token rather than your password. You can generate an OAuth token here
  • TWITCH_CHANNEL: The channel that the bot will connect to

Adding a Command

Every bot command should be a part of the com.github.brianmmcclain.reactivebotframework.commands pacakge and extend the BotCommand class, implementing the execute() method at bare-minimum. The execute() method expectes two arguments:

  • data (String): The full message, minus the command prefix
  • tMessage (TwitchMessage): The TwitchMessage object which contains the full information about the message

The execute() method should return a String, which will be sent back to the channel it was receive from.

For example, the following command echos back the message received, tagging the person that sent it:

package com.github.brianmmcclain.reactivebotframework.commands;

import com.github.brianmmcclain.reactivebotframework.TwitchMessage;

public class Echo extends BotCommand {
    @Override
    public String execute(String data, TwitchMessage tMessage) {
        return "@" + tMessage.getSentBy() + " " + data;
    }
}

Deploying

With the three environment variables described above, the application can be ran as a normal Spring application:

./mvnw spring-boot:run

If you want to run it on Kubernetes, there are several scripts in the deployment directory to help, including one to deploy Prometheus and Grafana.

You can build a container for the application using:

./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=brianmmcclain/reactive-bot-framework

And push it to Docker Hub with:

docker push brianmmcclain/reactive-bot-framework

Replacing "brianmmcclain" with your own username in both commands.

Then to deploy to Kubernetes, replace the image name in the deploy.yml with your own, as well as set the proper values in the secret.yml file. REMEMBER: The values in the secret need to be base64-encoded. Finally, set the "TWITCH_CHANNEL" environment variable to the channel you wish the bot to join

You can then deploy the application with

kubectl apply -f deployment/secret.yml
kubectl apply -f deployment/deploy.yml

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published