-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
226933d
commit 0a57c56
Showing
10 changed files
with
327 additions
and
83 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from tbot.utils.twitch import twitch_request | ||
from tbot.web.handlers.api.base import Api_handler | ||
|
||
|
||
class BadgesHandler(Api_handler): | ||
async def get(self, channel_id): | ||
badges = await twitch_request( | ||
self.ahttp, url='https://api.twitch.tv/helix/chat/badges/global' | ||
) | ||
channel_badges = await twitch_request( | ||
self.ahttp, | ||
url=f'https://api.twitch.tv/helix/chat/badges?broadcaster_id={channel_id}', | ||
) | ||
self.write_object( | ||
{ | ||
'global_badges': badges['data'], | ||
'channel_badges': channel_badges['data'], | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useQuery } from "react-query"; | ||
import api from "tbot/twitch/api"; | ||
|
||
export function Badges({ channelId, badges }) { | ||
const { data, isLoading } = useQuery( | ||
["badges", channelId], | ||
async () => { | ||
const data = await api.get(`/api/twitch/channels/${channelId}/badges`); | ||
return [...data.data.global_badges, ...data.data.channel_badges]; | ||
}, | ||
{ | ||
staleTime: 1000 * 60 * 60, | ||
cacheTime: 1000 * 60 * 60, | ||
} | ||
); | ||
if (isLoading || !badges) { | ||
return <></>; | ||
} | ||
const items = badges.split(","); | ||
const parsedBadges = items.map((item) => { | ||
const [set_id, id] = item.split("/"); | ||
return { set_id, id }; | ||
}); | ||
return ( | ||
<> | ||
{parsedBadges.map((badge) => { | ||
const b = findBadge(data, badge.set_id, badge.id); | ||
if (b) | ||
return ( | ||
<img | ||
key={[badge.set_id, badge.id]} | ||
title={b.title} | ||
className="chat-badge" | ||
src={b.image_url_1x} | ||
></img> | ||
); | ||
})} | ||
</> | ||
); | ||
} | ||
|
||
function findBadge(badges, set_id, id) { | ||
for (const badge of badges) { | ||
if (badge.set_id === set_id) { | ||
for (const version of badge.versions) { | ||
if (version.id === id) { | ||
return version; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters