-
Notifications
You must be signed in to change notification settings - Fork 0
StreamerBot
KK edited this page Feb 20, 2022
·
11 revisions
Using the Plugin in Streamer.bot
For setting up the Minecraft server, please see the Getting Started page.
Make sure that you have Streamer.bot installed before following guide!
- Inside Streamer.bot, navigate to the
Actionstab. - Right click on the
Actionstab and selectAdd. - Create a group for the action called
Minecraft Websocket. - Name the action
MC WS Connected. - Then press
Ok. - Add 2 more actions to the group, called
MC WS DisconnectedandMC WS Message.
- Inside Streamer.bot, navigate to the
Servers/Clientstab. - Click the sub-tab
Websocket Clients. - Inside the window, add a new Host, by right-clicking and pressing
Add. - Inside the popup window, set the
NametoMinecraft WebSocket Server. - Inside the popup window, set the
Hosttows://{localhost}:{8887}. (please replace{localhost}with your host, and{8887}with your port number) - Set the Action Connected to
MC WS Connected. - Set the Action Disconnected to
MC WS Disconnected. - Set the Action Message to
MC WS Message. - Click
Ok.
In this guide, the following will be the flowchart of the actions:
Example workflow:
WS Connect
- Log to file
WS Message
- Authenticate
- Subscribe to events
- Send events to WS Events
WS Disconnect
- Log to file
WS Events
- Get event ran
- Convert event data to Json, and store in variable
- Run WS Event-{event ran}
WS Event-{events}
- Send message in twitch chat
- Make a sub action
File->Write to file, make a new file calledWS_Logs.txt, and set it to append to the file, with the text%date% %time% - WS Connected.
- Make a sub action
File->Write to file, select the file calledWS_Logs.txt, and set it to append to the file, with the text%date% %time% - WS Disconnected.
This is where the magic starts!
- Make a sub action
File->Write to file, select the file calledWS_Logs.txt, and set it to append to the file, with the text%date% %time% - WS Message: %message%. - Make a sub action
C#->Run C# code- inside the C# window, add the following inside
Execute():
- inside the C# window, add the following inside
var auth = ""; // Add your authentication token here
string[] listeners = { // Add the events you want to listen to here
"PlayerDeathEvent",
"PlayerJoinEvent",
"PlayerQuitEvent",
"PlayerChatEvent",
"PlayerDamageEvent",
"PlayerHealEvent" ,
"PlayerAdvancementDoneEvent",
"PlayerChangedWorldEvent",
"PlayerFoodChangeEvent",
"PlayerDamagePlayerEvent"
};
var msg = args["message"].ToString();
if (msg.StartsWith("Authentication needed")) {
// Send authentication message
CPH.WebsocketSend("Bearer " + auth);
return true;
}
if (msg.StartsWith("Authentication not required") || msg.StartsWith("Successfully Authenticated")) {
// Subscribe to events
var listenString = "Listen " + String.Join("\nListen ", listeners);
CPH.WebsocketSend(listenString);
return true;
}
if (msg.StartsWith("Event ")) {
// Event received
CPH.SetArgument("event", msg.Substring("Event ".Length));
CPH.RunAction("MC WS Event Handler");
}
return true;- This will handle all messages between the server and the client.
- Make a sub action
C#->Run C# code- inside the C# window, add the following inside
Execute():
- inside the C# window, add the following inside
// Add these at the top of your code
// using Newtonsoft.Json;
// using System.Collections.Generic;
var ev = args["event"].ToString();
var evRun = ev.Split(' ')[0];
var unParsedJson = ev.Substring(evRun.Length);
List<object> json = JsonConvert.DeserializeObject<List<object>>(unParsedJson);
CPH.SetArgument("event-json", json);
CPH.RunAction("MC WS Event-" + evRun);
return true;- This will forward the event to the correct action.
- Replace
{event ran}with the event name you want to handle. - Handle the event
- Example with PlayerDeathEvent: (making the action name
MC WS Event-PlayerDeathEvent)
// Add this at the top of your code
// using System.Collections.Generic;
List<object> json = args["event-json"];
string player = json[0].ToString();
string deathMessage = json[1].ToString();
CPH.SendMessage(deathMessage);
return true;- Inside Streamer.bot, navigate to the
Actionstab. - Make an action called
Forward Twitch Chat to Minecraft Chat. - Navigate to the
Settings->Eventstab. - Set
Chat MessagetoForward Twitch Chat to Minecraft Chat. - Go back to the
Forward Twitch Chat to Minecraft Chataction. - Make a sub action
C#->Run C# code- inside the C# window, add the following inside
Execute():
- inside the C# window, add the following inside
var msg = args["message"].ToString();
// Make sure to remove bad characters from the message, if you don't, users can break out of tellraw, and other commands
msg = msg.Replace("\\", "");
msg = msg.Replace("\"", "");
var user = args["user"].ToString();
CPH.WebsocketSend("Command say ["+user+"] " + msg);
return true;- This will forward the message to the Minecraft server.