diff --git a/DisCatSharp.ThirdPartyLookups/ThirdPartyLookupExtension.cs b/DisCatSharp.ThirdPartyLookups/ThirdPartyLookupExtension.cs index e45483c1b..5172ccc66 100644 --- a/DisCatSharp.ThirdPartyLookups/ThirdPartyLookupExtension.cs +++ b/DisCatSharp.ThirdPartyLookups/ThirdPartyLookupExtension.cs @@ -1,89 +1,89 @@ // This file is part of the DisCatSharp project, based off DSharpPlus. // // Copyright (c) 2021-2022 AITSYS // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; using DisCatSharp.Entities; using DisCatSharp.ThirdPartyLookups.Entities; using DisCatSharp.ThirdPartyLookups.Exceptions; using Newtonsoft.Json; namespace DisCatSharp.ThirdPartyLookups; /// /// The third party lookup extension. /// public class ThirdPartyLookupExtension : BaseExtension { /// /// DO NOT USE THIS MANUALLY. /// /// DO NOT USE THIS MANUALLY. /// protected override void Setup(DiscordClient client) { if (this.Client != null) throw new InvalidOperationException("What did I tell you?"); this.Client = client; } /// /// Gets a mee6 leaderboard based of a DiscordGuild. /// /// The guild to fetch. /// /// Thrown if no guild id was provided. /// Thrown if the guild was not found. public async Task GetMee6Leaderboard(DiscordGuild Guild) => await this.GetMee6Leaderboard(Guild.Id); /// /// Gets a mee6 leaderboard based of a guild id. /// /// The guild id to fetch. /// /// Thrown if no guild id was provided. /// Thrown if the guild was not found. public async Task GetMee6Leaderboard(ulong GuildId) { if (GuildId == 0) throw new ArgumentException("Please provide a valid guild id."); var client = new HttpClient(); - client.DefaultRequestHeaders.Add("User-Agent", $"DisCatSharp.ThirdPartyLookups"); - client.DefaultRequestHeaders.Add("Accept", "application/json"); - client.DefaultRequestHeaders.Add("Content-Type", "application/json"); + client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", $"DisCatSharp.ThirdPartyLookups"); + client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/json"); + client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); var response = await client.GetAsync($"https://mee6.xyz/api/plugins/levels/leaderboard/{GuildId}"); var mee6 = JsonConvert.DeserializeObject(await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync()); return mee6 is null ? throw new NotFoundException() : mee6; } }