示例#1
0
        public void RegisterEmote(TwitchEmote emote)
        {
            var window = _host.ActiveIWindow;

            //Check if we've already added this emote
            if (_handledEmotes.Contains(emote.Name))
            {
                return;
            }

            var emoteDirectory = _host.ConfigFolder + @"\TwitchEmotes";
            var emoteFile      = $"{emoteDirectory}\\{emote.Id}.png";

            //Check if we've already downloaded this emote earlier, if so just
            //add the existing file.
            if (File.Exists(emoteFile))
            {
                //ExecuteCommand executes a scripting command like you entered
                //into the window ExecteCommand is being invoked on.
                //https://dev.adiirc.com/projects/adiirc/wiki/Scripting_Commands

                //AdiIRC will supress the output of a slashcommand if its
                //instead invoked with a starting .

                //Setoption is a slash command to add or change options in the .ini file
                //https://dev.adiirc.com/projects/adiirc/wiki/Setoption
                var command = $".setoption Emoticons Emoticon_{emote.Name} {emoteFile}";
                window.ExecuteCommand(command);
                _handledEmotes.Add(emote.Name);
                return;
            }

            //Try to download the emote, then add it
            if (emote.DownloadEmote(emoteFile))
            {
                //See above
                var command = $".setoption Emoticons Emoticon_{emote.Name} {emoteFile}";
                window.ExecuteCommand(command);
                _handledEmotes.Add(emote.Name);
            }
        }
示例#2
0
        private bool ExtractEmotes()
        {
            //Early exit if the tags does not contain any emotes.
            if (!Tags.ContainsKey("emotes"))
            {
                return(false);
            }

            Emotes = new List <TwitchEmote>();

            var emoteMatches = Regex.Matches(Tags["emotes"], _emoteRegex);

            //Early exit if no emotes were actually matched.
            if (emoteMatches.Count <= 0)
            {
                return(false);
            }

            //Emotes are received as an id and the partof the message they match too
            //So we substring the actual name of the mote out of the message.
            foreach (Match match in emoteMatches)
            {
                var emoteId    = match.Groups[2].ToString();
                var startIndex = int.Parse(match.Groups[3].ToString());
                var endIndex   = int.Parse(match.Groups[4].ToString());

                var emoteName = RawMessage.Substring(startIndex, endIndex - startIndex + 1);
                File.AppendAllText(TwitchApiTools.logPath, $"{match.Value} <-> Extracting({startIndex}, {endIndex}): {emoteName}\r\n");

                var emote = new TwitchEmote {
                    Id = emoteId, Name = emoteName
                };

                Emotes.Add(emote);
            }

            return(true);
        }