Giter VIP home page Giter VIP logo

marcdonald / twitch-spotify-request-bot Goto Github PK

View Code? Open in Web Editor NEW
32.0 4.0 23.0 688 KB

This is a bot that listens to the chat of a given Twitch stream for messages with a Spotify song link in them and then adds that song to a playlist and/or your queue.

Home Page: https://www.marcdonald.com

License: MIT License

TypeScript 93.27% Shell 5.84% JavaScript 0.89%
twitch-bot twitch twitchtv twitch-tv spotify spotify-api spotify-web-api spotify-playlist livestream songs

twitch-spotify-request-bot's Introduction

Twitch Spotify Request Bot

What is this?

This is a bot that listens to the chat of a given Twitch stream for messages with a Spotify song link in them and then adds that song to a playlist and/or your queue. The Spotify link must be at the start of the message in order to be picked up.

✔️ Message that WOULD be picked up:

!prefix https://open.spotify.com/track/4uLU6hMCjMI75M1A2tKUQC?si=x-_FFgqBRB20mzW_lM7kDQ pls play this, it's a bop

❌ Message that WOULD NOT be picked up:

!prefix this is a bop can you please play this https://open.spotify.com/track/4uLU6hMCjMI75M1A2tKUQC?si=x-_FFgqBRB20mzW_lM7kDQ

Setup

Prerequisites

  • Some basic programming knowledge (running terminal commands and editing .env files)
  • Node (developed and tested on 18 - your mileage may vary on other versions)
  • A Spotify account
  • A GitHub Personal Access Token (PAT) with the read:packages scope stored in an environment variable called GH_PKG_AUTH_TOKEN - Click here to generate one

Running

  1. Run npm install

  2. Go to the Spotify developer dashboard and create a new application. The app can have whatever name and description you want

  3. Once the app is created, click on Edit Settings and add a redirect URL of http://localhost:8000/spotifyAuth (NB: the port will be whatever you have set as the AUTH_SERVER_PORT in the ./.env file, by default it is 8000)

  4. Create a ./.env file based on ./.env.template file and fill in the fields

    • The playlist ID can be found by either:

      • Right-clicking on the playlist -> clicking Share -> Copy Spotify URI and then copying the ID after spotify:playlist: e.g. spotify:playlist:{THIS_STRING_IS_THE_ID})
      • Or by right-clicking on the playlist -> clicking Share -> Copy Link to Playlist and then copying the ID after https://open.spotify.com/playlist/ and before the ?si= e.g. https://open.spotify.com/playlist/{THIS_STRING_IS_THE_ID}?si=12345123)
    • The Spotify client ID and secret are obtained from the application you created in the Spotify developer dashboard

    • If you wish to have chat feedback, set CHAT_FEEDBACK to true then generate a Twitch Chat OAuth Token and set it as the TWITCH_TOKEN field in the .env file. Also set the BOT_USERNAME field to the name of the account you wish to use (must be the same account you generate the OAuth token for)

      	**Do NOT commit this file to Git as it will contain SECRETS to log in as you!**
      
  5. Run npm run build && npm start to start the bot

  6. Open the authorization link and give the app the required permissions

  7. If you have ADD_TO_QUEUE toggled on, ensure you have the Spotify client open and that it is active (i.e. is playing a song)

  8. Type a Spotify link in the chat (ensuring the link is the first piece of text in the message) and make sure it shows up in your desired playlist (Spotify links should start with https://open.spotify.com/track/)

  9. If there's a problem with Spotify authorization at any point, try deleting the spotify-auth-store.json file and starting the app again

(Optional) Generating a binary file

  1. Run bash ./build.sh. This will automatically compile from source using npm and then build OS-native binaries using pkg

  2. Run the freshly compiled binary for your OS in ./out.

Open Source Libraries Used

Used for connecting to and performing actions using Spotify

MIT License

Used for connecting to Twitch chat

MIT License

Used for creating a temporary local web server to retrieve the callback from the Spotify authorization

MIT License

Used for the icon

Apache 2 License

Contributors

Checkout the Contributors file to see everyone who has helped out with the bot

twitch-spotify-request-bot's People

Contributors

colorful98 avatar deepsourcebot avatar dependabot[bot] avatar itsrumo avatar ivangodinez21 avatar marcdonald avatar trithir 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

Watchers

 avatar  avatar  avatar  avatar

twitch-spotify-request-bot's Issues

Heroku Deploy Erroring After Several Minutes

When the app is deployed out to Heroku, it works fine for a while, but then shuts down seemingly randomly after a few minutes. This occurs when the app is left idle AND when the app is in constant use. Issue first identified by ssbPleb on Twitter and I can recreate it on my own Heroku account with a fresh app created.

This is an example of the logs when the error occurs.
Example of logs that print when the error occurs

When Heroku restarts the app, there seems to be two instances which work in parallel for a short amount of time, resulting in messages being processed twice.

Messages being processed twice

After a minute or so Heroku fully shuts down both of the instances.

Error logs when Heroku shuts down the instances

Heroku on the free tier does shut down instances after 30 minutes of sitting idle, however this error occurs after only a few minutes and even occurs when the instance is not idle.

Bot response in twitch-chat

Would it be possible to make the bot respond in the chat using a defined twitch account?

For example my twitch is: abcd
And a second twitch account for the bot would be: abcd_bot (ofc the streamer would need to set this up on their own)

I understand that this adds another layer of complexity to the bot as it has to be authorized to twitch aswell as spotify! But it would be amazing to get some form of response for the viewers attempting to "request" songs to be played on stream 👍

Basically, when the bot detects the command (i use !spotify as prefix) it responds in chat with something like this:

Success: "Song XYZ was added to the playlist"
Fail (already in playlist): "Song XYZ is already in the playlist"
Fail (no link): "No spotify link detected"

I'm facing the issue that the people using the command are confused regarding if the song was actually added to the playlist or not, since the playlist isn't available to everyone 👍

Kind Regards,
Colorful

Procfile wrong declarations

I forgot to add worker type to the Procfile

npm start

worker npm start

This could be added at any time, it doesn't affect the deploy, it just add an option to prevent app sleeping using free dyno hours. This let the app runs 24/7 (depends on the remaining dyno hours) if the user turn on worker npm start instead of turning on web npm start (that only works for 1 hour and then go to sleep).

Currently, is only available web npm start (the other one doesn't work until Procfile be updated)

Inked120200829-62430700-c1ea-11eb-93bc-8bbdffa726fd_LI

Need Help

When it come to this, i will say that im a noob. Having several issues trying to set this up. Anyone available to help with step by step instructions. I have went to two different people and ive had no luck

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.