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": {
"@biomejs/biome": "1.9.4",
"@changesets/cli": "^2.28.1",
"@commitlint/cli": "^19.7.1",
"@commitlint/config-conventional": "^19.7.1",
"@types/node": "^22.13.5",
"@commitlint/cli": "^19.8.0",
"@commitlint/config-conventional": "^19.8.0",
"@types/node": "^22.14.0",
"husky": "^9.1.7",
"lint-staged": "^15.4.3",
"typescript": "^5.7.3",
"vitest": "^3.0.6"
"lint-staged": "^15.5.0",
"typescript": "^5.8.2",
"vitest": "^3.1.1"
},
"homepage": "https://seyfert.dev",
"repository": {
@ -69,5 +69,11 @@
"*.ts": [
"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,
GuildShorter,
InteractionShorter,
InvitesShorter,
LogLevels,
Logger,
type MakeRequired,
@ -81,6 +82,9 @@ export class BaseClient {
interactions = new InteractionShorter(this);
voiceStates = new VoiceStateShorter(this);
soundboards = new SoundboardShorter(this);
invites = new InvitesShorter(this);
/**@internal */
debugger?: Logger;

View File

@ -3,6 +3,8 @@ export * from './it/utils';
export * from './it/colors';
export { CustomizeLoggerCallback, AssignFilenameCallback, LogLevels, Logger, LoggerOptions } from './it/logger';
export * from './it/formatter';
// circular lol
export * from './shorters/invites';
//
export * from './shorters/channels';
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,7 +104,9 @@ export type SnakeCase<S extends string> = S extends `${infer A}${infer Rest}`
: `${A}${SnakeCase<Rest>}`
: Lowercase<S>;
export type ObjectToLower<T> = Identify<{
export type ObjectToLower<T> = T extends unknown[]
? ObjectToLower<T[0]>[]
: Identify<{
[K in keyof T as CamelCase<Exclude<K, symbol | number>>]: T[K] extends unknown[]
? Identify<ObjectToLower<T[K][0]>[]>
: T[K] extends object

View File

@ -1,5 +1,6 @@
import type { GuildMemberStructure, GuildStructure } from '../client';
import type { UsingClient } from '../commands';
import type { CreateInviteFromChannel } from '../common';
import type { ObjectToLower, StructPropState, StructStates, ToClass } from '../common/types/util';
import type { APIGuild, APIPartialGuild, GatewayGuildCreateDispatchData, RESTPatchAPIGuildJSONBody } from '../types';
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'>> {
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 */

View File

@ -24,6 +24,7 @@ import {
} from '../client';
import type { SeyfertChannelMap, UsingClient } from '../commands';
import {
type CreateInviteFromChannel,
type EmojiResolvable,
type MessageCreateBodyRequest,
type MessageUpdateBodyRequest,
@ -213,6 +214,16 @@ export class BaseGuildChannel extends BaseChannel<ChannelType> {
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 = {
fetch: (): ReturnType<Overwrites['get']> =>
this.client.cache.overwrites?.get(this.id) ||