rmsoft1

R1 Status v2.0 [Snippet]

Jun 8th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.31 KB | None | 0 0
  1.        
  2.  
  3.         private static int CheckEventR1()
  4.         {
  5.  
  6.             try
  7.             {
  8.                 HttpWebRequest wc = WebRequest.CreateHttp("http://events.rewards1.com/socket.io.js");
  9.                 wc.Method = "GET";
  10.                 wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
  11.                 HttpWebResponse wr = wc.GetResponse() as HttpWebResponse;
  12.                 return (int)wr.StatusCode;
  13.             }
  14.             catch (System.Net.WebException ex)
  15.             {
  16.                
  17.                 var resp = (HttpWebResponse)ex.Response;
  18.                 return (int)resp.StatusCode;
  19.             }
  20.             catch (Exception)
  21.             {
  22.                
  23.                 return -100;
  24.             }
  25.         }
  26.  
  27.         private static int CheckHpR1()
  28.         {
  29.  
  30.             try
  31.             {
  32.                 HttpWebRequest wc = WebRequest.CreateHttp("http://rewards1.com");
  33.                 wc.Method = "GET";
  34.                 wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
  35.                 HttpWebResponse wr = wc.GetResponse() as HttpWebResponse;
  36.                 return (int)wr.StatusCode;
  37.             }
  38.             catch (System.Net.WebException ex)
  39.             {
  40.                
  41.                 var resp = (HttpWebResponse)ex.Response;
  42.                 return (int)resp.StatusCode;
  43.             }
  44.             catch (Exception)
  45.             {
  46.                
  47.                 return -100;
  48.             }
  49.         }
  50.  
  51.         private static int CheckAjaxR1()
  52.         {
  53.  
  54.             try
  55.             {
  56.                 HttpWebRequest wc = WebRequest.CreateHttp("http://rewards1.com/ajax/home.php?function=load&fp=0");
  57.                 wc.Method = "GET";
  58.                 wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
  59.                 HttpWebResponse wr = wc.GetResponse() as HttpWebResponse;
  60.                 return (int)wr.StatusCode;
  61.             }
  62.             catch (System.Net.WebException ex)
  63.             {
  64.  
  65.                 var resp = (HttpWebResponse)ex.Response;
  66.                 return (int)resp.StatusCode;
  67.             }
  68.             catch (Exception)
  69.             {
  70.  
  71.                 return -100;
  72.             }
  73.         }
  74.  
  75.         /// <summary>
  76.         /// DoR1Check - EXEC
  77.         /// </summary>
  78.         /// <param name="Context"></param>
  79.         /// <param name="param"></param>
  80.         public static void DoR1Check(IUserMessage Context, string param)
  81.         {
  82.             IDisposable o = Context.Channel.EnterTypingState();
  83.             int code = CheckEventR1();
  84.             int code2 = CheckHpR1();
  85.             int codeAjax = CheckAjaxR1();
  86.             bool res = code < 400 && code2 < 400;
  87.             bool res2 = codeAjax < 400;
  88.             if (res)
  89.             {
  90.                 EmbedBuilder builder = new EmbedBuilder();
  91.                 builder.Color = Color.Green;
  92.                 builder.AddField("`R1 Main`", "Status-code: `" + code2 + "`");
  93.                 builder.AddField("`R1 Events`", "Status-code: `" + code + "`");
  94.                 builder.AddField("`R1 AJAX`", "Status-code: `" + codeAjax + "`");
  95.                 builder.WithAuthor("Rewards1.com Status: Available");
  96.                 builder.WithDescription("No problems are detected at this time.");
  97.                 builder.WithFooter("ArcadeCORE - RMSoftware.ModularBot");
  98.                 Context.Channel.SendMessageAsync("", false, builder.Build());
  99.                 o.Dispose();
  100.             }
  101.             if (res & !res2)
  102.             {
  103.                 EmbedBuilder builder = new EmbedBuilder();
  104.                 builder.Color = Color.Orange;
  105.                 builder.AddField("`R1 Main`", "Status-code: `" + code2 + "`");
  106.                 builder.AddField("`R1 Events`", "Status-code: `" + code + "`");
  107.                 builder.AddField("`R1 AJAX`", "Status-code: `" + codeAjax + "`");
  108.                 builder.WithAuthor("Rewards1.com Status: WARNING.");
  109.                 builder.WithDescription("Some portions of the site may not load correctly.");
  110.                 builder.WithFooter("ArcadeCORE - RMSoftware.ModularBot");
  111.                 Context.Channel.SendMessageAsync("", false, builder.Build());
  112.                 o.Dispose();
  113.             }
  114.             if (!res)
  115.             {
  116.                 EmbedBuilder builder = new EmbedBuilder();
  117.                 builder.Color = Color.Red;
  118.                 builder.AddField("`R1 Main`", "Status-code: `" + code2 + "`");
  119.                 builder.AddField("`R1 Events`", "Status-code: `" + code + "`");
  120.                 builder.AddField("`R1 AJAX`", "Status-code: `" + codeAjax + "`");
  121.                 builder.WithAuthor("Rewards1.com Status: Unavailable");
  122.                 if(code >= 400)
  123.                 {
  124.                     builder.WithDescription("The R1 Events server is currently down. This will affect a major portion of the site.");
  125.                 }
  126.                 if(code2 >= 400)
  127.                 {
  128.                     builder.WithDescription("The entire site is currently down.");
  129.                 }
  130.                 builder.WithFooter("ArcadeCORE - RMSoftware.ModularBot");
  131.                 Context.Channel.SendMessageAsync("", false, builder.Build());
  132.                 o.Dispose();
  133.             }
  134.         }
Advertisement
Add Comment
Please, Sign In to add comment