A socket api for Twitch IRC servers.
To use this bot, you must have Python 3.6+ installed. Run pip install -r requirements.txt
to install all required modules.
To allow for use with Twitch, you must edit config.py
to contain all your bot info. Obtaining this information is outlined below.
To create a bot with which you may interface with Twitch, you must do the following things:
-
Create a new Twitch account under the bot's name.
-
Head to the Twitch Chat OAuth Password Generator and click generate. Ensure that you are logged in as the bot, then click authorize.
-
You should now see an OAuth token that looks something like this:
oauth:1k4j4njnuh2o41jo1j4jjj11io23jo
Save this token somewhere secure, as it acts as a password to your bot account.
-
You are now ready to fill in the
config.py
file.USER = Your bot's Twitch account name
PASS = Your bot's OAuth token
CHAN = The Twitch channel you want the bot to chat in
PREFIX = Any single character you wish to signify a command in chat (ex: !)
NOTE: Your Twitch bot must be verified to make full use of this API
You can also set a value for LOGLEVEL: - DEBUG: Records pretty much all bot connection information. - INFO: Records all command executions. - ERROR: Records connection losses. - CRITICAL: Records bot crashes.
Note: The default level is INFO. All levels also record those below them.
This script interacts with a number of .json
files to perform its functions. Below are the descriptions for each file.
This file holds the default poll used when the user runs >poll create auto (read Commands below for more information.) All polls must take the form of a dictionary with:
- title: A string for the name of the poll
- choices: A list of strings for options in the poll
- random: A boolean to allow for randomize votes
This file holds a list of bot admins. This list must be edited manually, and by default is empty. If you want to give someone full access to the bot, add their Twitch username to this list.
This file contains a dictionary of messages to send periodically. The keys are messages, and their values contain the number of minutes between messages, and a dummy variable to track the last time the message was sent. This should always be zero. The file can be edited manually, or through a bot command.
Note: These periodic messages are only sent when an event in the chat is detected. This is likely a message, or the automated PING Twitch sends all clients every five minutes. So, times are not exact.
This file contains a dictionary of messages the bot should reply to. The key is the message to look for in chat, and the value is what the bot says in response. This file can be edited manually, or through a command.
This file contains the names of command functions as keys, and their chat aliases as listed values. If you wish to add a command alias, simply add it to one of the lists manually.
Similar to auto_replies.json
, this makes the bot reply to single words, but only if they are entered as a command (prepended with the prefix).
It can be edited through commands or manually.
The bot comes with a number of commands.
Examples of the commands will use $
as the prefix.
Used for testing if the bot is present in the chat.
User: $ping
Bot: Pong!
Disconnects the bot from the IRC server and shuts the script down.
User: $disconnect
Bot disconnects, and is no longer running.
The bot will repeat whatever is said to it.
User: $echo I am a cool bot!
Bot: I am a cool bot!
Create/Start, End, or Display a poll in chat.
Create:
User: $poll create auto
Bot sends the poll display string in chat.
OR
User: $poll create {"title": "Pick the game I'm going to play!","choices": ["Game X","Game Y","Game Z"],"random": false}
Bot sends the poll display string in chat.
End:
User: $poll end
Bot sends the poll results in chat.
Display:
User: $poll display
Bot sends the poll display string in chat.
Vote for an option in the poll.
User: $vote 3
If there are at least three options on the poll, the vote is recorded.
Create, Delete, or Display automated replies.
Create:
User: $reply create This bot sucks! | No u
Later...
User: This bot sucks!
Bot: No u
Delete:
Assume This bot rocks!
is another automated reply
User: $reply delete This bot sucks! | This bot rocks!
Later...
User: This bot sucks!
Bot does not reply.
User: This bot rocks!
Bot does not reply.
Display:
User: $reply display
Bot sends all reply: response objects in a private message.
Allows the creation, deletion, and display of scheduled automated messages.
Create:
User: $schedule create Remember to drink water! | 5
Five minutes later...
Bot: Remember to drink water!
Delete:
User: $schedule delete Remember to drink water!
Five minutes later...
Bot does not send automated message.
Display:
User: $schedule display
Bot privately messages automated message dictionary.
Create, delete, and display custom commands.
Create:
User: $command create setup Computer, keyboard, and mouse.
Later...
User: $setup
Bot: Computer, keyboard, and mouse.
Delete:
User: $command delete setup
Later...
User: $setup
Bot does not reply.
Display:
User: $command display
Bot sends commands and replies privately to the user.