public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { var match = PrivateMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content); var url = string.Format("http://www.google.com/ig/calculator?hl=en&q={0}", Uri.EscapeDataString(match.Groups[3].Value)); var client = new HttpClient(); client.Timeout = new TimeSpan(0, 0, 2); client.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("en-us")); client.DefaultRequestHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8")); var request = client.GetAsync(url).ContinueWith(requestTask => { if (requestTask.Result.IsSuccessStatusCode) { requestTask.Result.Content.ReadAsStringAsync().ContinueWith(readTask => { dynamic json = JsonConvert.DeserializeObject(readTask.Result); string solution = json.rhs; jabbrClient.SayToRoom(message.Room, solution ?? "Does not compute."); }); } else { jabbrClient.SayToRoom(message.Room, "Does not compute."); } }); } }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { var match = RoomMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content); var text = Uri.EscapeUriString(match.Groups[3].Value); var client = new HttpClient(); client.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("en-us")); client.DefaultRequestHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8")); client.GetAsync(String.Format(Url, text)).ContinueWith(task => { if (task.Result.IsSuccessStatusCode) { task.Result.Content.ReadAsStringAsync().ContinueWith(readTask => { jabbrClient.SayToRoom(message.Room, readTask.Result); }); } else { jabbrClient.PrivateReply(message.From, "Error ascii'ing that for you."); } }); } }
public override void Handle(IPrivateMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { if (PrivateMessagePatterns.First().Match(message.Content).Success) { jabbrClient.PrivateReply(message.From, this.GetFormattedHelp()); } else if (PrivateMessagePatterns.ElementAt(1).Match(message.Content).Success) { jabbrClient.PrivateReply(message.From, "pong"); } else if (PrivateMessagePatterns.ElementAt(2).Match(message.Content).Success) { var match = PrivateMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content); jabbrClient.PrivateReply(message.From, match.Groups[2].Value); } else if (PrivateMessagePatterns.ElementAt(3).Match(message.Content).Success) { jabbrClient.PrivateReply(message.From, String.Format("{0:F} UTC", DateTimeOffset.UtcNow)); } else if (PrivateMessagePatterns.ElementAt(4).Match(message.Content).Success) { jabbrClient.PrivateReply(message.From, String.Format("I'm sorry, {0}. I'm afraid I can't do that.", message.From)); } } }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { jabbrClient.SayToRoom(message.Room, Carltons.RandomElement()); } }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { var formattedInformation = GetFormattedInformation(); jabbrClient.SayToRoom(message.Room, formattedInformation); } }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { var id = RoomMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content).Groups[2].Value; var url = string.IsNullOrWhiteSpace(id) ? GetRandomUrl() : GetComicUrl(id); jabbrClient.SayToRoom(message.Room, url); } }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { var location = RoomMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content).Groups[3].Value; var formattedInformation = GetWeather(location); jabbrClient.SayToRoom(message.Room, formattedInformation); } }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { var match = PrivateMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content); var choices = match.Groups[1].Value.Split(new string[] { "\"" }, StringSplitOptions.None).Where(s => !string.IsNullOrWhiteSpace(s)); jabbrClient.SayToRoom(message.Room, choices.RandomElement()); } }
public virtual void Handle(IRoomMessage message, IJabbrClient jabbrClient) { if (message == null) { throw new ArgumentNullException("message"); } if (jabbrClient == null) { throw new ArgumentNullException("jabbrClient"); } }
public override void Handle(IPrivateMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { if (PrivateMessagePatterns.First().Match(message.Content).Success) { jabbrClient.PrivateReply(message.From, this.GetFormattedHelp()); } } }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { foreach (var rule in Rules) { jabbrClient.SayToRoom(message.Room, rule); } } }
public override void Handle(IPrivateMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { if (PrivateMessagePatterns.First().Match(message.Content).Success) { jabbrClient.PrivateReply(message.From, this.GetFormattedHelp()); } else if (PrivateMessagePatterns.ElementAt(1).Match(message.Content).Success) { var match = PrivateMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content); var room = match.Groups[1].Value; var invitecode = match.Groups[3].Value; if (string.IsNullOrWhiteSpace(invitecode)) { if (jabbrClient.JoinRoom(room)) { jabbrClient.SayToRoom(room, Greetings.RandomElement()); } else { jabbrClient.PrivateReply(message.From, string.Format("Unable to join room {0}. If the room is private, make sure to /allow [botname] [room] or use /msg [botname] join room [room] [invitecode]", room)); } } else { if (jabbrClient.JoinRoom(room, invitecode)) { jabbrClient.SayToRoom(room, Greetings.RandomElement()); } else { jabbrClient.PrivateReply(message.From, string.Format("Unable to join room {0}. The invite code {1} is invalid.", room, invitecode)); } } } else if (PrivateMessagePatterns.ElementAt(2).Match(message.Content).Success) { var match = PrivateMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content); var room = match.Groups[2].Value; jabbrClient.SayToRoom(room, Farewells.RandomElement()); if (!jabbrClient.LeaveRoom(room)) { jabbrClient.PrivateReply(message.From, string.Format("Unable to leave room {0}.", room)); } } } }
public override void Handle(IPrivateMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { if (PrivateMessagePatterns.First().Match(message.Content).Success) { jabbrClient.PrivateReply(message.From, this.GetFormattedHelp()); } else { var id = PrivateMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content).Groups[2].Value; var url = string.IsNullOrWhiteSpace(id) ? GetRandomUrl() : GetComicUrl(id); jabbrClient.PrivateReply(message.From, url); } } }
public override void Handle(IPrivateMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { if (PrivateMessagePatterns.First().Match(message.Content).Success) { jabbrClient.PrivateReply(message.From, this.GetFormattedHelp()); } else { var match = PrivateMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content); var choices = match.Groups[1].Value.Split(new string[] { "\"" }, StringSplitOptions.None).Where(s => !string.IsNullOrWhiteSpace(s)); jabbrClient.PrivateReply(message.From, choices.RandomElement()); } } }
public override void Handle(IPrivateMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { if (PrivateMessagePatterns.First().Match(message.Content).Success) { jabbrClient.PrivateReply(message.From, this.GetFormattedHelp()); } else { var location = PrivateMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content).Groups[3].Value; var formattedInformation = GetWeather(location); jabbrClient.PrivateReply(message.From, formattedInformation); } } }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { Task.Factory.StartNew(() => { var match = RoomMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content); var imageUrl = match.Groups[2].Value; var stachedImageUrl = String.Format("http://faceup.me/img.jpg?overlay={0}&src={1}", Accessories.RandomElement(), Uri.EscapeDataString(imageUrl)); jabbrClient.SayToRoom(message.Room, stachedImageUrl); }).ContinueWith(task => { var result = task.Exception; }, TaskContinuationOptions.OnlyOnFaulted); } }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { var match = RoomMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content); var achievement = Uri.EscapeUriString(match.Groups[2].Value); var email = Uri.EscapeUriString(match.Groups[5].Value); var url = String.Format(Url, achievement); if (!String.IsNullOrWhiteSpace(email)) { url += String.Format("?email={0}.png", email); } jabbrClient.SayToRoom(message.Room, url); } }
public override void Handle(IPrivateMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { if (PrivateMessagePatterns.First().Match(message.Content).Success) { jabbrClient.PrivateReply(message.From, this.GetFormattedHelp()); } else { var match = PrivateMessagePatterns.First(p => p.Match(message.Content).Success).Match(message.Content); var url = string.Format("http://www.google.com/ig/calculator?hl=en&q={0}", Uri.EscapeDataString(match.Groups[3].Value)); var client = new HttpClient(); client.Timeout = new TimeSpan(0, 0, 2); client.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("en-us")); client.DefaultRequestHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8")); var request = client.GetAsync(url).ContinueWith(requestTask => { if (requestTask.Result.IsSuccessStatusCode) { requestTask.Result.Content.ReadAsStringAsync().ContinueWith(readTask => { dynamic json = JsonConvert.DeserializeObject(readTask.Result); string solution = json.rhs; jabbrClient.PrivateReply(message.From, solution ?? "Does not compute."); }); } else { jabbrClient.PrivateReply(message.From, "Does not compute."); } }); } } }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { if (RoomMessagePatterns.ElementAt(0).IsMatch(message.Content)) { jabbrClient.SayToRoom(message.Room, new string[] { "(ノಠ益ಠ)ノ︵┻━┻", "(╯°□°)╯︵ ┻━┻" }.RandomElement()); } else if (RoomMessagePatterns.ElementAt(1).IsMatch(message.Content)) { jabbrClient.SayToRoom(message.Room, "┬──┬◡ノ(° -°ノ)"); } else if (RoomMessagePatterns.ElementAt(2).IsMatch(message.Content)) { jabbrClient.SayToRoom(message.Room, "(ケ¬◟¬)ケ"); } else if (RoomMessagePatterns.ElementAt(3).IsMatch(message.Content)) { jabbrClient.SayToRoom(message.Room, "ლ(ಠ益ಠლ)"); } else if (RoomMessagePatterns.ElementAt(4).IsMatch(message.Content)) { jabbrClient.SayToRoom(message.Room, new string[] { "♪┏(・o・)┛♪", "♪┗ ( ・o・) ┓♪", "♪┏ (・o・) ┛♪", "♪┗ (・o・ ) ┓♪", "♪┏(・o・)┛♪" }.RandomElement()); } else if (RoomMessagePatterns.ElementAt(5).IsMatch(message.Content)) { jabbrClient.SayToRoom(message.Room, "ಠ_ಠ"); } else if (RoomMessagePatterns.ElementAt(6).IsMatch(message.Content)) { jabbrClient.SayToRoom(message.Room, @"¯\_(ツ)_/¯"); } } }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); }
public override void Handle(IRoomMessage message, IJabbrClient jabbrClient) { base.Handle(message, jabbrClient); if (this.CanHandle(message)) { jabbrClient.SayToRoom(message.Room, Coin.RandomElement()); } }