예제 #1
0
파일: queup.py 프로젝트: zneix/pajbot
 def get_current_song(self, room_id):
     return self.cache.cache_fetch_fn(
         redis_key=f"api:queup:current-song:{room_id}",
         fetch_fn=lambda: self.fetch_current_song(room_id),
         serializer=ClassInstanceSerializer(QueUpQueueSong),
         expiry=lambda response: 0 if response is None else 5,
     )
예제 #2
0
 def get_current_song(self, room_id):
     return self.cache.cache_fetch_fn(
         redis_key="api:dubtrack:current-song:{}".format(room_id),
         fetch_fn=lambda: self.fetch_current_song(room_id),
         serializer=ClassInstanceSerializer(DubtrackQueueSong),
         expiry=lambda response: 0 if response is None else 5,
     )
예제 #3
0
 def get_channel_badge_sets(self, channel_id):
     return self.cache.cache_fetch_fn(
         redis_key=f"api:twitch:badges:channel-badge-sets:{channel_id}",
         fetch_fn=lambda: self._fetch_channel_badge_sets(channel_id),
         serializer=ClassInstanceSerializer(BadgeSets),
         expiry=60 * 60,
     )
예제 #4
0
 def get_stream_by_user_id(self, user_id) -> Optional[UserStream]:
     return self.cache.cache_fetch_fn(
         redis_key=f"api:twitch:helix:stream:by-id:{user_id}",
         fetch_fn=lambda: self._fetch_stream_by_user_id(user_id),
         serializer=ClassInstanceSerializer(UserStream),
         expiry=lambda response: 30 if response is None else 300,
     )
예제 #5
0
 def get_games_by_name(self, game_names: List[str]) -> List[TwitchGame]:
     return self.cache.cache_bulk_fetch_fn(
         game_names,
         redis_key_fn=lambda game_name: f"api:twitch:helix:game:by-name:{game_name}",
         fetch_fn=lambda game_names: self._fetch_games("name", game_names),
         serializer=ClassInstanceSerializer(TwitchGame),
         expiry=lambda response: 300 if response is None else 7200,
     )
예제 #6
0
 def get_channel_information(self, user_id) -> Optional[UserChannelInformation]:
     """Gets the channel information of a Twitch user for the given Twitch user ID,
     utilizing a cache or the Twitch API on cache miss.
     If no channel with the user exists, None is returned.
     https://dev.twitch.tv/docs/api/reference#get-channel-information"""
     return self.cache.cache_fetch_fn(
         redis_key=f"api:twitch:helix:channel-information:{user_id}",
         serializer=ClassInstanceSerializer(UserChannelInformation),
         fetch_fn=lambda: self.fetch_channel_information(user_id),
         expiry=lambda response: 30 if response else 300,
     )