Twitch API
by
Carson Kompon
| Summary | A stupid simple Library that allows you to subscribe to events from Twitch Chat, with additional metadata for users/messages. |
|---|---|
| Description |
Twitch API A stupid simple Library that allows you to subscribe to events from Twitch Chat, with additional metadata such as Badges, Emotes, whether or not a user is Moderator, Subscriber, Turbo, ect. Here's how you do suff via code: using TwitchAPI; public class MyComponent : Component { TwitchChatConnection TwitchChat; List MessageHistory { get; set; } protected override void OnEnabled() { // Connect to the Chat TwitchChat = new TwitchChatConnection("CarsonKompon"); // Subscribe to the different events TwitchChat.OnMessageReceieved += OnMessageReceieved; TwitchChat.OnMessagesCleared += OnMessagesCleared; } protected override void OnDisabled() { if(TwitchChat is null) return; // Disconnect/Dispose of the connection TwitchChat?.Dispose(); // Un-subscribe from the events TwitchChat.OnMessageReceieved -= OnMessageReceieved; TwitchChat.OnMessagesCleared -= OnMessagesCleared; } void OnMessageReceived(TwitchChatMessage message) { // Add the message to the message history MessageHistory.Add(message); // "!test" command that only works for Moderators and subs if(message.Message == "!test" && (message.User.IsModerator || message.User.IsSubscriber)) { Log.Info("Testing!"); return; } // Otherwise, print the message to the console Log.Info($"{message.Username}: {message.Message}"); } void OnMessagesCleared() { // Clear the message history MessageHistory.Clear(); } } There's also a TwitchComponent included which can be used for simple ActionGraph-based solutions.Twitch API
A stupid simple Library that allows you to subscribe to events from Twitch Chat, with additional metadata such as Badges, Emotes, whether or not a user is Moderator, Subscriber, Turbo, ect.
Here's how you do suff via code:
using TwitchAPI;
public class MyComponent : Component
{
TwitchChatConnection TwitchChat;
List MessageHistory { get; set; }
protected override void OnEnabled()
{
// Connect to the Chat
TwitchChat = new TwitchChatConnection("CarsonKompon");
// Subscribe to the different events
TwitchChat.OnMessageReceieved += OnMessageReceieved;
TwitchChat.OnMessagesCleared += OnMessagesCleared;
}
protected override void OnDisabled()
{
if(TwitchChat is null) return;
// Disconnect/Dispose of the connection
TwitchChat?.Dispose();
// Un-subscribe from the events
TwitchChat.OnMessageReceieved -= OnMessageReceieved;
TwitchChat.OnMessagesCleared -= OnMessagesCleared;
}
void OnMessageReceived(TwitchChatMessage message)
{
// Add the message to the message history
MessageHistory.Add(message);
// "!test" command that only works for Moderators and subs
if(message.Message == "!test" && (message.User.IsModerator || message.User.IsSubscriber))
{
Log.Info("Testing!");
return;
}
// Otherwise, print the message to the console
Log.Info($"{message.Username}: {message.Message}");
}
void OnMessagesCleared()
{
// Clear the message history
MessageHistory.Clear();
}
}
There's also a TwitchComponent included which can be used for simple ActionGraph-based solutions.
|
| Votes | 👍0 👎0 ❤️0 |
| Error Rate | 0% |
| Data | {} |
| Version | Created | Size (modified) | Files | Changes |
|---|---|---|---|---|
| 74431 | 145.4 KB | 26 +26 | Changes on 2024-10-10 |
Loading history…