コード例 #1
0
ファイル: EmoteInfo.cs プロジェクト: NikkyAI/vs-twitchemotes
        public EmoteInfo(TwitchEmoteUtil emoteUtil, ICoreClientAPI api, Mod mod, string channelName, int id, string code,
                         string variant, string key)
        {
            ChannelName = channelName;
            Url         = $"https://static-cdn.jtvnw.net/emoticons/v2/{id + variant}/default/dark/3.0";
            Id          = id;
            Code        = code;
            Variant     = variant;
            IsRegex     = !Regex.IsMatch(code, "^[a-zA-Z0-9]*$");
            Key         = IsRegex ? $"emote_{id}" + Variant : key;
            Filepath    = GenerateFilepathForEmote(api.DataBasePath, channelName, Key);
            // Key = IsRegex ? key.Replace("\\", "") : key;
            ImageData = null;

            DownloadTask = Task.Run(async() =>
            {
                try
                {
                    return(await emoteUtil.LoadEmote(this));
                }
                catch (Exception e)
                {
                    mod.Logger.Error("unhandled exception loading {0} exception: {1}", Key, e);
                    return(false);
                }
            });
            // DownloadTask.Wait();
        }
コード例 #2
0
        public override void StartClientSide(ICoreClientAPI api)
        {
            _mod = base.Mod;
            LoadConfig(api);
            _emoteUtil = new TwitchEmoteUtil(_mod, api, Config.channels);

            base.Mod.Logger.Debug("registering command");
            VtmlUtil.TagConverters.Add(
                "twitch_icon",
                (coreApi, token, stack, link) =>
            {
                if (!token.Attributes.TryGetValue("emotekey", out string emoteKey))
                {
                    _mod.Logger.Error("missing 'emoteKey' in twitch_icon tag, attributes: {0}", string.Join(" ", token.Attributes.Keys));
                    return(new IconComponent(coreApi, "none", stack.Peek()));
                }
                if (!token.Attributes.TryGetValue("raw", out string?raw))
                {
                    raw = null;
                }

                if (!_emoteUtil.emotes.TryGetValue(emoteKey, out var emote))
                {
                    _mod.Logger.Error("missing '{0}' in emotes", emoteKey);
                    return(new IconComponent(coreApi, "none", stack.Peek()));
                }

                var success = emote.DownloadTask.Result;
                if (success != true)
                {
                    _mod.Logger.Error("emote '{0}' marked as failing", emoteKey);
                    return(new IconComponent(coreApi, "none", stack.Peek()));
                }

                TwitchIconComponent iconComponent = new(coreApi, _mod, stack.Peek(), emoteKey, raw, _emoteUtil);
                return((RichTextComponentBase)iconComponent);
            }