Twitcham ~ Telegram bot for Twitch subscribers

This bot is able to check if a Telegram user is a subscriber in a Twitch channel. However, the repository is no longer maintained and you can just start from this to build your personal bot. The quality of code is not very good, since I wrote it in one-two days one year ago.

Dependencies

The bot uses MongoDB as database with the PyMongo library. The external libraries needed are in the requirements.txt file while the others are installed with Anaconda by default.

Folders

As you can see, there are two folders: bot and automatic_check. In the first folder there are all the files needed to run the bot, while in the second one there are the files needed to run the auto-checker for the bot.

Simple setup

I recommend to use some process manager like pm2 in order to avoid any problem in case of failure. In order to run the code you need to setup some variables:

  • bot.py: replace tokenBotId with your development token bot and production token bot (line 69), replace clientID with your client id provided by Twitch (line 70), replace the parameters for the database connection (line 71);
  • commands.py: replace clientID with your client id provided by Twitch (line 521), replace clientSecret with your client secret provided by Twitch (line 522);
  • messages.py: replace the same as commands.py file at lines: 45, 46;
  • sub_checker.py: replace the same as commands.py file at lines: 37, 38, 98. At lines 212, 328, 337 and 340 replace botIdAndToken with your bot id and token (as reported in Telegram APIs);
  • main.py: replace MongoDB connection parameters with yours.

Just run python bot.py and you will se your bot running. Run python main.py to run the auto checker.

Database table

The database IS NOT OPTIMIZED. This is an example of data:

{
    "_id": {
        "$oid": "5ff09030cd55d6d9f378d460"
    },
    "groups": ["list of groups id"],
    "twitch_username": "user_twitch_username",
    "twitch_id": "user_twitch_id",
    "last_access_ts": 1632839210,
    "last_access": "2021-9-28 15:26:50",
    "telegram_id": "telegram_id as integer",
    "verified_date": "2021-1-2 16:24:32",
    "verified_ts": 1609601072,
    "group_users": {
        "chat_id": [{
            "telegram_id": "telegram_id as integer",
            "twitch_id": "twitch_id"
        }],
    },
    "group_user": [],
    "access_token": "access_token_twitch",
    "refresh_token": "refresh_token_twitch",
    "registered_access": "2021-1-2 16:24:42",
    "invitationLink": "used only with single group and not multigroup",
    "telegram_group_active": true,
    "telegram_group_id": {
        "group id": {
            "invitationLink": "group invitation link",
            "isActive": true,
            "automaticCheck": true
        },
    },
    "groups_users_to_kick": {}
}

The group_users column is a column with all the groups registered by the user and each key as a value a list with all users' twitch id and telegram id.

Saving users in database

As you can see, at this, there is a redirect to a page. In this case I pass the telegram id to that page and then I store it in the database. You can use any language to do that.