Carson Kompon Carson Kompon Library update 1y ago

Twitch API

A stupid simple Library that allows you to subscribe to events from Twitch Chat, with additional metadata for users/messages.

hard_drive 0 MB folder 26 files build Engine v17 history Last update 638d ago
open_in_new View on sbox.game

About This Package

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<TwitchChatMessage> 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.

Media (2)

Twitch API - Thumbnail 2
No usage statistics available
This package may be new or not widely used yet. Usage data becomes available as more users install and play with the package.
Package ID: carsonk.twitchapi
Created: 2024-10-10 02:52 UTC
Updated: 2024-10-10 02:52 UTC
Type: library
Public: Yes
Version: 74431
files: 26
Size: 0.1 MB
Engine Version: 17
Asset Version ID: 74431
Version Created: 2024-10-10 02:52 UTC
Hash: -8978935434540897752
Manifest: Open manifest
Cs Proj Name:
Resources:
Code Package References:
new_releases Latest Update Oct 10, 2024
Changes on 2024-10-10
tag v74431 folder 26 files hard_drive 0.1 MB build Engine v17
74431 Oct 10, 2024
Changes on 2024-10-10
folder 26 files hard_drive 145.43 KB build Engine v17