Skip to content

Discord · Modules

2 modules · 8 exports · 1 repository · 0 e2e tests · 2 routes

Who imports who · hover a node
Depends onDiscord modulesUsed byBans.serverbanDiscordAPI.server5 expo…LinkedRoles.server3 exp…Routes2 filesActions1 fileRoutines1 file

DiscordAPI

serverapp/features/discord/core/DiscordAPI.server.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
2 routes1 module

Types

type

DiscordTokens

no JSDoc:14
export type DiscordTokens = OAuth2Strategy.VerifyOptions["tokens"];

Functions & values

const

linkedRoleStrategy

:20

OAuth flow of the linked role verification URL. Separate from log in: it asks for the role_connections.write scope and the tokens are stored to update the metadata later.

export const linkedRoleStrategy = new OAuth2Strategy<DiscordTokens>(
	{
		clientId: ServerConfig.discord.clientId,
		clientSecret: ServerConfig.discord.clientSecret,

		authorizationEndpoint: "https://discord.com/api/oauth2/authorize",
		tokenEndpoint: `${API_URL}/oauth2/token`,
		redirectURI: new URL(LINKED_ROLE_CALLBACK_URL, Config.siteDomain),

		scopes: ["identify", "role_connections.write"],
		cookie: {
			name: "discord_linked_role",
function

fetchUserId

:43

Discord id of the user the access token belongs to.

export async function fetchUserId(accessToken: string)
function

refreshTokens

:57

New tokens for the refresh token, null if Discord no longer accepts it (e.g. the user deauthorized the app).

export async function refreshTokens(
	refreshToken: string,
): Promise<DiscordTokens | null>
function

putRoleConnection

:75

Replaces the user's linked role metadata. Waits out rate limits. Resolves to "UNAUTHORIZED" if Discord no longer accepts the access token.

export async function putRoleConnection({
	accessToken,
	platformUsername,
	metadata,
}: {
	accessToken: string;
	platformUsername: string;
	metadata: SendouInkDiscordMetadata;
}): Promise<"OK" | "UNAUTHORIZED">

LinkedRoles

serverapp/features/discord/core/LinkedRoles.server.ts

No overview comment at the top of the file.

Imports
Bans.serverDiscordAPI.server
Used by
1 action1 route1 routine

Functions & values

function

saveTokens

:16

Stores the user's tokens from a finished linked role OAuth flow.

export function saveTokens(userId: number, tokens: DiscordAPI.DiscordTokens)
function

syncUser

:30

Pushes the user's current sendou.ink data (Plus tier unless banned) to Discord as their linked role metadata. Does nothing for a user who has not linked. Tokens Discord no longer accepts are deleted. Throws on other failures.

export async function syncUser(userId: number)
Unit tests (7)
function

syncUsers

:53

{@link syncUser} for each user one after another. Never throws: failures are logged and the rest carry on.

export async function syncUsers(userIds: number[])
Unit tests (1)