Skip to content

Commit

Permalink
Fix for twitch's bad category search
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaserlang committed Apr 18, 2022
1 parent 0321189 commit 440da91
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tbot/twitch_bot/functions/title_game_views_followers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from tbot.twitch_bot.var_filler import fills_vars, Send_error
from tbot import utils

Expand Down Expand Up @@ -90,11 +91,17 @@ async def set_game(bot, channel_id, args, var_args, **kwargs):
data = await utils.twitch_channel_token_request(
bot, channel_id,
'https://api.twitch.tv/helix/search/categories',
params={'query': game},
params={'query': f'"{game}"'},
)
if 'data' in data and data['data']:
game_id = data['data'][0]['id']
game = data['data'][0]['name']
for g in data['data']:
if g['name'].lower() == game.lower():
game_id = g['id']
game = g['name']
break
else:
game_id = data['data'][0]['id']
game = data['data'][0]['name']
else:
raise Send_error(f'No game or category found for {game}')
try:
Expand Down

0 comments on commit 440da91

Please sign in to comment.