BlushyFace.Core.Twitch.Chat demo

This is the code snippet of the blog post here:

Twitch lib updated to .NET Core

Compiled debug build can be found here: files.blushyface.com/BlushyFace.Core.Tests/

files.blushyface.com/BlushyFace.Core.Tests/Twitch/Chat/Program.cs

using System;
using BlushyFace.Core.Twitch.Chat;

namespace BlushyFace.Core.Tests.Twitch.Chat
{
    class Program
    {
        private static Client _client;
        private static Client _client2;

        private static bool ConnectClient1 = false;
        private static bool ConnectClient2 = true;

        static void Main(string[] args)
        {
            var userName = "";
            var token = "";

            if (ConnectClient1)
            {
                _client = new Client
                {
                    RegisterCapRequestCommands = true,
                    RegisterCapRequestMembership = true,
                    RegisterCapRequestTags = true
                };

                _client.OnPrivMsg += Events.ClientOnPrivMsg;
                _client.OnNotice += Events.ClientOnNotice;
                _client.OnClearChat += Events.ClientOnClearChat;
                _client.OnClearMsg += Events.ClientOnClearMsg;
                _client.OnGlobalUserState += Events.ClientOnGlobalUserState;
                _client.OnHostTarget += (o, e) => Events.ClientOnHostTarget(o, e, _client.Commands);
                _client.OnRoomState += Events.ClientOnRoomState;
                _client.OnUserNotice += Events.ClientOnUserNotice;
                _client.OnUserState += Events.ClientOnUserState;
                _client.OnMode += Events.ClientOnMode;
                _client.OnNames += Events.ClientOnNames;
                _client.OnCap += Events.ClientOnCap;
                _client.OnNumeric += Events.ClientOnNumeric;
                _client.OnJoin += Events.ClientOnJoin;
                _client.OnPart += Events.ClientOnPart;

                _client.OnRitual += Events.ClientOnRitual;
                _client.OnBits += Events.ClientOnBits;
                _client.OnSubscription += Events.ClientOnSubscription;
                _client.OnRaid += Events.ClientOnRaid;

                _client.Connect(userName, token);
                _client.Commands.Join("blushyface");

                // usage of various commands
                // _client.SendMessage("blushyface", "Hello!");
                // _client.Commands.Mods("blushyface");
                // _client.Commands.Host("blushyface","blushyfacebot");
                // _client.Commands.Whisper("blushyface","Hello hello is a whisper.");
            }

            // Note: both clients share the same event handlers.
            if (ConnectClient2)
            {
                _client2 = new Client
                {
                    RegisterCapRequestCommands = true,
                    RegisterCapRequestMembership = true,
                    RegisterCapRequestTags = true
                };

                _client2.OnPrivMsg += Events.ClientOnPrivMsg;
                _client2.OnNotice += Events.ClientOnNotice;
                _client2.OnClearChat += Events.ClientOnClearChat;
                _client2.OnClearMsg += Events.ClientOnClearMsg;
                _client2.OnGlobalUserState += Events.ClientOnGlobalUserState;
                _client2.OnHostTarget += (o, e) => Events.ClientOnHostTarget(o, e, _client2.Commands);
                _client2.OnRoomState += Events.ClientOnRoomState;
                _client2.OnUserNotice += Events.ClientOnUserNotice;
                _client2.OnUserState += Events.ClientOnUserState;
                _client2.OnMode += Events.ClientOnMode;
                _client2.OnNames += Events.ClientOnNames;
                _client2.OnCap += Events.ClientOnCap;
                _client2.OnNumeric += Events.ClientOnNumeric;
                _client2.OnJoin += Events.ClientOnJoin;
                _client2.OnPart += Events.ClientOnPart;

                _client2.OnRitual += Events.ClientOnRitual;
                _client2.OnBits += Events.ClientOnBits;
                _client2.OnSubscription += Events.ClientOnSubscription;
                _client2.OnWhisper += Events.ClientOnWhisper;
                _client2.OnRaid += Events.ClientOnRaid;

                _client2.Connect();
                _client2.Commands.Join("blushyface");
            }

            Console.Read();
        }
    }
}

 

files.blushyface.com/BlushyFace.Core.Tests/Twitch/Chat/Events.cs

using BlushyFace.Core.Twitch.Chat.Commands;
using BlushyFace.Core.Twitch.Chat.Events;
using BlushyFace.Core.Twitch.Chat.Events.Custom;
using BlushyFace.Core.Twitch.Chat.Helpers;

namespace BlushyFace.Core.Tests.Twitch.Chat
{
    static class Events
    {
        internal static void ClientOnRaid(object sender, Raid e)
        {
            Utilities.WriteDebugConsole($"[RAID] ");
        }

        internal static void ClientOnNumeric(object sender, Numeric e)
        {
            Utilities.WriteDebugConsole($"[NUMERIC] {e.SystemMessage}");
        }

        internal static void ClientOnCap(object sender, Cap e)
        {
            Utilities.WriteDebugConsole($"[CAP] {e.SystemMessage}");
        }

        internal static void ClientOnWhisper(object sender, Whisper e)
        {
            Utilities.WriteDebugConsole($"[WHISPER] {e.From} {e.Message}");
        }

        internal static void ClientOnSubscription(object sender, Subscription e)
        {
            Utilities.WriteDebugConsole($"[SUBSCRIPTION] {e.Channel} {e.SystemMessage} {e.UserMessage}");
        }

        internal static void ClientOnNames(object sender, Names e)
        {
            Utilities.WriteDebugConsole($"[NAMES] {e.Channel}");
        }

        internal static void ClientOnMode(object sender, Mode e)
        {
            Utilities.WriteDebugConsole($"[MODE] {e.Channel} {e.UserName}");
        }

        internal static void ClientOnUserState(object sender, UserState e)
        {
            Utilities.WriteDebugConsole($"[USERSTATE] {e.Channel} {e.UserName}");
        }

        internal static void ClientOnRoomState(object sender, RoomState e)
        {
            Utilities.WriteDebugConsole($"[ROOMSTATE] {e.Channel} Slow: {e.SlowModeDuration} Emote: {e.EmoteOnly} Followers: {e.FollowersOnly} R9K: {e.R9kOnly} Rituals: {e.Rituals} Subs: {e.SubsOnly}");
        }

        internal static void ClientOnHostTarget(object sender, HostTarget e, Commands command)
        {
            Utilities.WriteDebugConsole($"[HOSTTARGET] {e.Channel} hosting: {e.ChannelBeingHosted}");

            if (e.ChannelBeingHosted.Equals("")) return; // the channel that is getting hosted shouldn't be empty but check it either way.
            command.Join(e.ChannelBeingHosted);
        }

        internal static void ClientOnGlobalUserState(object sender, GlobalUserState e)
        {
            Utilities.WriteDebugConsole($"[GLOBALUSERSTATE] {e.Tags.Tags["display-name"]}");
        }

        internal static void ClientOnClearChat(object sender, ClearChat e)
        {
            var message = $"{e.Channel} {e.UserName} " + (e.Duration.Equals("") ? e.UserName.Equals("") ? "" : "Permanently banned" : $"banned for {e.Duration} seconds");
            Utilities.WriteDebugConsole($"[CLEARCHAT] {message}");
        }

        internal static void ClientOnClearMsg(object sender, ClearMsg e)
        {
            Utilities.WriteDebugConsole($"[CLEARCMSG] {e.UserName} {e.MessageId}");
        }

        internal static void ClientOnRitual(object sender, Ritual e)
        {
            Utilities.WriteDebugConsole($"[RITUAL] {e.Channel} {e.UserName} {e.UserMessage} {e.SystemMessage}");
        }

        internal static void ClientOnBits(object sender, Bits e)
        {
            Utilities.WriteDebugConsole($"[BITS] {e.Channel} {e.UserName} just cheered with {e.Amount} bits! {e.UserMessage}");
        }

        internal static void ClientOnNotice(object sender, Notice e)
        {
            Utilities.WriteDebugConsole($"[NOTICE] {e.Channel} {e.SystemMessage}");
        }

        internal static void ClientOnUserNotice(object sender, UserNotice e)
        {
            Utilities.WriteDebugConsole($"[USERNOTICE] {e.Channel} {e.SystemMessage} {e.UserMessage}");
        }

        internal static void ClientOnPrivMsg(object sender, PrivMsg e)
        {
            var message = (e.Channel != string.Empty ? e.Channel + " " : "") + $"{e.UserName}: {e.UserMessage}";
            Utilities.WriteDebugConsole($"[PRIVMSG] {message}");
        }

        internal static void ClientOnJoin(object sender, Join e)
        {
            Utilities.WriteDebugConsole($"[JOIN] {e.Channel} {e.UserName}");
        }
        internal static void ClientOnPart(object sender, Part e)
        {
            Utilities.WriteDebugConsole($"[PART] {e.Channel} {e.UserName}");
        }
    }
}

 

Herrow, I'm BlushyFace and this is where you can read about Blushies. I hope you enjoy my silly content as much as I have fun creating!
Consider a tip if you like my content, thank you for supporting my content!

PS: Due to current and unforeseen circumstances (lockdown & reduced income due layoffs) I'm currently open for commissions!

Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Site Footer

@Blushyface | All Rights Reserved - Blushyface.com