public static void SaveConfig(UrlHistoryConfigModel.UrlHistoryConfig config, bool syncToCache = true) { if (syncToCache) { Cache.Set(CacheName, config, DateTimeOffset.Now.AddMinutes(CacheExpiration)); } ConfigHelpers.SaveConfig(config, ConfigHelpers.ConfigPaths.UrlHistoryConfig); }
public static string GetResponse(UrlHistoryConfigModel.UrlHistoryConfig config, string channel) { List <string> possibleMentions = config.DefaultResponses.Concat(config.ChannelConfigs .Find(c => string.Equals(c.Channel, channel, ComparisonCulture)) .Responses) .ToList(); return(possibleMentions[new Random().Next(0, possibleMentions.Count - 1)]); }
// null if no mention public static UrlHistoryConfigModel.UrlMention GetUrlMention(UrlHistoryConfigModel.UrlHistoryConfig config, string channel, string url) { // Links in stored mentions should not contain a #, clean up any imports you might do, regex I used to match # in links was "#(\S+)" // It's mostly a preference to not store #blahblah stuff as it is client specific and may cause false negatives for people posting very similar URLs if (url.Contains("#")) { url = url.Substring(0, url.LastIndexOf("#", StringComparison.InvariantCulture)); } var channelConfig = config.ChannelConfigs.Find(c => string.Equals(c.Channel, channel, ComparisonCulture)) ?? new UrlHistoryConfigModel.ChannelConfig { MatchMentionsFromOtherChannels = false }; var mentionMatch = config.Mentions.Find(m => m.Link == url && (string.Equals(channel, m.Channel, ComparisonCulture) || channelConfig.MatchMentionsFromOtherChannels)); return(mentionMatch); }