Code Monkey home page Code Monkey logo

mitchellharrison / python-twitch-chatbot Goto Github PK

View Code? Open in Web Editor NEW
37.0 37.0 14.0 254 KB

A custom, 100% Python Twitch Chatbot that stores chat/viewership data in a PostgreSQL database.

Home Page: https://twitch.tv/MitchsWorkshop

Python 100.00%
analytics bot chat-bot data-analysis data-science database insights postgresql python-chat-application python-chatbot python-irc-bot python-postgresql python-twitch-api python-twitch-bot twitch twitch-api twitch-bot twitch-data twitch-irc

python-twitch-chatbot's People

Contributors

lrn-care avatar mitchellharrison avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

python-twitch-chatbot's Issues

sample creds.env file

A sample environment fiel would be useful, with all the requires key's with dummy values for ease of use

Fix !uptime command

The !uptime command is currently not functioning. The likely cause is incorrect SQL syntax. The command is not designed to give the stream's, but the bot's uptime. The logic looks sound, but there may be some syntax issues that could be quick to fix.

Store library of emotes by ID for referencing the emote tags sent by every message.

Twitch IRC sends emote tags with every message by emote ID. If we store these in a table, we can reference the id for emote analysis later. The internet says the legacy endpoint for getting all emotes should still work. It's reference is here. It also includes links to images as well, which is a lot of data but we can get those later if we need them.

Research improving bot response time/performance

Both the Streamelements bot that I used before and this bot are slow to respond if multiple commands are used in quick succession. I thought this was an issue with Twitch or IRC since the larger commercial products have the same issue. But some chatters have demonstrated their bots working much faster. Some kind of concurrency might be the issue. I'm looking into the following concurrency options:

  • Threading
  • Async IO
  • Multiprocesing

A primer on the subject is found here. If anyone has different ideas to improve performance, comments are welcome as ever!

Backfill followers table at startup

At the first startup, the followers table should be backfilled with existing followers. This will take some time, so there should be a check to see if the length matches total follower count. If not, delete the table and recreate. This should be helpful for getting total follower count.

Feature Request !FeatureRequest command

As a User, it might be awesome if typing something like.... !featurerequest add a featurerequest command that allows a user to define a new github issue with the feature request label on the chat bot project

Feature Request: !rank command

As a user, I should be able to type !rank and get my overall chat rank from the bot. It might also be fun to include sub ranks such as... !rank discord to see where I as a user rank in executing the !discord command.

!followage command doesn't work if tagging user with @

Currently, if a user wants to see the follow age of another user, they have to use the "!followage <username>" command. If they try to include a tag for that user (i.e. "@<username>"), the bot doesn't find them.

Thanks bug hunters WorthieGG and GanaXE

Refactor app to align with goals of the overarching project.

  • Chat bot should join a specified chat room.
  • Chat bot should parse incoming messages for commands /emotes.
  • Chat bot should send messages in response to various commands parsed.
  • Chat bot should log command usage events to a database.

Commands:

Admin

  • !addcommand - Adds a command to the database of known commands.
  • !editcommand - Edits an existing command within the database.
  • !delcommand - Deletes an existing command within the database.

User/text

  • !followage -
  • !uptime -
  • !commands - Lists the commands available within the database.
  • !rank -
  • !joke - Utilizes a third-party API to return a random joke.

baked in !so for shoutout of other users

an important feature for a lot of streamers is a ShoutOut command, it should be limited use, a user can't !so themselves but the streamer should define what level of user can use it - all - vip - mod

Convert database to PostgreSQL from SQLite to (hopefully) increase bot performance.

The following steps point me in the direction of the database as the culprit responsible for the bot being slow to respond to some commands as listed in issue #22. Printing every message to console confirmed that every message is being received without fail, and the !joke and !poem commands that rely on external API's work as intended. That tells me that the database itself is the issue. Messages are being logged fine, but the commands that pull from the database cause issues.

I'm hoping that switching from SQLite to Postgres will help with database performance enough to make the bot as responsive with database commands as the !poem and !joke commands are.

Restructure app to use SQLalchemy ORM

After a discussion with the discord server, I'm going to attempt to stick with SQLite for ease of end use. But writing queries as strings is for the birds, so I am going to implement SQLalchemy using a separate models.py file and maybe a database.py file as well.

Add command-specific leaderboard to !rank

Once !rank is implemented, it would be great to give users the ability to get their rank for a specific command (i.e. !rank !discord). This should be agnostic to the use of the second exclamation mark. So !rank discord and !rank !discord should function identically.

Build a per-minute viewership tracker

The script should, while the stream is live, get the following information from Twitch:

  • Stream Title
  • Viewers
  • Category
  • Language

As well as the current time. The script should stop when the stream goes offline

Parse and store emote use in chat.

I'd like to implement emote tracking into the bot. For both streamer-specific and twitch-wide emotes. This should be stored in a database table, but I'm unsure how to do it. Options are:

  • One row in the table per emote, and simply increment.
  • Add a column to the chat_messages table to list which emotes were used per message.

The former seems like I would be losing some granularity as far as who is using the emotes and which streams see the most emote use. But I'm unclear on the implementation of the latter. I would have to pass something like a list into a single column and that would make future analysis much more difficult and slower.

If anyone has insights, feel free to drop them!

Notifications don't come through EventSub callbacks.

app.py successfully creates EventSub subscriptions. The app prints them to the terminal and all of the desired ones are shown. But after the webhooks are established, no notifications appear. No clue on this one so I'm tagging it as "help wanted," but I'll do some digging and see what I find.

Current subscriptions:

  • Stream goes online
  • Stream goes offline
  • Stream info is updated (title, etc.)
  • Channel points are redeemed

All show as established and authenticated, but ngrok doesn't even get a PUT request from Twitch after the initial creation of the webhook (even though it does during creation and authentication).

Check mod status and pass to commands

Some commands should be useable by admins. We will have to pull mod status from each message. They could be stored alongside each message in booleans like is_mod in the chat_messages table. Then we could pass that mod status to each execute() method and run certain commands or not based on that status.

Put postgres login credentials into credentials.env

Right now, the default postgres username is being used with a password of "password". A user should be able to put their postgres username and password into the credentials file to be read automatically at runtime.

Implement key-value store for tokens

Several scripts are going to need access to several tokens that need to change in real-time in case they are revoked. So we are going to store them in our database for now. There should be a module to interface with this token store with methods to refresh tokens from anywhere in the environment.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.