-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial User structure, for comments
- Loading branch information
Showing
6 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './users'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import type { APIConnection } from 'discord-api-types/v10'; | ||
|
||
/** | ||
* Represents a user's connection on Discord. | ||
*/ | ||
export class Connection { | ||
public constructor( | ||
/** | ||
* The raw data received from the API for the connection | ||
*/ | ||
protected raw: APIConnection, | ||
) {} | ||
|
||
/** | ||
* The id of the connection account | ||
*/ | ||
public get id() { | ||
return this.raw.id; | ||
} | ||
|
||
/** | ||
* The username of the connection account | ||
*/ | ||
public get name() { | ||
return this.raw.name; | ||
} | ||
|
||
/** | ||
* The type of service this connection is for | ||
*/ | ||
public get type() { | ||
return this.raw.type; | ||
} | ||
|
||
/** | ||
* Whether the connection is revoked | ||
*/ | ||
public get revoked() { | ||
return this.raw.revoked ?? false; | ||
} | ||
|
||
/** | ||
* Any integrations associated with this connection | ||
*/ | ||
public get integrations() { | ||
return this.raw.integrations ?? null; | ||
} | ||
|
||
/** | ||
* Whether the connection is verified | ||
*/ | ||
public get verified() { | ||
return this.raw.verified; | ||
} | ||
|
||
/** | ||
* Whether friend sync is enabled for this connection | ||
*/ | ||
public get friendSync() { | ||
return this.raw.friend_sync; | ||
} | ||
|
||
/** | ||
* Whether activities related to this connection are shown in the users presence | ||
*/ | ||
public get showActivity() { | ||
return this.raw.show_activity; | ||
} | ||
|
||
/** | ||
* The visibilty state for this connection | ||
*/ | ||
public get visibility() { | ||
return this.raw.visibility; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { DiscordSnowflake } from '@sapphire/snowflake'; | ||
import type { APIUser, Snowflake } from 'discord-api-types/v10'; | ||
|
||
/** | ||
* Represents any user on Discord. | ||
*/ | ||
export class User { | ||
public constructor( | ||
/** | ||
* The raw data received from the API for the user | ||
*/ | ||
protected raw: APIUser, | ||
) {} | ||
|
||
/** | ||
* The user's id | ||
*/ | ||
public get id(): Snowflake { | ||
return this.raw.id; | ||
} | ||
|
||
/** | ||
* The username of the user | ||
*/ | ||
public get username() { | ||
return this.raw.username; | ||
} | ||
|
||
/** | ||
* The user's 4 digit tag, in combination with the username can uniquely identify the user | ||
*/ | ||
public get discriminator() { | ||
return this.raw.discriminator; | ||
} | ||
|
||
/** | ||
* The user avatar's hash | ||
*/ | ||
public get avatar() { | ||
return this.raw.avatar; | ||
} | ||
|
||
/** | ||
* Whether the user is a bot | ||
*/ | ||
public get bot() { | ||
return this.raw.bot ?? false; | ||
} | ||
|
||
/** | ||
* Whether the user is an Official Discord System user | ||
*/ | ||
public get system() { | ||
return this.raw.system ?? false; | ||
} | ||
|
||
/** | ||
* Whether the user has mfa enabled | ||
* <info>This property is only set when the user was fetched with an OAuth2 token and the `identify` scope</info> | ||
*/ | ||
public get mfaEnabled() { | ||
return this.raw.mfa_enabled; | ||
} | ||
|
||
/** | ||
* The user's banner hash | ||
* <info>This property is only set when the user was manually fetched</info> | ||
*/ | ||
public get banner() { | ||
return this.raw.banner; | ||
} | ||
|
||
/** | ||
* The base 10 accent color of the user's banner | ||
* <info>This property is only set when the user was manually fetched</info> | ||
*/ | ||
public get accentColor() { | ||
return this.raw.accent_color; | ||
} | ||
|
||
/** | ||
* The user's primary discord language | ||
* <info>This property is only set when the user was fetched with an Oauth2 token and the `identify` scope</info> | ||
*/ | ||
public get locale() { | ||
return this.raw.locale; | ||
} | ||
|
||
/** | ||
* Whether the email on the user's account has been verified | ||
* <info>This property is only set when the user was fetched with an OAuth2 token and the `email` scope</info> | ||
*/ | ||
public get verified() { | ||
return this.raw.verified; | ||
} | ||
|
||
/** | ||
* The user's email | ||
* <info>This property is only set when the user was fetched with an OAuth2 token and the `email` scope</info> | ||
*/ | ||
public get email() { | ||
return this.raw.email; | ||
} | ||
|
||
/** | ||
* The type of nitro subscription on the user's account | ||
* <info>This property is only set when the user was fetched with an OAuth2 token and the `identify` scope</info> | ||
*/ | ||
public get premiumType() { | ||
return this.raw.premium_type; | ||
} | ||
|
||
/** | ||
* The flags for the user | ||
*/ | ||
public get flags() { | ||
return this.raw.public_flags; | ||
} | ||
|
||
/** | ||
* The timestamp the user was created at | ||
*/ | ||
public get createdTimestamp() { | ||
return DiscordSnowflake.timestampFrom(this.id); | ||
} | ||
|
||
/** | ||
* The time the user was created at | ||
*/ | ||
public get createdAt() { | ||
return new Date(this.createdTimestamp); | ||
} | ||
|
||
/** | ||
* The hexadecimal version of the user accent color, with a leading hash | ||
* <info>This property is only set when the user was manually fetched</info> | ||
*/ | ||
public get hexAccentColor() { | ||
if (typeof this.accentColor !== 'number') return this.accentColor; | ||
return `#${this.accentColor.toString(16).padStart(6, '0')}`; | ||
} | ||
|
||
/** | ||
* The Discord "tag" (e.g. `hydrabolt#0001`) for this user | ||
*/ | ||
public get tag() { | ||
return `${this.username}#${this.discriminator}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './Connection'; | ||
export * from './User'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters