Console Twitch IRC Chat View

Console Twitch IRC Chat View


Friday, 28 May, 2021 All posts

As a Twitch viewer, I often run into the problem of deciding whether or not to display chat. I enjoy reading the chat when something interesting is going on, but the chat view shrinks my full screen view of the content and takes some of the immersion out for me. Since I have 2 monitors, I often would wish that I could detatch the chat to be able to have full screen on one monitor and the chat on another. Because of this I decided to do something about it.

Version 1: node.js

Originally I created a desktop application using the javascript framework Electron. The build looked like this:

Original App View
The source code for this project can be found here I used a javascript library tmi.js that would connect to an IRC client and read twitch chat messages. Each chat message would then be rendered into html elements and displayed on the dom for me to view. This was nice but ended up using lots of resources as soon my dom would get too large and I would have to garbage collect old chats.

I decided I wanted something more lightweight, and I also wanted to tap into the IRC client myself without using a prebuilt framework. Since I have more knowledge in python, I decided to rewrite the application as a python command line tool instead.

Version 2: Python

I decided to program this project using only websockets and tap into the twitch irc client myself to handle the messages. Twitch has great documentation on how to connect to an IRC client here. I went with a command line interface design that allows me to hop between different channels without having to restart my program.

my code for the project is public and can be found here.

In my program I decided to create 2 classes:
- IRC Bot
- Logger

IRC Bot class

This file held the logic for connecting to the correct IRC client using websockets. It also handles all incomming messages and how the messages will be displayed as well as reconnecting in the case of a disconnection to the server. As the code is pretty long for this file, I wont be adding images of it, instead you can view the file.

Logger

I thought it would be neat to add the functionality of logging all chat messages if the user wanted to. I created a simple logging class that would add each chat message and some data about it such as date,timestamp, channel to a list. When a user would decide to leave a twitch channel, if logging was enabled, the Logger would either append the data to a csv or create a new csv file for the streamers name. This allowed me to create cool datasets on twitch chat for the potential to do some data analysis on it in the future.

The code for this class was small and could have probably been added to the IRC_Bot file but I wanted to keep functionality seperate. Logging Code

An example of accessing the dataset: Accessing Chat Data

Python Twitch IRC Demo

The tool has a simple interface that allows me to hop around different chats without having to restart my code. The interface is simple and to the point, exactly how I wanted it. Chat Demo

Conclusion

I am satisfied with how this program turned out. This is something that I use everytime I use twitch at my desk as it solves the problem I originally had and does everything I wanted it to do. This program taught me more about IRC as well as using web sockets to communicate between clients and servers.