Skip to content

Instantly share code, notes, and snippets.

@EsteveSegura
Created March 9, 2020 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EsteveSegura/a6813e3c2f09d1d8fc6374d72f8d5b99 to your computer and use it in GitHub Desktop.
Save EsteveSegura/a6813e3c2f09d1d8fc6374d72f8d5b99 to your computer and use it in GitHub Desktop.
Unity + twitch chat.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.ComponentModel;
using System.Net.Sockets;
using System.IO;
public class TwitchIntegration : MonoBehaviour{
public Ball player;
private TcpClient twitchClient;
private StreamReader reader;
private StreamWriter writer;
public string username;
public string password;
public string channel;
void Start(){
player = GameObject.FindWithTag("Player").GetComponent<Ball>();
Connect();
}
void Update(){
if(!twitchClient.Connected){
Connect();
}
ReadChat();
}
private void Connect(){
twitchClient = new TcpClient("irc.chat.twitch.tv", 6667);
reader = new StreamReader(twitchClient.GetStream());
writer = new StreamWriter(twitchClient.GetStream());
writer.WriteLine("PASS "+password);
writer.WriteLine("NICK "+username);
writer.WriteLine("USER "+username+" 8 * :"+username);
writer.WriteLine("JOIN #"+ channel);
writer.Flush();
}
private void ReadChat(){
if(twitchClient.Available > 0){
string message = reader.ReadLine();
if(message.Contains(":!jump")){
player.Jump();
}
if(message.Contains(":!forward")){
player.Forward();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment