[Aliases("masternode-count")] // alternative names for the command public async Task Count(CommandContext ctx) // this command takes no arguments { // let's trigger a typing indicator to let // users know we're working await ctx.TriggerTypingAsync(); string result = string.Empty; using (System.Net.Http.HttpClient _client = new System.Net.Http.HttpClient(new HttpClientHandler { Credentials = _credentials })) { RPCRequest command = new RPCRequest() { Id = "node-count", Method = "masternode", Parameters = new List <string>() { "count" } }; try { var response = await _client.PostAsync(MASTERNODE_URL, new System.Net.Http.StringContent(command.ToString())); response.EnsureSuccessStatusCode(); var json = JsonConvert.DeserializeObject <RPCResponse>(await response.Content.ReadAsStringAsync()); var emoji = DiscordEmoji.FromName(ctx.Client, ":thumbsup:"); result = $"Actually we have {json.Result} Masternodes online! Not so bad huh! {emoji}"; } catch (Exception e) { ctx.Client.DebugLogger.LogMessage(LogLevel.Error, "DBot", $"{ctx.User.Username} tried executing '{ctx.Command?.QualifiedName ?? "<unknown command>"}' but it errored: {e.GetType()}: {e.Message ?? "<no message>"}", DateTime.Now); result = ERROR; } } await ctx.RespondAsync(result); }
[Aliases("masternode-status")] // alternative names for the command public async Task Status(CommandContext ctx, string ip) { // let's trigger a typing indicator to let // users know we're working await ctx.TriggerTypingAsync(); string result = string.Empty; using (System.Net.Http.HttpClient _client = new System.Net.Http.HttpClient(new HttpClientHandler { Credentials = _credentials })) { RPCRequest command = new RPCRequest() { Id = "node-status", Method = "masternodelist", Parameters = new List <string>() { "info", ip } }; try { var response = await _client.PostAsync(MASTERNODE_URL, new System.Net.Http.StringContent(command.ToString())); response.EnsureSuccessStatusCode(); var json = JsonConvert.DeserializeObject <RPCResponse>(await response.Content.ReadAsStringAsync()); string line = ((JObject)json.Result).First.First.ToString(); string[] values = line.Split(' ').Where(lc => lc.Trim().Length > 0).ToArray(); StringBuilder c = new StringBuilder("Status : "); c.AppendLine(values[0]); c.AppendFormat("Last seen : {0:MM/dd/yyy - HH\\:mm\\:ss}\r\n", values[3].FromUnixTime()); c.Append("Up time : "); if (!string.IsNullOrEmpty(values[4])) { c.AppendLine(TimeSpan.FromSeconds(int.Parse(values[4])).ToString().Replace(".", "d ")); } else { c.AppendLine("N/A"); } c.Append("Sentinel version : "); if (!string.IsNullOrEmpty(values[5])) { c.AppendFormat("{0}", values[5]); } else { c.AppendLine("N/A"); } result = c.ToString(); } catch (Exception e) { ctx.Client.DebugLogger.LogMessage(LogLevel.Error, "DBot", $"{ctx.User.Username} tried executing '{ctx.Command?.QualifiedName ?? "<unknown command>"}' but it errored: {e.GetType()}: {e.Message ?? "<no message>"}", DateTime.Now); result = ERROR; } } await ctx.RespondAsync(result); }