private static void HandleEventLoop(IrcDotNet.IrcClient client) { bool isExit = false; while (!isExit) { Console.Write("> "); var command = Console.ReadLine(); switch (command) { case "exit": isExit = true; break; default: if (!string.IsNullOrEmpty(command)) { if (command.StartsWith("/") && command.Length > 1) { client.SendRawMessage(command.Substring(1)); } else { Console.WriteLine("unknown command '{0}'", command); } } break; } } client.Disconnect(); }
private static void HandleEventLoop(IrcClient client) { _ircLocaluser = client.LocalUser; _hostNameToWebSockets.Add("", new WebSocketListenerClient(PrivateConstants.TestAccountWebsocketAuth)); _hostNameToWebSockets[""].Run(sendToIrcProcessor); bool isExit = false; while (!isExit) { Console.Write("> "); var command = Console.ReadLine(); switch (command) { case "exit": isExit = true; break; default: if (!string.IsNullOrEmpty(command)) { if (command.StartsWith("/") && command.Length > 1) { client.SendRawMessage(command.Substring(1)); } else { Console.WriteLine($"Unknown command '{command}'"); } } break; } } client.Disconnect(); }
public ActionResult Irc() { var api = new AppHarborApi(new AuthInfo { AccessToken = ConfigurationManager.AppSettings["authToken"] }); var latestBuild = api.GetBuilds(Constants.AppHarborAppName).First(); var testResults = api.GetTests(Constants.AppHarborAppName, latestBuild.ID); List<AppHarbor.Model.Test> allTests = new List<AppHarbor.Model.Test>(); foreach (var testresult in testResults) { FillTests(allTests, testresult); } AutoResetEvent are = new AutoResetEvent(false); IrcDotNet.IrcClient client = new IrcDotNet.IrcClient(); try { client.Connect("irc.gamesurge.net", false, new IrcUserRegistrationInfo() { NickName = "crymono-build", RealName = "crymono", UserName = "******" }); client.ClientInfoReceived += (s, e) => are.Set(); are.WaitOne(); client.Channels.Join(new string[] { "#crymono" }); Thread.Sleep(200); string msg = latestBuild.Commit.Message.Replace("\n", "").Replace("\r", ""); client.LocalUser.SendMessage("#crymono", "Build finished, latest commit: " + msg); Thread.Sleep(200); int numPassedTests = allTests.Count(t => t.Status == "Passed"); float percentage = (float)numPassedTests / allTests.Count * 100; client.LocalUser.SendMessage("#crymono", String.Format("Test results: {0} of {1} passed ({2:0}%) - http://crymono.apphb.com/#!/{3} - AppHB: https://appharbor.com/applications/crymonobuild/builds/{3}/tests", numPassedTests, allTests.Count, percentage, latestBuild.ID )); Thread.Sleep(200); } finally { if (client != null && client.IsConnected) { client.Quit("to the hills!"); Thread.Sleep(200); client.Disconnect(); } } return Content("OK"); }
public Bot() { commands = Command.GetCommands(this); IsInChannel = false; IsIdentified = false; IsRunning = true; // Initialize commands foreach(Command command in commands) command.Initialize(); client = new IrcClient { FloodPreventer = new IrcStandardFloodPreventer(4, 2000) }; // TODO Nasty... connectedEvent = new ManualResetEventSlim(false); client.Connected += (sender, e) => connectedEvent.Set(); client.Connected += (sender, args) => Console.WriteLine("Connected!"); client.Disconnected += (sender, args) => { const int MaxRetries = 16; int tries = 0; if (!IsRunning) { Console.WriteLine("Disconnected and IsRunning == false, assuming graceful shutdown..."); return; } IsInChannel = false; IsIdentified = false; // Wait a little so the server doesn't block us from rejoining (flood control) Console.WriteLine("Lost connection, attempting to reconnect in 6 seconds..."); client.Disconnect(); Thread.Sleep(6000); // Reconnect Console.Write("Reconnecting... "); while (!Connect(Configuration.Server) && tries++ < MaxRetries) { Console.Write("\rReconnecting, attempt {0}...", tries); Thread.Sleep(1); } if (tries == MaxRetries) { Console.WriteLine("Failed."); Quit("Failed to reconnect."); return; } Console.WriteLine("Connected"); Console.Write("Joining channel... "); if (JoinChannel(Configuration.Channel)) Console.WriteLine("Success"); else { Console.WriteLine("Failed"); Quit("Failed to rejoin channel."); } }; client.Registered += (sender, args) => { IrcClient localClient = (IrcClient)sender; // Identify with server client.SendRawMessage(String.Format("ns identify {0}", Configuration.Password)); localClient.LocalUser.NoticeReceived += (o, eventArgs) => { if (eventArgs.Text.StartsWith("Password accepted")) IsIdentified = true; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(eventArgs.Text); Console.ForegroundColor = ConsoleColor.Gray; }; localClient.LocalUser.JoinedChannel += (o, eventArgs) => { IrcChannel channel = localClient.Channels.FirstOrDefault(); if (channel == null) return; Console.WriteLine("Joined channel!"); channel.MessageReceived += HandleMessage; channel.UserJoined += (sender1, userEventArgs) => { string joinMessage = String.Format("Used joined: {0}", userEventArgs.Comment ?? "No comment"); foreach (Command command in commands) command.HandlePassive(joinMessage, userEventArgs.ChannelUser.User.NickName); }; channel.UserLeft += (sender1, userEventArgs) => { string leftMessage = String.Format("Used left: {0}", userEventArgs.Comment ?? "No comment"); foreach (Command command in commands) command.HandlePassive(leftMessage, userEventArgs.ChannelUser.User.NickName); }; IsInChannel = true; }; localClient.LocalUser.LeftChannel += (o, eventArgs) => { Console.Write("Rejoining channel... "); if (JoinChannel(Configuration.Channel)) Console.WriteLine("Success"); else { Console.WriteLine("Failed"); Quit("Failed to rejoin channel."); } }; Console.WriteLine("Registered!"); }; client.Error += (sender, args) => { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("IRC Error {0}", args.Error.Message); Console.ForegroundColor = ConsoleColor.Gray; }; }
// // GET: /Notify/ public ActionResult TravisCi() { var payload = Request.Form["payload"]; JObject jsonPayload = null; if (payload != null) {jsonPayload = (JObject)JsonConvert.DeserializeObject(payload);} TimeSpan buildDuration; bool buildSuccess = true; int buildId = 0; HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.travis-ci.org/repositories.json?slug=inkdev%2FCryMono"); using (StreamReader sr = new StreamReader(webRequest.GetResponse().GetResponseStream())) { string result = sr.ReadToEnd(); var jsonResult = ((JArray)JsonConvert.DeserializeObject(result))[0]; buildDuration = TimeSpan.FromSeconds(jsonResult["last_build_duration"].Value<double>()); buildSuccess = jsonResult["last_build_status"].Value<int>() == 0; buildId = jsonResult["last_build_id"].Value<int>(); var type = jsonResult.GetType(); } // Get build log webRequest = (HttpWebRequest)HttpWebRequest.Create(String.Format("http://www.travis-ci.org/jobs/{0}.json", buildId + 1)); using (StreamReader sr = new StreamReader(webRequest.GetResponse().GetResponseStream())) { string result = sr.ReadToEnd(); var jsonResult = ((JObject)JsonConvert.DeserializeObject(result)); string log = jsonResult["log"].Value<string>(); bool buildResult = false; using (StringReader stringReader = new StringReader(log)) { string line = stringReader.ReadLine(); string summary = "No tests run"; while (line != null) { if (line.Equals("-- START TEST RUN --")) { buildResult = true; } else if (line.StartsWith("Tests run: ")) { summary = line + " - " + stringReader.ReadLine(); } else if (line.Equals("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>")) { string xmlContents = stringReader.ReadToEnd(); xmlContents = xmlContents.Substring(0, xmlContents.IndexOf("</test-results>")+15); XDocument doc = XDocument.Parse(xmlContents); AutoResetEvent are = new AutoResetEvent(false); IrcDotNet.IrcClient client = new IrcDotNet.IrcClient(); try { client.Connect("irc.gamesurge.net", false, new IrcUserRegistrationInfo() { NickName = "inkdev-build", RealName = "crymono", UserName = "******" }); client.ClientInfoReceived += (s, e) => are.Set(); are.WaitOne(); //client.Channels.Join(new string[] { "#crymono" }); Thread.Sleep(200); //string msg = latestBuild.Commit.Message.Replace("\n", "").Replace("\r", ""); string msg = "hello"; string buildStatus = buildResult ? "OK" : "FAILED"; client.LocalUser.SendMessage("#crymonobuild", String.Format("Travis build completed. Build: {0} - http://travis-ci.org/inkdev/CryMono/builds/{1}", buildStatus,buildId)); Thread.Sleep(200); var testResultsElement = doc.Element("test-results"); client.LocalUser.SendMessage("#crymonobuild", String.Format("Tests run: {0}, Errors: {1}, Failures: {2}, Inconclusive: {3}, Not run: {4}, Invalid: {5}, Ignored: {6}, Skipped: {7}, Time: {8}s", testResultsElement.Attribute("total").Value, testResultsElement.Attribute("errors").Value, testResultsElement.Attribute("failures").Value, testResultsElement.Attribute("inconclusive").Value, testResultsElement.Attribute("not-run").Value, testResultsElement.Attribute("invalid").Value, testResultsElement.Attribute("ignored").Value, testResultsElement.Attribute("skipped").Value, doc.Descendants("test-suite").First().Attribute("time").Value )); Thread.Sleep(500); var failingTests = doc.Descendants("test-case").Where( x => x.Attribute("success").Value == "False" && x.Descendants().Any(d => d.Name == "failure")).Take(3); foreach (var item in failingTests) { client.LocalUser.SendMessage("#crymonobuild", String.Format("{0}: {1}", item.Attribute("name").Value, item.Element("failure").Element("message").Value.Replace("\n",""))); Thread.Sleep(500); } if (payload == null) { client.LocalUser.SendMessage("#crymonobuild", "Something wrong: " + String.Join(",",Request.Form.AllKeys)); } else { client.LocalUser.SendMessage("#crymonobuild", "Debug for ins\\: " + payload); } Thread.Sleep(5000); } finally { if (client != null && client.IsConnected) { client.Quit("to the hills!"); Thread.Sleep(200); client.Disconnect(); } } break; } line = stringReader.ReadLine(); } } } return Content("What?"); }
private void HandleEventLoop(IrcDotNet.IrcClient client) { logger.Debug("In HandleEventLoop"); IsExit = false; while (!IsExit) { Console.Write("> "); var command = Console.ReadLine(); switch (command) { case "exit": case "quit": IsExit = true; break; default: if (!string.IsNullOrEmpty(command)) { if (command.StartsWith("limit")) { short tempLimit; if (Int16.TryParse(command.Substring(6).Trim(), out tempLimit)) { levels.LevelLimit = tempLimit; } } else if (command == "o") { if (!levels.Open) { levels.OpenQueue(); client.SendPrivateMessage(MAINCHANNEL, "/me Submissions Open"); client.SendPrivateMessage(MAINCHANNEL, "/me Submit levels with !submit"); } } else if (command == "c") { if (levels.Open) { levels.CloseQueue(); client.SendPrivateMessage(MAINCHANNEL, "/me Submissions Closed"); if (levels.FinalLevels.Count >= 0) { string plural = (levels.FinalLevels.Count != 1) ? " levels " : " level "; client.SendPrivateMessage(MAINCHANNEL, "/me " + levels.FinalLevels.Count + plural + "will be randomly picked."); client.SendPrivateMessage(MAINCHANNEL, "/me Now Playing: " + levels.CurrentLevel); Console.WriteLine(); Console.WriteLine(levels.CurrentLevel + " (" + levels.Remaining + ")"); Console.WriteLine(); PostToWebsite(); } else { client.SendPrivateMessage(MAINCHANNEL, "/me No Levels submitted."); } } } else if (command.StartsWith("s ")) { command = command.Remove(0, 2).Trim(); SaveLevel(command); } else if (command == "settings") { OpenSettingsWindow(); } else if (command == "restart") { this.Restart = true; return; } else if (command.StartsWith("v ")) { command = command.Remove(0, 2).Trim(); short vol; if (Int16.TryParse(command, out vol)) { soundPlayerVolume = vol; } } else if (command.StartsWith("max ")) { command = command.Remove(0, 4).Trim(); int amt; if (Int32.TryParse(command, out amt)) { if (amt <= 0) { break; } BotSettings.MaxSubmissionsForSingleUser = amt; Console.WriteLine("User can only submit " + amt + " level(s) per round."); Console.WriteLine(); } } else if (command.StartsWith("cool ")) { command = command.Remove(0, 5).Trim(); int tempCooldown; if (int.TryParse(command, out tempCooldown)) { cooldownSeconds = tempCooldown; } } else if (command == "q") { foreach (var level in levels.FinalLevels) { Console.WriteLine(level.Item2 + " " + level.Item1); } } else if (command.StartsWith("add ")) { string[] args = command.Split(' '); if (args.Length > 2) { if (LevelSubmitter.IsValidLevelCode(ref args[2])) { levels.ForceAddLevel(args[2].ToUpper(), args[1]); PostToWebsite(); if (levels.Remaining == 0) { Console.WriteLine(levels.CurrentLevel + " (" + levels.Remaining + ")"); } } } } else if (command == "prev") { if (levels.Remaining == levels.FinalLevels.Count) { break; } levels.PreviousLevel(); PostToWebsite(); Console.WriteLine(); Console.WriteLine(levels.CurrentLevel + " (" + levels.Remaining + ")"); Console.WriteLine(); } else if (command == "h" || command == "help") { DisplayMainMenu(); } } //ELSE - command IsNullOrEmpty - (Enter Key pressed) else { if (levels.Remaining > 0) { levels.NextLevel(); PostToWebsite(); client.SendPrivateMessage(MAINCHANNEL, "/me Now Playing: " + levels.CurrentLevel); Console.WriteLine(); Console.WriteLine(levels.CurrentLevel + " (" + levels.Remaining + ")"); Console.WriteLine(); } } break; } } client.Disconnect(); }