feat(invites): add invites shortcuts

This commit is contained in:
Socram03 2025-04-02 16:05:41 -04:00
parent 1731d2de6b
commit ca26338a4c
8 changed files with 498 additions and 405 deletions

View File

@ -23,13 +23,13 @@
"devDependencies": { "devDependencies": {
"@biomejs/biome": "1.9.4", "@biomejs/biome": "1.9.4",
"@changesets/cli": "^2.28.1", "@changesets/cli": "^2.28.1",
"@commitlint/cli": "^19.7.1", "@commitlint/cli": "^19.8.0",
"@commitlint/config-conventional": "^19.7.1", "@commitlint/config-conventional": "^19.8.0",
"@types/node": "^22.13.5", "@types/node": "^22.14.0",
"husky": "^9.1.7", "husky": "^9.1.7",
"lint-staged": "^15.4.3", "lint-staged": "^15.5.0",
"typescript": "^5.7.3", "typescript": "^5.8.2",
"vitest": "^3.0.6" "vitest": "^3.1.1"
}, },
"homepage": "https://seyfert.dev", "homepage": "https://seyfert.dev",
"repository": { "repository": {
@ -69,5 +69,11 @@
"*.ts": [ "*.ts": [
"biome check --write" "biome check --write"
] ]
},
"pnpm": {
"onlyBuiltDependencies": [
"@biomejs/biome",
"esbuild"
]
} }
} }

796
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,7 @@ import {
EmojiShorter, EmojiShorter,
GuildShorter, GuildShorter,
InteractionShorter, InteractionShorter,
InvitesShorter,
LogLevels, LogLevels,
Logger, Logger,
type MakeRequired, type MakeRequired,
@ -81,6 +82,9 @@ export class BaseClient {
interactions = new InteractionShorter(this); interactions = new InteractionShorter(this);
voiceStates = new VoiceStateShorter(this); voiceStates = new VoiceStateShorter(this);
soundboards = new SoundboardShorter(this); soundboards = new SoundboardShorter(this);
invites = new InvitesShorter(this);
/**@internal */
debugger?: Logger; debugger?: Logger;

View File

@ -3,6 +3,8 @@ export * from './it/utils';
export * from './it/colors'; export * from './it/colors';
export { CustomizeLoggerCallback, AssignFilenameCallback, LogLevels, Logger, LoggerOptions } from './it/logger'; export { CustomizeLoggerCallback, AssignFilenameCallback, LogLevels, Logger, LoggerOptions } from './it/logger';
export * from './it/formatter'; export * from './it/formatter';
// circular lol
export * from './shorters/invites';
// //
export * from './shorters/channels'; export * from './shorters/channels';
export * from './shorters/emojis'; export * from './shorters/emojis';

View File

@ -0,0 +1,45 @@
import type { RESTPostAPIChannelInviteJSONBody } from '../../types';
import { toCamelCase } from '../it/utils';
import { BaseShorter } from './base';
export class InvitesShorter extends BaseShorter {
get(code: string) {
return this.client.proxy
.invites(code)
.get()
.then(x => toCamelCase(x));
}
delete(code: string, reason?: string) {
return this.client.proxy
.invites(code)
.delete({ reason })
.then(x => toCamelCase(x));
}
channels = {
create: ({ channelId, reason, ...body }: CreateInviteFromChannel) =>
this.client.proxy
.channels(channelId)
.invites.post({ body, reason })
.then(x => toCamelCase(x)),
list: (channelId: string) =>
this.client.proxy
.channels(channelId)
.invites.get()
.then(x => toCamelCase(x)),
};
guilds = {
list: (guildId: string) =>
this.client.proxy
.guilds(guildId)
.invites.get()
.then(x => toCamelCase(x)),
};
}
export interface CreateInviteFromChannel extends RESTPostAPIChannelInviteJSONBody {
channelId: string;
reason?: string;
}

View File

@ -104,15 +104,17 @@ export type SnakeCase<S extends string> = S extends `${infer A}${infer Rest}`
: `${A}${SnakeCase<Rest>}` : `${A}${SnakeCase<Rest>}`
: Lowercase<S>; : Lowercase<S>;
export type ObjectToLower<T> = Identify<{ export type ObjectToLower<T> = T extends unknown[]
[K in keyof T as CamelCase<Exclude<K, symbol | number>>]: T[K] extends unknown[] ? ObjectToLower<T[0]>[]
? Identify<ObjectToLower<T[K][0]>[]> : Identify<{
: T[K] extends object [K in keyof T as CamelCase<Exclude<K, symbol | number>>]: T[K] extends unknown[]
? Identify<ObjectToLower<T[K]>> ? Identify<ObjectToLower<T[K][0]>[]>
: AuxIsStrictlyUndefined<T[K]> extends true : T[K] extends object
? undefined ? Identify<ObjectToLower<T[K]>>
: ObjectToLowerUndefined<T[K]>; : AuxIsStrictlyUndefined<T[K]> extends true
}>; ? undefined
: ObjectToLowerUndefined<T[K]>;
}>;
export type ObjectToLowerUndefined<T> = T extends unknown[] export type ObjectToLowerUndefined<T> = T extends unknown[]
? ObjectToLower<T[0]>[] ? ObjectToLower<T[0]>[]

View File

@ -1,5 +1,6 @@
import type { GuildMemberStructure, GuildStructure } from '../client'; import type { GuildMemberStructure, GuildStructure } from '../client';
import type { UsingClient } from '../commands'; import type { UsingClient } from '../commands';
import type { CreateInviteFromChannel } from '../common';
import type { ObjectToLower, StructPropState, StructStates, ToClass } from '../common/types/util'; import type { ObjectToLower, StructPropState, StructStates, ToClass } from '../common/types/util';
import type { APIGuild, APIPartialGuild, GatewayGuildCreateDispatchData, RESTPatchAPIGuildJSONBody } from '../types'; import type { APIGuild, APIPartialGuild, GatewayGuildCreateDispatchData, RESTPatchAPIGuildJSONBody } from '../types';
import { AutoModerationRule } from './AutoModerationRule'; import { AutoModerationRule } from './AutoModerationRule';
@ -82,6 +83,12 @@ export class Guild<State extends StructStates = 'api'> extends (BaseGuild as unk
edit(body: RESTPatchAPIGuildJSONBody, reason?: string): Promise<GuildStructure<'api'>> { edit(body: RESTPatchAPIGuildJSONBody, reason?: string): Promise<GuildStructure<'api'>> {
return this.client.guilds.edit(this.id, body, reason); return this.client.guilds.edit(this.id, body, reason);
} }
invites = {
list: () => this.client.invites.guilds.list(this.id),
create: (data: CreateInviteFromChannel) => this.client.invites.channels.create(data),
delete: (code: string, reason?: string) => this.client.invites.delete(code, reason),
};
} }
/** Maximun custom guild emojis per level */ /** Maximun custom guild emojis per level */

View File

@ -24,6 +24,7 @@ import {
} from '../client'; } from '../client';
import type { SeyfertChannelMap, UsingClient } from '../commands'; import type { SeyfertChannelMap, UsingClient } from '../commands';
import { import {
type CreateInviteFromChannel,
type EmojiResolvable, type EmojiResolvable,
type MessageCreateBodyRequest, type MessageCreateBodyRequest,
type MessageUpdateBodyRequest, type MessageUpdateBodyRequest,
@ -213,6 +214,16 @@ export class BaseGuildChannel extends BaseChannel<ChannelType> {
super(client, rest); super(client, rest);
} }
invites = {
list: () => this.client.invites.channels.list(this.id),
create: (data: Omit<CreateInviteFromChannel, 'channelId'>) =>
this.client.invites.channels.create({
...data,
channelId: this.id,
}),
delete: (code: string, reason?: string) => this.client.invites.delete(code, reason),
};
permissionOverwrites = { permissionOverwrites = {
fetch: (): ReturnType<Overwrites['get']> => fetch: (): ReturnType<Overwrites['get']> =>
this.client.cache.overwrites?.get(this.id) || this.client.cache.overwrites?.get(this.id) ||