Skip to content

Chat actions, custom events, other code and the keyboard

C# methods for a Run C# code step. See C# methods for how to use them.

SendAction

Sends a /me line in your Twitch chat, shown in italics. If that is not possible, it is sent as a normal chat message. Empty text sends nothing.

void SendAction(string action, bool bot = true, bool fallback = true)

Gives back: Nothing.

Example

CPH.SendAction("waves at everyone in chat");

TriggerEvent

Fires a custom event by name. Actions with a "Custom code event" trigger for that name run, and get this action's variables unless you pass false.

void TriggerEvent(string eventName, bool useArgs = true)

Gives back: Nothing.

Example

CPH.TriggerEvent("confetti");

KeyboardPress

Presses keys on your keyboard for you, like {F13} or ^{S} for Ctrl+S (+ is Shift, % is Alt). Fails with "not supported" when Cuebot cannot press keys on this computer.

void KeyboardPress(string keyPress)

Gives back: Nothing.

Example

CPH.KeyboardPress("{F13}");

ExecuteMethod

Runs one method (with no inputs) from another "Execute C# code" sub-action. It finds that code by its "Code name" setting, or as the first C# code in the action with that name.

bool ExecuteMethod(string codeName, string methodName)

Gives back: What the method gives back (true for methods that give nothing). false when the code or method is not found.

Example

bool ok = CPH.ExecuteMethod("Helpers", "ResetScores");
CPH.LogInfo($"Reset worked: {ok}");

TriggerCodeEvent

Fires a custom event by name, with the values of a JSON text (like {"amount": 50}) as its variables. Actions with a "Custom code event" trigger for that name run.

void TriggerCodeEvent(string eventName, string json)

Gives back: Nothing.

Example

CPH.TriggerCodeEvent("confetti", "{\"amount\": 50}");

UrlEncode

Makes text safe to put in a web link, for example spaces become %20.

string UrlEncode(string text)

Gives back: The safe text.

Example

string safe = CPH.UrlEncode("hello world & friends");
CPH.LogInfo(safe);

EscapeString

Makes text safe to put inside a JSON text value: quotes, backslashes and line breaks get a backslash in front.

string EscapeString(string text)

Gives back: The escaped text.

Example

string safe = CPH.EscapeString("She said \"hi\"");
CPH.LogInfo(safe);

BroadcastUdp

Sends a small message (UDP) to a port on this computer only (127.0.0.1). Text is sent as is; anything else is sent as JSON.

int BroadcastUdp(int port, object? data)

Gives back: How many bytes were sent.

Example

int sent = CPH.BroadcastUdp(9000, "flash");
CPH.LogInfo($"Sent {sent} bytes.");

AddUserToGroup

Older form: adds a Twitch user to one of your groups by their number id. The group must already exist.

bool AddUserToGroup(int userId, string groupName)

Gives back: true when they were added. false when they were already in it or the group does not exist.

Example

bool added = CPH.AddUserToGroup(12345678, "Regulars");
CPH.LogInfo($"Added: {added}");

RemoveUserFromGroup

Older form: takes a Twitch user out of one of your groups by their number id.

bool RemoveUserFromGroup(int userId, string groupName)

Gives back: true when they were removed. false when they were not in it.

Example

bool removed = CPH.RemoveUserFromGroup(12345678, "Regulars");
CPH.LogInfo($"Removed: {removed}");

UserInGroup

Older form: checks whether a Twitch user (by their number id) is in one of your groups.

bool UserInGroup(int userId, string groupName)

Gives back: true when they are in the group, otherwise false.

Example

bool inGroup = CPH.UserInGroup(12345678, "Regulars");
CPH.LogInfo($"In group: {inGroup}");

DiscordPostTextToWebhook

Older form: posts a message to a Discord channel through its webhook link, with an optional bot name and read-aloud (TTS) switch, but no picture.

string DiscordPostTextToWebhook(string webhookUrl, string content, string? username, bool textToSpeech)

Gives back: The new Discord message's id, or empty text when Discord did not say.

Example

string id = CPH.DiscordPostTextToWebhook("https://discord.com/api/webhooks/123/abc", "We are live!", "Cuebot", false);
CPH.LogInfo($"Message id: {id}");

WebsocketSend

Sends bytes through one of your WebSocket clients (set up on the Servers page). Cuebot turns the bytes into text first. 0 is your first client.

void WebsocketSend(byte[] data, int connection = 0)

Gives back: Nothing.

Example

byte[] data = System.Text.Encoding.UTF8.GetBytes("hello");
CPH.WebsocketSend(data, 0);