/// <summary> Post server count to BotBlock.org </summary> public async Task SendBotBlock(LogType type) { bool isError = false; if (Http == null) { if (Discord == null) { Log(type, LogType.Error, "Cannot post server count, Discord client is null"); isError = true; } else if (Discord.CurrentUser == null) { Log(type, LogType.Error, "Cannot post server count, CurrentUser is null"); isError = true; } Http = new HttpClient(); Http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); Http.DefaultRequestHeaders.Add("User-Agent", $"BotListAPI {Version} - " + Discord.CurrentUser.ToString()); } if (!isError) { ListJson Json = Config.GetJson(); Json.SetCount(Discord); string JsonString = JsonConvert.SerializeObject(Json); try { StringContent Content = new StringContent(JsonString, Encoding.UTF8, "application/json"); Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage Res = await Http.PostAsync("https://botblock.org/api/count", Content); if (Res.IsSuccessStatusCode) { Log(type, LogType.Info, $"Successfully posted server count to BotBlock"); Log(type, LogType.Debug, "Request response in JSON\n" + JsonConvert.SerializeObject(Res, Formatting.Indented)); } else { Log(type, LogType.Error, $"Error could not post server count to BotBlock, {(int)Res.StatusCode} {Res.ReasonPhrase}"); Log(type, LogType.Debug, "Request response in JSON\n" + JsonConvert.SerializeObject(Res, Formatting.Indented)); } } catch (Exception ex) { Log(type, LogType.Error, $"Error could not post server count to BotBlock, {ex.Message}"); Log(type, LogType.Debug, "Exception\n" + ex.ToString()); } } }
public ListJson GetJson() { ListJson Json = new ListJson(); PropertyDescriptorCollection sourceproperties = TypeDescriptor.GetProperties(new ListConfig()); PropertyDescriptorCollection targetproperties = TypeDescriptor.GetProperties(new ListJson()); foreach (PropertyDescriptor pd in targetproperties) { foreach (PropertyDescriptor _pd in sourceproperties) { if (pd.Name == _pd.Name) { pd.SetValue(Json, _pd.GetValue(this)); } } } return(Json); }