Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
TWITCH TUNES v1.3.0 OH MY GOD TAJJ IS GONNA BE SO EXCITED
Browse files Browse the repository at this point in the history
  • Loading branch information
mmattbtw committed May 28, 2022
1 parent a02cacc commit 3095a77
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"type": "python",
"request": "launch",
"program": "bot.py",
// "args": ["dev"],
"console": "integratedTerminal"
}
]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@
* `!np` - Shows the current song

* `!songrequest {song}` - Requests a song to be played

* `!lastsong` - Shows the last 10 songs that were played! (we still can't get the Spotify queue from the API https://community.spotify.com/t5/Closed-Ideas/Developer-Web-API-playback-queue-route/idc-p/5387376#M261127 i hate spotify web api...)
34 changes: 27 additions & 7 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def path_exists(filename):
"user-modify-playback-state",
"user-read-currently-playing",
"user-read-playback-state",
"user-read-recently-played",
],
)
)
Expand All @@ -150,14 +151,11 @@ def __init__(self):
)

self.token = os.environ.get("SPOTIFY_AUTH")
self.version = "1.2.8"
self.version = "1.3.0"

async def event_ready(self):
log.info("\n" * 100)
log.info(f"TwitchTunes ({self.version}) Ready, logged in as: {self.nick}")
log.info(
"Ignore the 'AttributeError: 'NoneType' object has no attribute '_ws'' error, this is an issue with the library."
)

def read_json(self, filename):
with open(f"{filename}.json", "r") as file:
Expand All @@ -171,9 +169,6 @@ def write_json(self, data, filename):
def is_owner(self, ctx):
return ctx.author.id == "640348450"

async def event_message(self, message):
await self.handle_commands(message)

# This is an owner only command for an inside joke in a certain channel, just ignore this :)
@commands.command(name="s3s")
async def s3s(self, ctx):
Expand Down Expand Up @@ -293,6 +288,26 @@ async def np_command(self, ctx):
f"🎶Now Playing - {data['item']['name']} by {', '.join(song_artists_names)} | Link: {data['item']['external_urls']['spotify']} | {time_through} - {time_total}"
)

@commands.command(
name="lastsong", aliases=["previoussongs", "last", "previousplayed"]
)
async def queue_command(self, ctx):
queue = sp.current_user_recently_played(limit=10)
songs = []

for song in queue["items"]:
# if the song artists include more than one artist: add all artist names to an artist list variable
if len(song["track"]["artists"]) > 1:
artists = [artist["name"] for artist in song["track"]["artists"]]
song_artists = ", ".join(artists)
# if the song artists only include one artist: add the artist name to the artist list variable
else:
song_artists = song["track"]["artists"][0]["name"]

songs.append(song["track"]["name"] + " - " + song_artists)

await ctx.send("Recently Played: " + " | ".join(songs))

@commands.command(name="songrequest", aliases=["sr", "addsong"])
async def songrequest_command(self, ctx, *, song: str):
song_uri = None
Expand Down Expand Up @@ -328,6 +343,11 @@ async def songrequest_command(self, ctx, *, song: str):
# else:
# await ctx.send(f"🎶You don't have permission to do that! (Album queue is Sub Only!)")

"""
DO NOT USE THE API REQUEST IT WONT WORK.
the logic should still work iwth using the spotipy library, so thats why I'm keeping it, but don't do an API request
- like this.
"""
# async def album_request(self, ctx, song):
# song = song.replace("spotify:album:", "")
# ALBUM_URL = f"https://api.spotify.com/v1/albums/{song}?market=US"
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
aiohttp == 3.7.4.post0

# C:\Users\notmm\twitchtunes\bot.py: 106
python_dotenv == 0.19.2
python_dotenv == 0.20.0

# C:\Users\notmm\twitchtunes\bot.py: 6
rich == 11.2.0
rich == 12.4.4

# C:\Users\notmm\twitchtunes\bot.py: 116,117
spotipy == 2.19.0

# C:\Users\notmm\twitchtunes\bot.py: 108
twitchio == 2.1.5
twitchio == 2.2.0
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ def path_exists(filename):
return os.path.join(".", f"{filename}")


input(
"Let's install the Python dependencies\n(This will also happen every time you open bot.py, to make sure they are up to date)\nPress `ENTER` to continue. "
)
input("Let's install the Python dependencies\nPress `ENTER` to continue. ")
os.system("pip install -U -r requirements.txt")

print("\n⚠⚠⚠⚠⚠ WARNING: DO NOT SHOW THE FOLLOWING ON STREAM. ⚠⚠⚠⚠⚠" * 10)
Expand Down
3 changes: 3 additions & 0 deletions update-bot-with-git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os

os.system("git pull origin master")
3 changes: 3 additions & 0 deletions update-dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os

os.system("pip install -r requirements.txt")

0 comments on commit 3095a77

Please sign in to comment.