Bare with me I am fairly new to IRC, APIs and chat bots.
I want to pull chat for a chat bot I’m building, but I’m not sure how to do it through the API (or if I can).
I’ve seen old posts saying to use tmi.twitch.tv or irc.twitch.tv but these are either unofficial or poorly implemented (having to regex the chat message out of a JSON puke is not ideal) and a more elegant JSON format would be better.
I have scripts for things like Slots or a Dice command but I want to implement them through the API and patching it in with the unofficial, and poorly documented IRC systems is not ideal. Anyone have any ideas or am I just misunderstanding how this all works and asking a dumb noob question here?
(writing in Python as its the language I am most comfortable with.)
Just curious if there are plans to implement chat through the API? It’s a little frustrating to have to use two methods of getting data from twitch in one program. If I want my bot to be able to see certain aspects of my channel, not only do I need to sit in IRC to wait for commands, but I also need to poll the API for data as well. Makes it a little more complex than desired.
The API is called TMI which is Twitch Messaging Interface which is an API, that API provides an IRC “compatible” interface.
There are no plans to put it in Helix as a endpoint as that doesn’t really make sense for that much real time data/stream. Of course I don’t work for Twitch and that plan could change.
Oh ok that makes sense. At the moment I need to regex a string to get Usernames, the message and the channel it was sent in. Is there a possibility I’m doing this wrong and there is an easier way where all this data is separate from one another and accessible by parsing a JSON object?
I am already using a library for my Bot, but my chat client I want to integrate does not. I suppose I should look into converting it to use the IRC library
In Conclusion, I’m dumb.
The IRC library turned my mess into exactly what I wanted (JSON that can be parsed for data). Thank you so much for your help and insight and sorry I asked such a silly question.
Snippet from my code:
def on_pubmsg(self, c, e):
# If a chat message starts with an exclamation point, try to run it as a command
if e.arguments[0][:1] == '!':
cmd = e.arguments[0].split(' ')[0][1:]
print('Received command: ' + cmd)
self.do_command(e, cmd)
# If it is any other chat message, print the username and message to the console
else:
# Get message
message = e.arguments[0]
# Get Username from tags
username = e.tags[2]['value']
print(username + ': ' + message)
return