HectorPulido / Unity-twitch-chat-link

Perfect api to connect unity and twitch chat Easy

Home Page:https://www.youtube.com/watch?v=wMvDKGSOsgA

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unity Twitch Chat

This is a handmade library to connect Unity with Twich Chat Api, easy to use and easy to understand

Test twitch chat

WHY (MOTIVATION)

Banner
This tutorial was made for Hector Pulido for his youtube channel
https://www.youtube.com/c/HectorAndresPulidoPalmar
And his Twitch Channel
https://goo.gl/otWsda (Hector_Pulido_)

Features

  • Commands support
  • Custom twitch events support
  • Sub, resub, bits, raid, etc
  • On init event, Disconnect event, Etc
  • Current chatter list

TODO

  • More Examples of use

How to use

  1. First of anything make sure you have a twitch acount
  2. You will need a OAUTH Key from Twitch https://twitchapps.com/tmi/
  3. Just Code what do you need just like this
  4. List of tags https://dev.twitch.tv/docs/irc/tags/

Rotating cube

This example switch a cube rotation depending of the Twitch chat and the commands !stop and !continue

    using TwitchBot;
    using CielaSpike; //You have to import this two namespaces
    public class ConnectTest : UnityBot //You have to inherit from UnityBot
    {
        public Transform cube;
        public bool rotating;
        public int maxRetry;

        void Start()
        {

            commands = new Dictionary<string, BotCommand>();

            //Command bots has 2 Arguments, the first one is an array of arguments
            //The other one it's the message it self
            commands.Add("!stop", new BotCommand((string[] args, Message message) =>
            {
                Debug.Log($"{message.username} ha ejecutado el comando !stop");
                rotating = false;
            }));

            commands.Add("!continue", new BotCommand((string[] args, Message message) =>
            {
                Debug.Log($"{message.username} ha ejecutado el comando !continue");
                if (args.Length > 1)
                {
                    Debug.Log($"Y el primer comando es {args[1]}");
                }
                rotating = true;
            }));

            whenNewMessage += (Message message) =>
            {
                Debug.Log($"{message.username}: {message.message}");
            };

            whenNewSystemMessage += (string message) =>
            {
                Debug.Log($"System: {message}");
            };

            whenDisconnect += () =>
            {
                Debug.Log("Desconexion");
            };

            whenStart += () =>
            {
                Debug.Log("Conexion");
            };

            whenNewChater += (string username) =>
            {
                Debug.Log($"{username}, bienvenido al stream!");
                SendMessageToChat($"{username}, bienvenido al stream!");
            };

            whenSub += (Message message) =>
            {
                Debug.Log($"{message.username} Muchas gracias por esa subscripcion");
                SendMessageToChat($"{message.username} Muchas gracias por esa subscripcion");
            };

            // You have to initializate the bot with this command
            this.StartCoroutineAsync(StartConnection(maxRetry));
        }

        private void Update()
        {
            // Game logic
            if(rotating)
                cube.localEulerAngles += new Vector3(0, 0, 360) * Time.deltaTime;
        }
    }

License

  • This project uses Thread Ninja
  • This project uses Twitch Api
  • Everything else is 100% handcrafted for me and MIT license

Let's connect 😋

Hector's LinkedIn     Hector's Twitter     Hector's Twitch     Hector's Youtube    

About

Perfect api to connect unity and twitch chat Easy

https://www.youtube.com/watch?v=wMvDKGSOsgA

License:MIT License


Languages

Language:C# 100.0%