'How to return a random sentence in Twitch chat, using Streamer.bot?
This is a simple functionality I have in my chatbot, but I want to customize it a little bit. Right now, when a user types !lurk, it returns one message. I want to add multiple other messages, and for it to pick a random one each time a user uses the command.
I would also like to have a separate list of sentences for when they come BACK from lurking. If you notice in the code, there's a second set where it displays a different message when the user uses the command a second time. It would also be nice if I could get it to un-lurk the user whenever they type ANYTHING in chat, instead of them having to use the command again.
Here's the code from inside the bot:
using System;
public class CPHInline
{
public bool Execute()
{
int connectionID = 0;
int count;
int totalCount;
string messageOut;
string userName = args["user"].ToString();
bool lurker = CPH.GetUserVar<bool>(userName, "lurker", true);
count = CPH.GetGlobalVar<int>("lurkCount", true);
totalCount = CPH.GetGlobalVar<int>("totalLurkCount", true);
string inString = args["rawInput"].ToString();
string[] outputer = inString.Split(' ');
if(String.Equals(outputer[0].ToLower(), "")) {
if(lurker == true) {
count--;
CPH.SetUserVar(userName, "lurker", false, true);
messageOut = $"{userName} is no longer lurking! Current Lurkers are now: {count}.";
} else if(lurker == false) {
count++;
totalCount++;
CPH.SetUserVar(userName, "lurker", true, true);
messageOut = $"{userName} is now lurking! Current Lurkers are now: {count}. We're now at {totalCount} all time lurkers!";
} else {
messageOut = "No Bueno";
}
} else if(String.Equals(outputer[0].ToLower(), "check")) {
if(lurker) {
messageOut = $"You are currently lurking! The current amount of lurkers: {count}. Total Lurkers: {totalCount}";
} else if(!lurker) {
messageOut = $"The current amount of lurkers: {count}. Total Lurkers: {totalCount}";
} else {
messageOut = "No Bueno";
}
} else if(String.Equals(outputer[0].ToLower(), "reset")) {
count = 0;
messageOut = $"The total amount of lurkers have been reset. New Count: {count}";
} else {
messageOut = "Incorrect usuage of the !lurk command";
}
CPH.SendMessage(messageOut);
CPH.SetGlobalVar("totalLurkCount", totalCount, true);
CPH.SetGlobalVar("lurkCount", count, true);
return true;
}
}```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|