Skip to content

Commit

Permalink
chore: use Endpoints.ME instead of "/@me"
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Jan 9, 2024
1 parent 289b025 commit c82e815
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
12 changes: 11 additions & 1 deletion DisCatSharp/Clients/DiscordOAuth2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public string BotLibrary
/// </summary>
internal static TimeSpan EventExecutionLimit { get; } = TimeSpan.FromMinutes(1);

/// <summary>
/// Gets the discord client.
/// </summary>
internal DiscordClient? DiscordClient { get; }

/// <summary>
/// Gets the RSA instance.
/// </summary>
Expand All @@ -100,6 +105,7 @@ public string BotLibrary
/// <param name="loggerFactory">The optional logging factory to use for this client. Defaults to null.</param>
/// <param name="minimumLogLevel">The minimum logging level for messages. Defaults to information.</param>
/// <param name="logTimestampFormat">The timestamp format to use for the logger.</param>
/// <param name="discordClient">Gets the optional discord client to populate access tokens on <see cref="DiscordUser"/> entities.</param>
public DiscordOAuth2Client(
ulong clientId,
string clientSecret,
Expand All @@ -110,12 +116,16 @@ public DiscordOAuth2Client(
bool useRelativeRateLimit = true,
ILoggerFactory loggerFactory = null!,
LogLevel minimumLogLevel = LogLevel.Information,
string logTimestampFormat = "yyyy-MM-dd HH:mm:ss zzz"
string logTimestampFormat = "yyyy-MM-dd HH:mm:ss zzz",
DiscordClient? discordClient = null
)
{
this.MinimumLogLevel = minimumLogLevel;
this.LogTimestampFormat = logTimestampFormat;

if (discordClient is not null)
this.DiscordClient = discordClient;

if (loggerFactory == null!)
{
loggerFactory = new DefaultLoggerFactory();
Expand Down
20 changes: 10 additions & 10 deletions DisCatSharp/Net/Rest/DiscordApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ internal async Task UpdateCurrentUserVoiceStateAsync(ulong guildId, ulong channe
RequestToSpeakTimestamp = requestToSpeakTimestamp
};

var route = $"{Endpoints.GUILDS}/:guild_id{Endpoints.VOICE_STATES}/@me";
var route = $"{Endpoints.GUILDS}/:guild_id{Endpoints.VOICE_STATES}{Endpoints.ME}";
var bucket = this.Rest.GetBucket(RestRequestMethod.PATCH, route, new
{
guild_id = guildId
Expand Down Expand Up @@ -3518,7 +3518,7 @@ internal async Task<DiscordMessage> CrosspostMessageAsync(ulong channelId, ulong
/// Gets the current user async.
/// </summary>
internal Task<DiscordUser> GetCurrentUserAsync()
=> this.GetUserAsync("@me");
=> this.GetUserAsync(Endpoints.ME);

/// <summary>
/// Gets the user async.
Expand Down Expand Up @@ -6788,7 +6788,7 @@ internal async Task DeleteTestEntitlementsAsync(ulong applicationId, ulong entit
/// Gets the current application info via oauth2.
/// </summary>
internal Task<TransportApplication> GetCurrentApplicationOauth2InfoAsync()
=> this.GetApplicationOauth2InfoAsync("@me");
=> this.GetApplicationOauth2InfoAsync(Endpoints.ME);

/// <summary>
/// Gets the application rpc info.
Expand Down Expand Up @@ -6982,7 +6982,7 @@ internal async Task<DiscordAuthorizationInformation> GetCurrentOAuth2Authorizati
throw new InvalidOperationException("Cannot use oauth2 endpoints with discord client");

// ReSharper disable once HeuristicUnreachableCode
var route = $"{Endpoints.OAUTH2}/@me";
var route = $"{Endpoints.OAUTH2}{Endpoints.ME}";
var bucket = this.Rest.GetBucket(RestRequestMethod.GET, route, new
{ }, out var path);

Expand All @@ -7006,7 +7006,7 @@ internal async Task<DiscordUser> GetCurrentUserAsync(string accessToken)
throw new InvalidOperationException("Cannot use oauth2 endpoints with discord client");

// ReSharper disable once HeuristicUnreachableCode
var route = $"{Endpoints.USERS}/@me";
var route = $"{Endpoints.USERS}{Endpoints.ME}";
var bucket = this.Rest.GetBucket(RestRequestMethod.GET, route,
new
{
Expand All @@ -7033,7 +7033,7 @@ internal async Task<IReadOnlyList<DiscordConnection>> GetCurrentUserConnectionsA
throw new InvalidOperationException("Cannot use oauth2 endpoints with discord client");

// ReSharper disable once HeuristicUnreachableCode
var route = $"{Endpoints.USERS}/@me{Endpoints.CONNECTIONS}";
var route = $"{Endpoints.USERS}{Endpoints.ME}{Endpoints.CONNECTIONS}";
var bucket = this.Rest.GetBucket(RestRequestMethod.GET, route, new
{ }, out var path);

Expand All @@ -7056,7 +7056,7 @@ internal async Task<IReadOnlyList<DiscordGuild>> GetCurrentUserGuildsAsync(strin
throw new InvalidOperationException("Cannot use oauth2 endpoints with discord client");

// ReSharper disable once HeuristicUnreachableCode
var route = $"{Endpoints.USERS}/@me{Endpoints.GUILDS}";
var route = $"{Endpoints.USERS}{Endpoints.ME}{Endpoints.GUILDS}";
var bucket = this.Rest.GetBucket(RestRequestMethod.GET, route, new
{ }, out var path);

Expand All @@ -7080,7 +7080,7 @@ internal async Task<DiscordMember> GetCurrentUserGuildMemberAsync(string accessT
throw new InvalidOperationException("Cannot use oauth2 endpoints with discord client");

// ReSharper disable once HeuristicUnreachableCode
var route = $"{Endpoints.USERS}/@me{Endpoints.GUILDS}/:guild_id{Endpoints.MEMBER}";
var route = $"{Endpoints.USERS}{Endpoints.ME}{Endpoints.GUILDS}/:guild_id{Endpoints.MEMBER}";
var bucket = this.Rest.GetBucket(RestRequestMethod.GET, route, new
{
guild_id = guildId.ToString(CultureInfo.InvariantCulture)
Expand All @@ -7106,7 +7106,7 @@ internal async Task<DiscordApplicationRoleConnection> GetCurrentUserApplicationR
throw new InvalidOperationException("Cannot use oauth2 endpoints with discord client");

// ReSharper disable once HeuristicUnreachableCode
var route = $"{Endpoints.USERS}/@me{Endpoints.APPLICATIONS}/:application_id/{Endpoints.ROLE_CONNECTIONS}";
var route = $"{Endpoints.USERS}{Endpoints.ME}{Endpoints.APPLICATIONS}/:application_id/{Endpoints.ROLE_CONNECTIONS}";
var bucket = this.Rest.GetBucket(RestRequestMethod.GET, route,
new
{
Expand Down Expand Up @@ -7142,7 +7142,7 @@ internal Task ModifyCurrentUserApplicationRoleConnectionAsync(string accessToken
};

// ReSharper disable once HeuristicUnreachableCode
var route = $"{Endpoints.USERS}/@me{Endpoints.APPLICATIONS}/:application_id/{Endpoints.ROLE_CONNECTIONS}";
var route = $"{Endpoints.USERS}{Endpoints.ME}{Endpoints.APPLICATIONS}/:application_id/{Endpoints.ROLE_CONNECTIONS}";
var bucket = this.Rest.GetBucket(RestRequestMethod.PUT, route, new
{
application_id = this.OAuth2Client.ClientId.ToString(CultureInfo.InvariantCulture)
Expand Down

0 comments on commit c82e815

Please sign in to comment.