Commands, groups and timers¶
C# methods for a Run C# code step. See C# methods for how to use them.
EnableCommand¶
Turns a command on, by its id or name. Stops your code with an error when no command has that id or name.
void EnableCommand(string id)
Gives back: Nothing.
Example
CPH.EnableCommand("!hug");
DisableCommand¶
Turns a command off, by its id or name, so chat can no longer use it. Stops your code with an error when no command has that id or name.
void DisableCommand(string id)
Gives back: Nothing.
Example
CPH.DisableCommand("!hug");
GetCommands¶
Gives you a list of all your commands, each with its id, name, group, whether it is on, its chat words and its cooldowns in seconds.
List<CommandData> GetCommands()
Gives back: A list of your commands.
Example
var commands = CPH.GetCommands();
CPH.LogInfo($"You have {commands.Count} commands.");
CommandGetCounter¶
Tells you how many times a command was used in total, by its id or name. Stops your code with an error when no command has that id or name.
int CommandGetCounter(string id)
Gives back: The number of uses.
Example
int uses = CPH.CommandGetCounter("!hug");
CPH.LogInfo($"!hug was used {uses} times.");
CommandResetCounter¶
Sets a command's total use counter back to 0. Stops your code with an error when no command has that id or name.
void CommandResetCounter(string id)
Gives back: Nothing.
Example
CPH.CommandResetCounter("!hug");
CommandResetAllUserCounters¶
Sets every viewer's use counter for a command back to 0, on all platforms. Stops your code with an error when no command has that id or name.
void CommandResetAllUserCounters(string id)
Gives back: Nothing.
Example
CPH.CommandResetAllUserCounters("!hug");
CommandResetGlobalCooldown¶
Starts a command's cooldown for everyone again, with its full length. Stops your code with an error when no command has that id or name.
void CommandResetGlobalCooldown(string id)
Gives back: Nothing.
Example
CPH.CommandResetGlobalCooldown("!hug");
CommandResetAllUserCooldowns¶
Starts every running per-viewer cooldown of a command again, with its full length. Stops your code with an error when no command has that id or name.
void CommandResetAllUserCooldowns(string id)
Gives back: Nothing.
Example
CPH.CommandResetAllUserCooldowns("!hug");
CommandResetUserCooldown¶
Starts one viewer's cooldown for a command again, with its full length. Give their user id and platform; the shorter forms mean Twitch.
void CommandResetUserCooldown(string id, string userId, Platform platform)
void CommandResetUserCooldown(string id, string userId)
void CommandResetUserCooldown(string id, int userId)
Gives back: Nothing.
Example
CPH.CommandResetUserCooldown("!hug", "12345678", Platform.Twitch);
CommandRemoveGlobalCooldown¶
Ends a command's cooldown for everyone right now, so it can be used again. Stops your code with an error when no command has that id or name.
void CommandRemoveGlobalCooldown(string id)
Gives back: Nothing.
Example
CPH.CommandRemoveGlobalCooldown("!hug");
CommandRemoveAllUserCooldowns¶
Ends every per-viewer cooldown of a command right now. The cooldown for everyone keeps running. Stops your code with an error when no command has that id or name.
void CommandRemoveAllUserCooldowns(string id)
Gives back: Nothing.
Example
CPH.CommandRemoveAllUserCooldowns("!hug");
CommandRemoveUserCooldown¶
Ends one viewer's cooldown for a command right now. Give their user id and platform; the shorter forms mean Twitch.
void CommandRemoveUserCooldown(string id, string userId, Platform platform)
void CommandRemoveUserCooldown(string id, string userId)
void CommandRemoveUserCooldown(string id, int userId)
Gives back: Nothing.
Example
CPH.CommandRemoveUserCooldown("!hug", "12345678", Platform.Twitch);
CommandAddToGlobalCooldown¶
Adds seconds to a command's cooldown for everyone. If it is not running, it starts now with that many seconds. Stops your code with an error when no command has that id or name.
void CommandAddToGlobalCooldown(string id, int seconds)
Gives back: Nothing.
Example
CPH.CommandAddToGlobalCooldown("!hug", 30);
CommandAddToAllUserCooldowns¶
Adds seconds to every running per-viewer cooldown of a command. Viewers without a running cooldown are not changed. Stops your code with an error when no command has that id or name.
void CommandAddToAllUserCooldowns(string id, int seconds)
Gives back: Nothing.
Example
CPH.CommandAddToAllUserCooldowns("!hug", 30);
CommandAddToUserCooldown¶
Adds seconds to one viewer's cooldown for a command (starting it when it is not running). Give their user id and platform; the shorter forms mean Twitch.
void CommandAddToUserCooldown(string id, string userId, Platform platform, int seconds)
void CommandAddToUserCooldown(string id, string userId, int seconds)
void CommandAddToUserCooldown(string id, int userId, int seconds)
Gives back: Nothing.
Example
CPH.CommandAddToUserCooldown("!hug", "12345678", Platform.Twitch, 30);
CommandGetUserCounter¶
Tells you how many times one viewer used a command, by their login name, platform and the command's id or name.
CommandCounter? CommandGetUserCounter(string userLogin, Platform platform, string commandId)
Gives back: The viewer's counter (with Count), or null (nothing) when the command does not exist.
Example
var counter = CPH.CommandGetUserCounter("coolviewer", Platform.Twitch, "!hug");
if (counter != null) CPH.LogInfo($"{counter.UserName} used it {counter.Count} times.");
CommandGetUserCounterById¶
Tells you how many times one viewer used a command, by their user id, platform and the command's id or name.
CommandCounter? CommandGetUserCounterById(string userId, Platform platform, string commandId)
Gives back: The viewer's counter (with Count), or null (nothing) when the command does not exist.
Example
var counter = CPH.CommandGetUserCounterById("12345678", Platform.Twitch, "!hug");
if (counter != null) CPH.LogInfo($"Used {counter.Count} times.");
CommandResetUserCounter¶
Sets one viewer's use counter for a command back to 0, by their user id and platform. Stops your code with an error when no command has that id or name.
void CommandResetUserCounter(string commandId, string userId, Platform platform)
Gives back: Nothing.
Example
CPH.CommandResetUserCounter("!hug", "12345678", Platform.Twitch);
CommandResetUsersCounters¶
Sets every viewer's use counter for a command back to 0, for one platform only. Cuebot always saves counters, so the true/false value is ignored.
void CommandResetUsersCounters(string commandId, Platform platform, bool persisted)
Gives back: Nothing.
Example
CPH.CommandResetUsersCounters("!hug", Platform.Twitch, true);
CommandSetGlobalCooldownDuration¶
Changes how long a command's cooldown for everyone lasts, in seconds, and saves it. Below 0 counts as 0. Stops your code with an error when no command has that id or name.
void CommandSetGlobalCooldownDuration(string id, int seconds)
Gives back: Nothing.
Example
CPH.CommandSetGlobalCooldownDuration("!hug", 60);
CommandSetUserCooldownDuration¶
Changes how long a command's per-viewer cooldown lasts, in seconds, and saves it. Below 0 counts as 0. Stops your code with an error when no command has that id or name.
void CommandSetUserCooldownDuration(string id, int seconds)
Gives back: Nothing.
Example
CPH.CommandSetUserCooldownDuration("!hug", 120);
AddGroup¶
Makes a new, empty group of viewers.
bool AddGroup(string groupName)
Gives back: true when it was made. false when the name is empty or already used.
Example
bool made = CPH.AddGroup("Regulars");
CPH.LogInfo($"Group made: {made}");
DeleteGroup¶
Deletes a group of viewers.
bool DeleteGroup(string groupName)
Gives back: true when it was deleted. false when there is no such group.
Example
bool deleted = CPH.DeleteGroup("Regulars");
CPH.LogInfo($"Deleted: {deleted}");
GetGroups¶
Gives you the names of all your viewer groups.
List<string> GetGroups()
Gives back: A list of group names.
Example
var groups = CPH.GetGroups();
CPH.LogInfo(string.Join(", ", groups));
GroupExists¶
Checks whether you have a viewer group with this name.
bool GroupExists(string groupName)
Gives back: true when the group exists, otherwise false.
Example
bool exists = CPH.GroupExists("Regulars");
CPH.LogInfo($"Regulars exists: {exists}");
ClearUsersFromGroup¶
Takes every viewer out of a group. The group itself stays.
bool ClearUsersFromGroup(string groupName)
Gives back: true when it worked. false when there is no such group.
Example
bool cleared = CPH.ClearUsersFromGroup("Regulars");
CPH.LogInfo($"Cleared: {cleared}");
UsersInGroup¶
Gives you a list of the viewers in a group, each with their id, login, name and platform.
List<GroupUser> UsersInGroup(string groupName)
Gives back: A list of viewers (empty when the group does not exist).
Example
var users = CPH.UsersInGroup("Regulars");
CPH.LogInfo($"{users.Count} people in Regulars.");
AddUserToGroup¶
Adds a viewer to a group, by their name and platform. The form without a platform means Twitch. The group must already exist.
bool AddUserToGroup(string userName, Platform platform, string groupName)
bool AddUserToGroup(string userName, 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("coolviewer", Platform.Twitch, "Regulars");
CPH.LogInfo($"Added: {added}");
AddUserIdToGroup¶
Adds a viewer to a group, by their user id and platform. The form without a platform means Twitch. The group must already exist.
bool AddUserIdToGroup(string userId, Platform platform, string groupName)
bool AddUserIdToGroup(string 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.AddUserIdToGroup("12345678", Platform.Twitch, "Regulars");
CPH.LogInfo($"Added: {added}");
RemoveUserFromGroup¶
Takes a viewer out of a group, by their name and platform. The form without a platform means Twitch.
bool RemoveUserFromGroup(string userName, Platform platform, string groupName)
bool RemoveUserFromGroup(string userName, string groupName)
Gives back: true when they were removed. false when they were not in it.
Example
bool removed = CPH.RemoveUserFromGroup("coolviewer", Platform.Twitch, "Regulars");
CPH.LogInfo($"Removed: {removed}");
RemoveUserIdFromGroup¶
Takes a viewer out of a group, by their user id and platform. The form without a platform means Twitch.
bool RemoveUserIdFromGroup(string userId, Platform platform, string groupName)
bool RemoveUserIdFromGroup(string userId, string groupName)
Gives back: true when they were removed. false when they were not in it.
Example
bool removed = CPH.RemoveUserIdFromGroup("12345678", Platform.Twitch, "Regulars");
CPH.LogInfo($"Removed: {removed}");
UserInGroup¶
Checks whether a viewer is in a group, by their name and platform. The form without a platform means Twitch.
bool UserInGroup(string userName, Platform platform, string groupName)
bool UserInGroup(string userName, string groupName)
Gives back: true when they are in the group, otherwise false.
Example
bool inGroup = CPH.UserInGroup("coolviewer", Platform.Twitch, "Regulars");
CPH.LogInfo($"In group: {inGroup}");
UserIdInGroup¶
Checks whether a viewer is in a group, by their user id and platform. The form without a platform means Twitch.
bool UserIdInGroup(string userId, Platform platform, string groupName)
bool UserIdInGroup(string userId, string groupName)
Gives back: true when they are in the group, otherwise false.
Example
bool inGroup = CPH.UserIdInGroup("12345678", Platform.Twitch, "Regulars");
CPH.LogInfo($"In group: {inGroup}");
EnableTimer¶
Turns a timer on, by its name (an id works too), and starts its countdown from now. Lasts until the timer is edited or Cuebot restarts. Errors when there is no such timer.
void EnableTimer(string timerName)
Gives back: Nothing.
Example
CPH.EnableTimer("Hydrate Reminder");
DisableTimer¶
Turns a timer off, by its name (an id works too). Lasts until the timer is edited or Cuebot restarts. Stops your code with an error when there is no such timer.
void DisableTimer(string timerName)
Gives back: Nothing.
Example
CPH.DisableTimer("Hydrate Reminder");
EnableTimerById¶
Turns a timer on, by its id (a name works too), and starts its countdown from now. Lasts until the timer is edited or Cuebot restarts. Errors when there is no such timer.
void EnableTimerById(string timerId)
Gives back: Nothing.
Example
CPH.EnableTimerById("5f2c1a7e-3b4d-4e8f-9a10-2b3c4d5e6f70");
DisableTimerById¶
Turns a timer off, by its id (a name works too). Lasts until the timer is edited or Cuebot restarts. Stops your code with an error when there is no such timer.
void DisableTimerById(string timerId)
Gives back: Nothing.
Example
CPH.DisableTimerById("5f2c1a7e-3b4d-4e8f-9a10-2b3c4d5e6f70");
GetTimerState¶
Checks whether a timer is on right now, by its id or name. Stops your code with an error when there is no such timer.
bool GetTimerState(string timerId)
Gives back: true when the timer is on, otherwise false.
Example
bool on = CPH.GetTimerState("Hydrate Reminder");
CPH.LogInfo($"Timer on: {on}");
SetTimerInterval¶
Changes how often a timer fires, in seconds, and starts its countdown again. Lasts until the timer is edited or Cuebot restarts. Errors when there is no such timer.
void SetTimerInterval(string timerId, int interval)
Gives back: Nothing.
Example
CPH.SetTimerInterval("Hydrate Reminder", 900);
RegisterCustomTrigger¶
Adds a choice to the "Custom code event" trigger, so you can pick the event name from a list. Usually called from Init(). Categories are optional.
bool RegisterCustomTrigger(string triggerName, string eventName, string[]? categories = null)
Gives back: true when it worked. false when the event name is empty.
Example
bool ok = CPH.RegisterCustomTrigger("Confetti blast", "confetti", new[] { "Fun" });
CPH.LogInfo($"Registered: {ok}");
TriggerCodeEvent¶
Fires a custom event by name. Actions with a "Custom code event" trigger for it run. They get this action's variables (pass false to skip), or the values you hand over.
void TriggerCodeEvent(string eventName, bool useArgs = true)
void TriggerCodeEvent(string eventName, Dictionary<string, object?> args)
Gives back: Nothing.
Example
CPH.TriggerCodeEvent("confetti");
CPH.TriggerCodeEvent("confetti", new Dictionary<string, object> { ["amount"] = 50 });
WebsocketBroadcastJson¶
Sends JSON data to every program connected to Cuebot's WebSocket server (Streamer.bot API), as a General.Custom event. Text that is not valid JSON is sent as plain text.
void WebsocketBroadcastJson(string data)
Gives back: Nothing.
Example
CPH.WebsocketBroadcastJson("{\"scene\": \"Gameplay\"}");
WebsocketBroadcastString¶
Sends text to every program connected to Cuebot's WebSocket server (Streamer.bot API), as a General.Custom event.
void WebsocketBroadcastString(string data)
Gives back: Nothing.
Example
CPH.WebsocketBroadcastString("Round over!");
WebsocketConnect¶
Connects one of your WebSocket clients (set up on the Servers page). 0 is your first client. Errors when there is no such client.
void WebsocketConnect(int connection = 0)
Gives back: Nothing.
Example
CPH.WebsocketConnect(0);
WebsocketDisconnect¶
Disconnects one of your WebSocket clients (set up on the Servers page). 0 is your first client.
void WebsocketDisconnect(int connection = 0)
Gives back: Nothing.
Example
CPH.WebsocketDisconnect(0);
WebsocketIsConnected¶
Checks whether one of your WebSocket clients is connected. 0 is your first client.
bool WebsocketIsConnected(int connection = 0)
Gives back: true while it is connected, otherwise false.
Example
bool connected = CPH.WebsocketIsConnected(0);
CPH.LogInfo($"Client connected: {connected}");
WebsocketSend¶
Sends text through one of your WebSocket clients (set up on the Servers page). 0 is your first client.
void WebsocketSend(string data, int connection = 0)
Gives back: Nothing.
Example
CPH.WebsocketSend("{\"cmd\": \"flash\"}", 0);
WebsocketGetConnectionByName¶
Finds the number of one of your WebSocket clients by its name, to use with the other Websocket methods.
int WebsocketGetConnectionByName(string name)
Gives back: The client's number (0 is the first), or -1 when no client has that name.
Example
int client = CPH.WebsocketGetConnectionByName("Lights");
CPH.LogInfo($"Lights is client {client}");
WebsocketCustomServerStart¶
Starts one of your custom WebSocket servers (set up on the Servers page). 0 is your first server. Nothing changes if it is already running.
void WebsocketCustomServerStart(int connection = 0)
Gives back: Nothing.
Example
CPH.WebsocketCustomServerStart(0);
WebsocketCustomServerStop¶
Stops one of your custom WebSocket servers. 0 is your first server.
void WebsocketCustomServerStop(int connection = 0)
Gives back: Nothing.
Example
CPH.WebsocketCustomServerStop(0);
WebsocketCustomServerIsListening¶
Checks whether one of your custom WebSocket servers is running. 0 is your first server.
bool WebsocketCustomServerIsListening(int connection = 0)
Gives back: true while it is running, otherwise false.
Example
bool running = CPH.WebsocketCustomServerIsListening(0);
CPH.LogInfo($"Server running: {running}");
WebsocketCustomServerBroadcast¶
Sends text to everyone connected to one of your custom WebSocket servers, or to only one connection when you give its session id. 0 is your first server.
void WebsocketCustomServerBroadcast(string data, string? sessionId = null, int connection = 0)
Gives back: Nothing.
Example
CPH.WebsocketCustomServerBroadcast("Round over!", null, 0);
WebsocketCustomServerCloseSession¶
Closes one connection (session) on one of your custom WebSocket servers, by its session id.
void WebsocketCustomServerCloseSession(string sessionId, int connection = 0)
Gives back: Nothing.
Example
CPH.WebsocketCustomServerCloseSession("a1b2c3", 0);
WebsocketCustomServerCloseAllSessions¶
Closes every connection on one of your custom WebSocket servers. The server keeps running.
void WebsocketCustomServerCloseAllSessions(int connection = 0)
Gives back: Nothing.
Example
CPH.WebsocketCustomServerCloseAllSessions(0);
WebsocketCustomServerGetConnectionByName¶
Finds the number of one of your custom WebSocket servers by its name, to use with the other WebsocketCustomServer methods.
int WebsocketCustomServerGetConnectionByName(string name)
Gives back: The server's number (0 is the first), or -1 when no server has that name.
Example
int server = CPH.WebsocketCustomServerGetConnectionByName("Overlay");
CPH.LogInfo($"Overlay is server {server}");