public void Execute(Bot bot) { if (string.IsNullOrWhiteSpace(ipAddressOrHostNameOfCCServer) || !Projects.Any()) return; var client = new CruiseServerHttpClient(string.Format("http://{0}/ccnet/", ipAddressOrHostNameOfCCServer)); foreach (var projectStatus in client.GetProjectStatus()) { var isNew = false; if (Projects.Contains(projectStatus.Name)) { var status = Statuses.FirstOrDefault(s => s.Name == projectStatus.Name); if (status == null) { status = projectStatus; Statuses.Add(status); isNew = true; } if (status.LastBuildDate != projectStatus.LastBuildDate || isNew) { status.LastBuildDate = projectStatus.LastBuildDate; foreach (var room in bot.Rooms) { bot.Say( string.Format("CCNET Build Server: {0} / {1} - {2} ({3}) - {4}", projectStatus.WebURL, projectStatus.Name, projectStatus.BuildStatus, projectStatus.LastBuildLabel, projectStatus.LastBuildDate.ToString()), room); } } } } }
public void Execute(Bot bot) { if (string.IsNullOrWhiteSpace(IpAddressOrHostNameOfCCServer) || !Projects.Any()) return; _client = new TeamCityClient(IpAddressOrHostNameOfCCServer); _client.Connect("teamcitysharpuser", "qwerty"); var allProjects = _client.AllProjects(); var allBuildConfigs = _client.AllBuildConfigs(); foreach (var proj in allProjects) { Project currentProject = proj; var buildConfigs = allBuildConfigs.Where(buildConfig => currentProject.Id == buildConfig.Project.Id); foreach (var currentBuildConfig in buildConfigs) { var build = _client.LastBuildByBuildConfigId(currentBuildConfig.Id); var project = new ProjectModel(currentProject.Name, currentProject.Id, currentBuildConfig.Name, build.StartDate, build.Status, build.StatusText); Update(bot, project); } } }
public void Execute(Bot bot) { if (Lock == true) return; Lock = true; Debug.WriteLine(string.Format("Fetching from Disqus! - {0:HH.mm.ss}", DateTime.Now)); var client = new WebClient(); var threads = GetThreads(client).ToList(); var posts = GetPosts(client).ToList(); foreach (var post in posts.Where(p => !(p.isDeleted == true || p.isSpam == true) && DateTime.Parse(p.createdAt.ToString()) > LastUpdate && DateTime.Parse(p.createdAt.ToString()) > DateTime.Now.AddDays(-1)).OrderBy(p => DateTime.Parse(p.createdAt.ToString()))) { var thread = threads.SingleOrDefault(t => t.id == post.thread); foreach (var room in bot.Rooms) { var msg = Regex.Replace(post.message.ToString(), @"<br>", "\n"); msg = Regex.Replace(msg, @"\"" rel=\""nofollow\"">[-./""\w\s]*://[-./""\w\s]*", string.Empty); msg = Regex.Replace(msg, @"<a href=\""", string.Empty); msg = Regex.Replace(msg, @"<(.|\n)*?>", string.Empty); bot.Say( string.Format("{0} - {1} ({2}) - {3}", thread == null ? "Unknown" : thread.title, post.author.name, DateTime.Parse(post.createdAt.ToString()), msg), room); } LastUpdate = DateTime.Parse(post.createdAt.ToString()); } Lock = false; }
private void NotifyRooms(Bot bot, ProjectModel project) { foreach (var room in bot.Rooms) { bot.Say( string.Format("TeamCity Build Server: {0} / {1} - {2} ({3}) ", project.BuildConfigName, project.ProjectName, project.LastBuildTime, project.LastBuildStatus), room); } }
public bool Handle(ChatMessage message, Bot bot) { var acceptedCommands = new string[] {bot.Name + " help", "@" + bot.Name + " help"}; if (acceptedCommands.Contains(message.Content.Trim())) { bot.PrivateReply(message.FromUser, "A list of commands this bot currently supports:\n\thelp"); return true; } return false; }
public void Execute(Bot bot) { if (Lock == true) return; Lock = true; Debug.WriteLine(string.Format("Fetching from BitBucket! - {0:HH.mm.ss}", DateTime.Now)); var client = new WebClient(); ExecuteFollowers(bot, client); ExecuteCommits(bot, client); ExecutePullRequests(bot, client); ExecuteIssues(bot, client); Lock = false; }
public void Execute(Bot bot) { var offset = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time"); var startingPoint = DateTime.UtcNow; var now = startingPoint.Add(offset.BaseUtcOffset); if (offset.IsDaylightSavingTime(startingPoint)) now = now.AddHours(1); var message = string.Format("The time in AEDST (Sydney time) is now {0}", now.ToString("hh:mm:ss tt, dd MMMM yyyy")); foreach (var room in bot.Rooms) { bot.Say(message, room); } }
private static bool TryCreateRoomIfNotExists(string roomName, Bot bot) { try { bot.CreateRoom(roomName); } catch (AggregateException e) { if (!e.GetBaseException().Message.Equals(string.Format("The room '{0}' already exists", roomName), StringComparison.OrdinalIgnoreCase)) { return false; } } return true; }
/// <summary> /// This method uses 2 configuration variables, feed list, and hour threshold see private members /// Using these 2, it will download the XML feed from the supplied feeds /// Comparing the publish date of each post, if less than X hours old, will announce new posts to the bot.Rooms /// If there are no new posts it will be silent /// based on a hard coded interval of 90 minutes for each blog feed check /// </summary> /// <param name="bot"></param> public void Execute(Bot bot) { var userAndUrlPairs = BuildUserNameAndBlogUrlPairs(bot); foreach (var pair in userAndUrlPairs) { //check feed (only 10 most recent) var feed = RssReader.ProcessEntireFeed(pair.Url).Take(10); //if something new //compose message for Jabbr int hoursOld; if (!Int32.TryParse(_hoursOldThreshold, out hoursOld)) hoursOld = 48; //failed to read from config default to 48 hours var newEntries = feed.Where(f => Math.Abs((DateTime.Now - f.PublishDate).TotalHours) < hoursOld).ToList(); if (newEntries.Any()) { var makePlural = ""; if (newEntries.Count > 1) makePlural = "s"; //some formatting about blog post, some meta data //take this as an opportunity to show the command to add another subscription var message = String.Format("New post{2} from {0}{1}", pair.User, Environment.NewLine, makePlural); foreach (var entry in newEntries) { /*if(String.IsNullOrWhiteSpace(entry.Summary)) entry.Summary = entry.PostText.Substring(0, 100) + " ... ";*/ message += String.Format("Title: {0}{2}Link: {1}{2}", entry.Title, entry.Url, Environment.NewLine); } //deliver to channels foreach (var room in bot.Rooms) { bot.Say(message, room); } } } }
public void Execute(Bot bot) { var now = DateTime.Now; Debug.WriteLine(string.Format("Fetching from tha twatters! - {0:HH.mm.ss} < {1:HH.mm.ss}", lastRun, now)); lastRun = now; var twitterService = new TwitterService(ConsumerKey, ConsumerSecret); twitterService.AuthenticateWith(Token, TokenSecret); List<TwitterStatus> latestTweets; if (latestTweet == null) { latestTweets = twitterService.ListTweetsOnSpecifiedUserTimeline(TwitterUserName, tweetLimit).ToList(); } else { latestTweets = twitterService.ListTweetsOnSpecifiedUserTimelineSince(TwitterUserName, latestTweet.Id, tweetLimit).ToList(); } if (!latestTweets.Any()) { return; } latestTweet = latestTweets.First(); foreach (var room in bot.Rooms) { bot.Say(string.Format("Latests tweets from @{0}", TwitterUserName), room); foreach (var tweet in latestTweets) { bot.Say(tweet.TextDecoded, room); } } }
static void Main() { Console.WriteLine("Connecting to {0}...", ServerUrl); var bot = new Bot(ServerUrl, "cyberzed-jibbr", "somepassword"); bot.PowerUp(); if (!TryCreateRoomIfNotExists(RoomName, bot)) { Console.Write("Could not create room {0}. Exiting..."); bot.ShutDown(); return; } bot.Say("Hello world!", RoomName); Console.Write("Press any key to quit..."); Console.ReadKey(); bot.ShutDown(); }
private void Update(Bot bot, ProjectModel project) { if (Projects.Contains(project.ProjectName)) { if (MappedProjects.All(x => x.ProjectName != project.ProjectName)) { MappedProjects.Add(project); NotifyRooms(bot, project); } else { var mappedProject = MappedProjects.FirstOrDefault(x => x.ProjectName == project.ProjectName); if (mappedProject != null) { if (project.LastBuildTime != mappedProject.LastBuildTime) { MappedProjects.Remove(mappedProject); MappedProjects.Add(project); NotifyRooms(bot, project); } } } } }
private IEnumerable<UserAndBlogPair> BuildUserNameAndBlogUrlPairs(Bot bot) { var blogs = _feedList.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(r => r.Trim()).ToList(); var userAndUrlPairs = new List<UserAndBlogPair>(); // Sorry this looks fragile, but haven't refactored it yet. try { for (var p = 0; p < blogs.Count(); p++) { if (p % 2 == 0) userAndUrlPairs.Add(new UserAndBlogPair { User = blogs[p] }); else { userAndUrlPairs.Last().Url = blogs[p]; } } var x = userAndUrlPairs.Count; } catch (Exception) { foreach (var room in bot.Rooms) { bot.Say("Having some trouble processing user and feed configuration, expecting pairs of users and feeds, comma delimited", room); } } return userAndUrlPairs; }
protected override void ProcessMatch(Match match, ChatMessage message, Bot bot) { bot.Say("http://xamldev.dk/IPityTheFool.gif", message.Receiver); }
private void ExecutePullRequests(Bot bot, WebClient client) { var pr = GetOpenedPullRequests(client).ToList(); foreach (var c in pr.Where(c => DateTime.Parse(c.created_on.ToString()) > LastUpdate_PROpen && DateTime.Parse(c.created_on.ToString()) > DateTime.Now.AddDays(-1)).OrderBy(c => DateTime.Parse(c.created_on.ToString()))) { foreach (var room in bot.Rooms) { bot.Say( string.Format("Pull request submitted to {0}/{1} - {2} ({3})", User, Repository, c.user == null ? "" : c.user.username.ToString(), DateTime.Parse(c.created_on.ToString())), room); } LastUpdate_PROpen = DateTime.Parse(c.created_on.ToString()); } pr = GetClosedPullRequests(client).ToList(); foreach (var c in pr.Where(c => DateTime.Parse(c.created_on.ToString()) > LastUpdate_PRClosed && DateTime.Parse(c.created_on.ToString()) > DateTime.Now.AddDays(-1)).OrderBy(c => DateTime.Parse(c.created_on.ToString()))) { foreach (var room in bot.Rooms) { bot.Say( string.Format("Pull request closed {0}/{1} - {2} ({3})", User, Repository, c.user == null ? "" : c.user.username.ToString(), DateTime.Parse(c.created_on.ToString())), room); } LastUpdate_PRClosed = DateTime.Parse(c.created_on.ToString()); } }
private void ExecuteIssues(Bot bot, WebClient client) { var issues = GetOpenedIssues(client).ToList(); foreach (var i in issues.Where(i => DateTime.Parse(i.created_on.ToString()) > LastUpdate_IssuesOpen && DateTime.Parse(i.created_on.ToString()) > DateTime.Now.AddDays(-1)).OrderBy(i => DateTime.Parse(i.created_on.ToString()))) { foreach (var room in bot.Rooms) { bot.Say( string.Format("Issue opened {0}/{1} - {2} ({3}) {4}", User, Repository, i.reported_by == null ? "" : i.reported_by.username.ToString(), DateTime.Parse(i.created_on.ToString()), i.content == null ? "" : "- " + i.content.ToString()), room); } LastUpdate_IssuesOpen = DateTime.Parse(i.created_on.ToString()); } issues = GetOtherIssues(client).ToList(); foreach (var i in issues.Where(i => DateTime.Parse(i.created_on.ToString()) > LastUpdate_IssuesOther && DateTime.Parse(i.created_on.ToString()) > DateTime.Now.AddDays(-1)).OrderBy(i => DateTime.Parse(i.created_on.ToString()))) { foreach (var room in bot.Rooms) { bot.Say( string.Format("Issue updated to {0} {1}/{2} - {3} ({4}) {5}", i.@status == null ? "" : "- " + i.@status, User, Repository, i.reported_by == null ? "" : i.reported_by.username.ToString(), DateTime.Parse(i.created_on.ToString()), i.content == null ? "" : "- " + i.content.ToString()), room); } LastUpdate_IssuesOther = DateTime.Parse(i.created_on.ToString()); } }
private void ExecuteFollowers(Bot bot, WebClient client) { var followers = GetFollowers(client).ToList(); // Probably the first time run, so don't notify about every follower if (Followers.Count == 0 && followers.Count > 5) Followers = followers; foreach (var f in followers.Where(f => !Followers.Contains(f)).OrderBy(f => f)) { foreach (var room in bot.Rooms) { bot.Say( string.Format("{0}/{1} Now followed by {2}", User, Repository, f), room); Followers.Add(f); } } }
private void ExecuteCommits(Bot bot, WebClient client) { var commits = GetCommits(client).ToList(); foreach (var c in commits.Where(c => DateTime.Parse(c.created_on.ToString()) > LastUpdate_Commits && DateTime.Parse(c.created_on.ToString()) > DateTime.Now.AddDays(-1)).OrderBy(c => DateTime.Parse(c.created_on.ToString()))) { foreach (var room in bot.Rooms) { bot.Say( string.Format("Commit to {0}/{1} - {2} ({3}) {4}", User, Repository, c.user == null ? "" : c.user.username.ToString(), DateTime.Parse(c.created_on.ToString()), c.description == null ? "" : "- " + c.description.ToString()), room); } LastUpdate_Commits = DateTime.Parse(c.created_on.ToString()); } }