public void Process(Message message) { if (CanProcess(message)) { var symbol = REGEX.Match(message.ProcessedContent).Groups[3].Value; message.ProcessedContent = GetStockInformation(symbol); } }
public override bool ContainsContent(Message message) { IEnumerable<Uri> urls; TextTransformer.TransformAndExtractUrls(message.ProcessedContent, out urls); return urls.Any(u => u.Authority.Equals("www.youtube.com", StringComparison.OrdinalIgnoreCase) || u.Authority.Equals("youtu.be", StringComparison.OrdinalIgnoreCase)); }
public void Process(Message message) { if (CanProcess(message)) { var location = REGEX.Match(message.ProcessedContent).Groups[3].Value; message.ProcessedContent = GetWeather(location); } }
public void Process(Message message) { if (CanProcess(message)) { if (REGEXES[0].IsMatch(message.ProcessedContent)) { message.ProcessedContent = GetCIInformation(); } } }
public override void ExtractContent(Message message) { IEnumerable<Uri> urls; TextTransformer.TransformAndExtractUrls(message.ProcessedContent, out urls); foreach (var url in urls.Distinct().Where(u => IsImageUrl(u))) { var extractedContent = string.Format("<img style=\"max-height:500px\" src=\"{0}\" />", url); message.ProcessedContent += string.Format(base.EmbeddedContentMarkUpFormat, url, extractedContent); } }
public void Process(Message message) { if (CanProcess(message)) { if (message.ProcessedContent.Equals("/bacon", StringComparison.OrdinalIgnoreCase)) { message.ProcessedContent = URLS.RandomElement(); } else if (REGEX.IsMatch(message.ProcessedContent)) { var url = REGEX.Match(message.ProcessedContent).Groups[3].Value; message.ProcessedContent = string.Format("http://bacolicio.us/{0}", url); } } }
public void Save(Message message) { var json = JsonConvert.SerializeObject(message); using (var connection = new RedisConnection(Host, Port, -1, Password)) { connection.Open().Wait(); connection.Lists.AddFirst(Db, REDISMESSAGESKEY, json).Wait(); var listLength = connection.Lists.GetLength(Db, REDISMESSAGESKEY).Result; if (listLength > MAXMESSAGES) { connection.Lists.Trim(Db, REDISMESSAGESKEY, MAXMESSAGES).Wait(); } } }
public bool CanProcess(Message message) { var canProcess = false; if (message.ProcessedContent.Equals("/ping", StringComparison.OrdinalIgnoreCase)) { canProcess = true; } else if (message.ProcessedContent.StartsWith("/echo", StringComparison.OrdinalIgnoreCase)) { canProcess = true; } else if (message.ProcessedContent.Equals("/time", StringComparison.OrdinalIgnoreCase)) { canProcess = true; } return canProcess; }
public override void ExtractContent(Message message) { const string extractedContentFormat = @"<object width=""425"" height=""344""><param name=""WMode"" value=""transparent""></param><param name=""movie"" value=""http://www.youtube.com/v/{0}fs=1""></param><param name=""allowFullScreen"" value=""true""></param><param name=""allowScriptAccess"" value=""always""></param><embed src=""http://www.youtube.com/v/{0}?fs=1"" wmode=""transparent"" type=""application/x-shockwave-flash"" allowfullscreen=""true"" allowscriptaccess=""always"" width=""425"" height=""344B""></embed></object>"; IEnumerable<Uri> urls; TextTransformer.TransformAndExtractUrls(message.ProcessedContent, out urls); foreach (var url in urls.Distinct()) { Match match = YoutubeRegex.Match(url.ToString()); if (match.Groups.Count < 2 || String.IsNullOrEmpty(match.Groups[1].Value)) { } else { string videoId = match.Groups[1].Value; string extractedContent = string.Format(extractedContentFormat, videoId); message.ProcessedContent += string.Format(base.EmbeddedContentMarkUpFormat, url, extractedContent); } } }
public void Process(Message message) { if (CanProcess(message)) { var regex = REGEXES.First(r => r.IsMatch(message.RawContent)); var type = regex.Match(message.RawContent).Groups[3].Value; var number = regex.Match(message.RawContent).Groups[4].Value; if (type.Equals("de", StringComparison.OrdinalIgnoreCase)) { message.ProcessedContent = GetDefect(number); } else if(type.Equals("ta", StringComparison.OrdinalIgnoreCase)) { message.ProcessedContent = GetTask(number); } else if (type.Equals("us", StringComparison.OrdinalIgnoreCase)) { message.ProcessedContent = GetStory(number); } } }
public void Process(Message message) { if (CanProcess(message)) { var index = Regexes.FindIndex(r => r.IsMatch(message.ProcessedContent)); var matches = Regexes.ElementAt(index).Matches(message.ProcessedContent); var accessory = index == 0 ? Accessories.RandomElement() : Accessories[index - 1]; var urls = new List<string>(); foreach (Match match in matches) { urls.Add(match.Groups[3].Value); } urls = urls.Distinct().ToList(); foreach (var url in urls) { message.ProcessedContent = String.Format("http://faceup.me/img.jpg?overlay={0}&src={1}", accessory, Uri.EscapeDataString(url)); } } }
public void Process(Message message) { if (CanProcess(message)) { if (message.ProcessedContent.Equals("/ping", StringComparison.OrdinalIgnoreCase)) { message.ProcessedContent = "pong"; message.From = ChatHubConfiguration.BotName; message.Type = MessageType.Private; } else if (message.ProcessedContent.StartsWith("/echo ", StringComparison.OrdinalIgnoreCase)) { message.ProcessedContent = message.ProcessedContent.Substring(6); message.From = ChatHubConfiguration.BotName; message.Type = MessageType.Private; } else if (message.ProcessedContent.Equals("/time", StringComparison.OrdinalIgnoreCase)) { message.ProcessedContent = string.Format("{0:F} UTC", DateTime.UtcNow); message.From = ChatHubConfiguration.BotName; message.Type = MessageType.Private; } } }
private void SendPrivateMessage(Message message) { try { Clients[Context.ConnectionId].addMessage(message); if (!string.IsNullOrWhiteSpace(message.To)) { var users = UserStore.Read().Where(u => u.Username.Equals(message.To.ToLower())); if (users != null && users.Any()) { foreach (var user in users) { Clients[user.ConnectionId].addMessage(message); } } else { message.From = ChatHubConfiguration.BotName; message.ProcessedContent = string.Format("Unknown username: @{0}", message.To); Clients[Context.ConnectionId].addMessage(message); } } } catch (Exception ex) { Logger.ErrorException("An exception occured while sending a private message.", ex); } }
private void SendPublicMessage(Message message) { try { Clients.addMessage(message); } catch (Exception ex) { Logger.ErrorException("An exception occured while sending a public message.", ex); } }
private void SendMessage(Message message) { try { switch (message.Type) { case MessageType.Public: SendPublicMessage(message); break; case MessageType.Private: SendPrivateMessage(message); break; case MessageType.Unknown: default: throw new ArgumentException("Unknown MessageType"); } } catch (Exception ex) { Logger.ErrorException("An exception occured while sending a message.", ex); } }
private Message ProcessMessage(Message message) { try { message.ProcessedContent = message.ProcessedContent.Trim(); message.ProcessedContent = HttpUtility.HtmlEncode(message.ProcessedContent); foreach (var commandProcessor in CommandProcessors.Where(p => p.CanProcess(message))) { commandProcessor.Process(message); } message.ProcessedContent = TextTransformer.TransformUrls(message.ProcessedContent); message.ProcessedContent = TextTransformer.FormatMultiLineContent(message.ProcessedContent); foreach (var contentProvider in ContentProviders.Where(p => p.ContainsContent(message))) { contentProvider.ExtractContent(message); } } catch (Exception ex) { Logger.ErrorException("An exception occured while processing a message.", ex); } return message; }
private void StoreMessage(Message message) { try { if (message.Type.Equals(MessageType.Public)) { MessageStore.Save(message); } } catch (Exception ex) { Logger.ErrorException("An exception occured while saving a message.", ex); } }
private Message ParseMessage(string message) { var privateMessageRegex = new Regex("^(@)(.+?)( )(.+)"); var parsedMessage = new Message { Timestamp = DateTime.UtcNow, From = Context.User.Identity.Name, RawContent = message }; try { if (privateMessageRegex.IsMatch(message)) { var match = privateMessageRegex.Match(message); var username = match.Groups[2].Value; var privateMessage = match.Groups[4].Value; parsedMessage.ProcessedContent = privateMessage; parsedMessage.Type = MessageType.Private; parsedMessage.To = username; } else { parsedMessage.ProcessedContent = message; parsedMessage.Type = MessageType.Public; } } catch (Exception ex) { Logger.ErrorException("An exception occured while parsing a message.", ex); } return parsedMessage; }
public bool CanProcess(Message message) { return REGEXES.Any(r => r.IsMatch(message.ProcessedContent)); }
public abstract bool ContainsContent(Message message);
public bool CanProcess(Message message) { return message.ProcessedContent.Equals("/bacon", StringComparison.OrdinalIgnoreCase) || REGEX.IsMatch(message.ProcessedContent); }
public void Save(Message message) { Messages.Add(message); }
public abstract void ExtractContent(Message message);
public bool CanProcess(Message message) { return REGEX.IsMatch(message.ProcessedContent); }
public override bool ContainsContent(Message message) { IEnumerable<Uri> urls; TextTransformer.TransformAndExtractUrls(message.ProcessedContent, out urls); return urls.Any(u => IsImageUrl(u)); }
private void Send(Message message) { ProcessMessage(message); StoreMessage(message); SendMessage(message); }