11import axios , { AxiosError , AxiosResponse } from "axios" ;
22import {
3+ RESTGetAPICurrentUserGuildsResult ,
34 RESTGetAPICurrentUserResult ,
5+ RESTGetCurrentUserGuildMemberResult ,
46 RESTPostOAuth2AccessTokenResult ,
57 Snowflake ,
6- RESTGetAPICurrentUserGuildsResult ,
7- RESTGetCurrentUserGuildMemberResult ,
88} from "discord-api-types/v9" ;
99import { FastifyInstance } from "fastify" ;
1010import { URLSearchParams } from "url" ;
11+
1112import { discordAPIBaseURL , requiredScopes } from "./constants" ;
1213import {
1314 ExpectedOauth2Failure ,
@@ -83,15 +84,15 @@ class DiscordOauthRequests {
8384 cacheExpiry ?: number ;
8485 userId ?: Snowflake ;
8586 } ) : Promise < UncachedResponse | CachedResponse > {
86- if ( cacheExpiry && userId ) {
87+ if ( cacheExpiry !== undefined && userId !== undefined ) {
8788 // TODO: Should cacheExpiry be checked / used
8889 // Requests without a token are not cached
8990 const cachedResponse = ( await this . _instance . redisCache . getOauthCache (
9091 path ,
9192 userId
9293 ) ) as string | null ;
9394
94- if ( cachedResponse ) {
95+ if ( cachedResponse !== null ) {
9596 return { cached : true , data : cachedResponse } ;
9697 }
9798 const response = await this . _makeRequest ( {
@@ -108,7 +109,7 @@ class DiscordOauthRequests {
108109 ) ;
109110 return response ;
110111 }
111- if ( token ) {
112+ if ( token !== undefined ) {
112113 headers = { ...headers , Authorization : `Bearer ${ token } ` } ;
113114 }
114115 let response : AxiosResponse ;
@@ -139,7 +140,8 @@ class DiscordOauthRequests {
139140 return new UnexpectedFailure (
140141 InteractionOrRequestFinalStatus . OAUTH_REQUEST_FAILED ,
141142 `Oauth request to ${
142- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions
143+ // TODO: Fix this type mess. Most likely by changing request libs
144+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions, @typescript-eslint/strict-boolean-expressions
143145 response . request . path || "Unknown path"
144146 } failed with the status ${ statusCode } `
145147 ) ;
@@ -152,7 +154,7 @@ class DiscordOauthRequests {
152154 } ) : Promise < RESTGetAPICurrentUserResult > {
153155 let cacheExpiry : number | undefined ;
154156 let response ;
155- if ( user . userId ) {
157+ if ( user . userId !== undefined ) {
156158 cacheExpiry = 1000 * 60 * 5 ; // 5 minutes
157159 response = await this . _makeRequest ( {
158160 path : "/users/@me" ,
0 commit comments