Table of Contents
Redis
The Redis database is used as a cache and to store state of both the bot and chatters.
Here's a list of keys that keep track of stream and bot state:
| NAME | FUNCTION | STATE |
|---|---|---|
anivmessages |
Store last aniv and aneev messages in JSON format | Always exists |
rouletteCount |
How many bullets have been fired with the roulette command | Always exists |
timeoutStacking |
Stores if timeout stacking is on | Exists if true, doesn't if false |
streamIsLive |
Stores if the stream is live | Exists if true, doesn't if false |
disabledcommands |
Stores a set of disabled commands and items | Each string in the set represents a command/item |
disabledcheers |
Stores a set of disabled cheers | Each string in the set represents a cheer |
To act as a cache, redis stores the userid, displayname and username.
The expiration is 30 minutes.
When creating a user object, the id gets stored in userlookup:{username}, the displayname in user:{userid}:displayName and the username in user:{userid}:username.
When looking up an id, you can see if they exist in userlookup, and when getting the displayname, you can use user:123:displayName.
This is all done by the User class.
Besides caching user data, redis has a lot more important information about users:
These are all stored in user:{id}:
| NAME | FUNCTION | STATE |
|---|---|---|
admin |
Is the user an admin | Exists if true, doesn't if false |
bot |
Is the user a bot | Exists if true, doesn't if false |
haschatted |
Has the user chatted in chat before | Exists if true, doesn't if false |
invulnerable |
Is the user invulnerable | Exists if true, doesn't if false |
mod |
Is the user a moderator in the channel | Exists if true, doesn't if false |
welcomemessageid |
Id of welcome message. So this message can be deleted after a ban | Exists for the first 10 minutes |
subbed |
Status of the subscription of the user | Exists if true, doesn't if false. Contains 1 for tier 1, 2 for tier 2 and 3 for tier 3 |
timeout |
Is the user timed out or banned | Exists if true, doesn't if false. Has an expiration set for when the user is freed, or none if it's a permanent-ban |
remod |
Does this user get mod after timeout is over | Exists if true, doesn't if false |
greedy |
Is the user greedy with lootboxes | Exists if true, doesn't if false |
vulnerable |
Is the user vulnerable to random timeouts (grenade, tnt, silverbullet) | Exists if true, doesn't if false |
itemlock |
Prevents the user from using and giving items and qbucks | Exists if true, doesn't if false |
haschattedthisstream |
The user has chatted in the current livestream. All will be cleared after you go live | Exists if true, doesn't if false |
welcomemessagetext |
The message the user has set as their welcome message. No expiration | If this exists, will send this message on the first message for a stream |
Note that all of these flags can or do have an expiration. Like the timeout flag, deletes itself when the user is freed
The haschatted flag only exists because twitch Eventsub subscription channel.chat.message doesn't tell you if the message is from a brand new chatter, unlike the soon-to-be-deprecated IRC API. There is an open request here