Exemplo n.º 1
0
    def parse_emotes(api_response_data):
        # get with default fallback
        url_template = api_response_data.get(
            "urlTemplate", "//cdn.betterttv.net/emote/{{id}}/{{image}}")
        url_template = BTTVAPI.fill_in_url_scheme(url_template)

        def get_url(emote_hash, size):
            return url_template.replace("{{id}}", emote_hash).replace(
                "{{image}}", size + "x")

        emotes = []
        for emote in api_response_data["emotes"]:
            emote_hash = emote["id"]
            emotes.append(
                Emote(
                    code=emote["code"],
                    provider="bttv",
                    id=emote_hash,
                    urls={
                        "1": get_url(emote_hash, "1"),
                        "2": get_url(emote_hash, "2"),
                        "4": get_url(emote_hash, "3")
                    },
                ))
        return emotes
Exemplo n.º 2
0
 def add_emote(self, emote_id=None, emote_hash=None, code=None):
     emote = Emote(self,
                   emote_id=emote_id,
                   emote_hash=emote_hash,
                   code=code)
     self.add_to_data(emote)
     self.db_session.add(emote)
     return emote
Exemplo n.º 3
0
 def load_cached_emotes(redis_key):
     try:
         redis = RedisManager.get()
         redis_result = redis.get(redis_key)
         if redis_result is None:
             return None
         return [Emote(**args) for args in json.loads(redis_result)]
     except:
         log.exception("Failed to get emotes from key {} from redis".format(redis_key))
         return []
Exemplo n.º 4
0
 def twitch_emote(emote_id, code):
     return Emote(
         code=code,
         provider="twitch",
         id=emote_id,
         urls={
             "1": EmoteManager.twitch_emote_url(emote_id, "1.0"),
             "2": EmoteManager.twitch_emote_url(emote_id, "2.0"),
             "4": EmoteManager.twitch_emote_url(emote_id, "3.0"),
         },
     )
Exemplo n.º 5
0
 def load_cached_subemotes(redis_key):
     try:
         redis = RedisManager.get()
         redis_result = redis.get(redis_key)
         if redis_result is None:
             return None, None, None
         obj = {key: [Emote(**args) for args in value] for key, value in json.loads(redis_result).items()}
         return obj["1"], obj["2"], obj["3"]
     except:
         log.exception("Failed to get subemotes from key {} from redis".format(redis_key))
         return [], [], []
Exemplo n.º 6
0
    def parse_emotes(api_response_data: List[Dict[str, Any]]) -> List[Emote]:
        def get_url(emote_id: str, size: str) -> str:
            return f"https://cdn.betterttv.net/emote/{emote_id}/{size}x"

        emotes = []
        for emote_data in api_response_data:
            emote_id = emote_data["id"]
            emotes.append(
                Emote(
                    code=emote_data["code"],
                    provider="bttv",
                    id=emote_id,
                    urls={"1": get_url(emote_id, "1"), "2": get_url(emote_id, "2"), "4": get_url(emote_id, "3")},
                )
            )
        return emotes
Exemplo n.º 7
0
    def load_data(self, redis=None):
        if redis is None:
            redis = RedisManager.get()

        redis_json = redis.get(self.current_emote_key)
        if redis_json is None:
            # randomize an emote
            # TODO possibly a setting to allow the user to configure the twitch_global=True, etc
            #      parameters to random_emote?
            self.current_emote = self.bot.emote_manager.random_emote(
                twitch_global=True)
            # If EmoteManager has no global emotes, current_emote will be None
            if self.current_emote is not None:
                redis.set(self.current_emote_key,
                          json.dumps(self.current_emote.jsonify()))
        else:
            self.current_emote = Emote(**json.loads(redis_json))
Exemplo n.º 8
0
    def parse_sets(emote_sets) -> List[Emote]:
        emotes = []
        for emote_set in emote_sets.values():
            for emote in emote_set["emoticons"]:
                # FFZ returns relative URLs (e.g. //cdn.frankerfacez.com/...)
                # so we fill in the scheme if it's missing :)
                urls = {
                    size: FFZAPI.fill_in_url_scheme(url)
                    for size, url in emote["urls"].items()
                }
                emotes.append(
                    Emote(code=emote["name"],
                          provider="ffz",
                          id=str(emote["id"]),
                          urls=urls))

        return emotes
Exemplo n.º 9
0
    def parse_emotes(api_response_data):
        def get_url(emote_id, size):
            return f"https://cdn.7tv.app/emote/{emote_id}/{size}x"

        emotes = []
        for emote_data in api_response_data:
            emote_id = emote_data["id"]
            emotes.append(
                Emote(
                    code=emote_data["name"],
                    provider="7tv",
                    id=emote_id,
                    urls={
                        "1": get_url(emote_id, "1"),
                        "2": get_url(emote_id, "2"),
                        "3": get_url(emote_id, "3"),
                        "4": get_url(emote_id, "4"),
                    },
                ))
        return emotes