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

Commit

Permalink
🔧Fixed blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
mmattbtw committed Aug 1, 2021
1 parent fb5f1ad commit 23fe786
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,24 @@ def __init__(self):
)

self.token = os.environ.get("SPOTIFY_AUTH")
self.version = "1.2.5"
self.version = "1.2.5.fix"

async def event_ready(self):
print("\n" * 100)
print(f"TwitchTunes ({self.version}) Ready, logged in as: {self.nick}")
print(
"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:
data = json.load(file)
return data

def write_json(self, data, filename):
with open(f"{filename}.json", "w") as file:
json.dump(data, file, indent=4)

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

Expand Down Expand Up @@ -261,6 +270,11 @@ async def song_request(self, ctx, song, song_uri, album: bool):
data = sp.search(song, limit=1, type="track", market="US")
song_uri = data["tracks"]["items"][0]["uri"]

elif re.match(URL_REGEX, song_uri):
data = sp.track(song_uri)
song_uri = data["uri"]
song_uri = song_uri.replace("spotify:track:", "")

song_id = song_uri.replace("spotify:track:", "")

if not album:
Expand All @@ -271,7 +285,7 @@ async def song_request(self, ctx, song, song_uri, album: bool):
duration = data["duration_ms"] / 60000

if song_uri != "not found":
if song_uri in jscon["blacklist"]:
if song_id in jscon["blacklist"]:
await ctx.send("That song is blacklisted.")

elif duration > 17:
Expand All @@ -282,14 +296,6 @@ async def song_request(self, ctx, song, song_uri, album: bool):
f"@{ctx.author.name}, Your song ({song_name} by {', '.join(song_artists_names)}) [ {data['external_urls']['spotify']} ] has been added to the queue!"
)

def read_json(self, filename):
with open(f"{cwd}/{filename}.json", "r") as file:
data = json.load(file)
return data

def write_json(self, data, filename):
with open(f"{cwd}/{filename}.json", "w") as file:
json.dump(data, file, indent=4)


bot = Bot()
Expand Down

0 comments on commit 23fe786

Please sign in to comment.