Beispiel #1
0
        /// <summary>
        ///     Removes the specified <see cref="MessageEmote"/> from the collection.
        /// </summary>
        /// <param name="emote">The <see cref="MessageEmote"/> to remove.</param>
        public void Remove(MessageEmote emote)
        {
            if (!_emoteList.ContainsKey(emote.Text))
            {
                return;
            }

            _emoteList.Remove(emote.Text);

            // These patterns look a lot scarier than they are because we have to look for
            // a lot of regex characters, which means we do a lot of escaping!

            // Matches ^(\bEMOTE\b)| and ^(\bEMOTE\b)
            // It's all grouped so that we can OR it with the second pattern.
            string firstEmotePattern = @"(^\(\\b" + emote.EscapedText + @"\\b\)\|?)";
            // Matches |(\bEMOTE\b) including the preceding | so that the following | and emote (if any)
            // merge seamlessly when this section is removed. Again, wrapped in a group.
            string otherEmotePattern = @"(\|\(\\b" + emote.EscapedText + @"\\b\))";
            string newPattern        = Regex.Replace(CurrentPattern, firstEmotePattern + "|" + otherEmotePattern, "");

            if (newPattern.Equals(""))
            {
                CurrentPattern = null;
            }
            else
            {
                CurrentPattern = newPattern;
            }
        }
Beispiel #2
0
 private string GetReplacementString(Match m)
 {
     if (_emoteList.ContainsKey(m.Value))
     {
         MessageEmote emote = _emoteList[m.Value];
         if (CurrentEmoteFilter(emote))
         {
             return(emote.ReplacementString);
         }
     }
     //If the match doesn't exist in the list ("shouldn't happen") or the filter excludes it, don't replace.
     return(m.Value);
 }
Beispiel #3
0
        /// <summary>
        ///     A delegate which attempts to match the calling <see cref="MessageEmote"/> with its
        ///     <see cref="EmoteSource"/> and pulls the <see cref="EmoteSize.Small">small</see> version
        ///     of the URL.
        /// </summary>
        /// <param name="caller"></param>
        /// <returns></returns>
        public static string SourceMatchingReplacementText(MessageEmote caller)
        {
            int sizeIndex = (int)caller.Size;

            switch (caller.Source)
            {
            case EmoteSource.BetterTwitchTv:
                return(String.Format(BetterTwitchTvEmoteUrls[sizeIndex], caller.Id));

            case EmoteSource.FrankerFaceZ:
                return(String.Format(FrankerFaceZEmoteUrls[sizeIndex], caller.Id));

            case EmoteSource.Twitch:
                return(String.Format(TwitchEmoteUrls[sizeIndex], caller.Id));
            }
            return(caller.Text);
        }
Beispiel #4
0
        /// <summary>
        ///     Adds an <see cref="MessageEmote"/> to the collection. Duplicate emotes
        ///     (judged by <see cref="MessageEmote.Text"/>) are ignored.
        /// </summary>
        /// <param name="emote">The <see cref="MessageEmote"/> to add to the collection.</param>
        public void Add(MessageEmote emote)
        {
            if (_emoteList.ContainsKey(emote.Text))
            {
                return;
            }

            _emoteList.Add(emote.Text, emote);
            if (CurrentPattern == null)
            {
                //string i = String.Format(_basePattern, "(" + emote.EscapedText + "){0}");
                CurrentPattern = String.Format(_basePattern, emote.EscapedText);
            }
            else
            {
                CurrentPattern = CurrentPattern + "|" + String.Format(_basePattern, emote.EscapedText);
            }
        }
Beispiel #5
0
 /// <summary>
 ///     This emote filter includes only <see cref="MessageEmote"/>s provided by Twitch.
 /// </summary>
 /// <param name="emote">
 ///     A <see cref="MessageEmote"/> which will be replaced if its
 ///     <see cref="MessageEmote.Source">Source</see> is <see cref="MessageEmote.EmoteSource.Twitch"/>
 /// </param>
 /// <returns>true always</returns>
 public static bool TwitchOnlyEmoteFilter(MessageEmote emote)
 {
     return(emote.Source == MessageEmote.EmoteSource.Twitch);
 }
Beispiel #6
0
 /// <summary>
 ///     The default emote filter includes every <see cref="MessageEmote"/> registered on this list.
 /// </summary>
 /// <param name="emote">An emote which is ignored in this filter.</param>
 /// <returns>true always</returns>
 public static bool AllInclusiveEmoteFilter(MessageEmote emote)
 {
     return(true);
 }