feat(Guild): AuditLogs (#96)

* fetch audit logs

* vefificationLevel

* types
This commit is contained in:
MARCROCK22 2022-08-07 22:18:39 -04:00 committed by GitHub
parent e25c527f0e
commit 4d90686ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 473 additions and 350 deletions

View File

@ -1,441 +1,465 @@
import type { Snowflake } from '../common';
import type { AuditLogEvents, Snowflake } from '../common';
export * from './cdn';
export function USER(userId?: Snowflake): string {
if (!userId) { return '/users/@me'; }
return `/users/${userId}`;
if (!userId) { return '/users/@me'; }
return `/users/${userId}`;
}
export function GATEWAY_BOT(): string {
return '/gateway/bot';
return '/gateway/bot';
}
export interface GetMessagesOptions {
limit?: number;
limit?: number;
}
export interface GetMessagesOptions {
around?: Snowflake;
limit?: number;
around?: Snowflake;
limit?: number;
}
export interface GetMessagesOptions {
before?: Snowflake;
limit?: number;
before?: Snowflake;
limit?: number;
}
export interface GetMessagesOptions {
after?: Snowflake;
limit?: number;
after?: Snowflake;
limit?: number;
}
export function CHANNEL(channelId: Snowflake): string {
return `/channels/${channelId}`;
return `/channels/${channelId}`;
}
export function CHANNEL_INVITES(channelId: Snowflake): string {
return `/channels/${channelId}/invites`;
return `/channels/${channelId}/invites`;
}
export function CHANNEL_TYPING(channelId: Snowflake): string {
return `/channels/${channelId}/typing`;
return `/channels/${channelId}/typing`;
}
export function CHANNEL_CREATE_THREAD(channelId: Snowflake): string {
return `/channels/${channelId}/threads`;
return `/channels/${channelId}/threads`;
}
export function MESSAGE_CREATE_THREAD(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}/threads`;
return `/channels/${channelId}/messages/${messageId}/threads`;
}
/** used to send messages */
export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOptions): string {
let url = `/channels/${channelId}/messages?`;
let url = `/channels/${channelId}/messages?`;
if (options) {
if (options.after) { url += `after=${options.after}`; }
if (options.before) { url += `&before=${options.before}`; }
if (options.around) { url += `&around=${options.around}`; }
if (options.limit) { url += `&limit=${options.limit}`; }
}
if (options) {
if (options.after) { url += `after=${options.after}`; }
if (options.before) { url += `&before=${options.before}`; }
if (options.around) { url += `&around=${options.around}`; }
if (options.limit) { url += `&limit=${options.limit}`; }
}
return url;
return url;
}
/** used to edit messages */
export function CHANNEL_MESSAGE(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}`;
return `/channels/${channelId}/messages/${messageId}`;
}
/** used to kick members */
export function GUILD_MEMBER(guildId: Snowflake, userId: Snowflake): string {
return `/guilds/${guildId}/members/${userId}`;
return `/guilds/${guildId}/members/${userId}`;
}
export interface ListGuildMembers {
limit?: number;
after?: string;
limit?: number;
after?: string;
}
export function GUILD_MEMBERS(guildId: Snowflake, options?: ListGuildMembers) {
let url = `/guilds/${guildId}/members?`;
let url = `/guilds/${guildId}/members?`;
if (options?.limit) url += `limit=${options.limit}`;
if (options?.after) url += `&after=${options.after}`;
if (options?.limit) url += `limit=${options.limit}`;
if (options?.after) url += `&after=${options.after}`;
return url;
return url;
}
/** used to ban members */
export function GUILD_BAN(guildId: Snowflake, userId: Snowflake): string {
return `/guilds/${guildId}/bans/${userId}`;
return `/guilds/${guildId}/bans/${userId}`;
}
export interface GetBans {
limit?: number;
before?: Snowflake;
after?: Snowflake;
limit?: number;
before?: Snowflake;
after?: Snowflake;
}
/** used to unban members */
export function GUILD_BANS(guildId: Snowflake, options?: GetBans): string {
let url = `/guilds/${guildId}/bans?`;
let url = `/guilds/${guildId}/bans?`;
if (options) {
if (options.limit) { url += `limit=${options.limit}`; }
if (options.after) { url += `&after=${options.after}`; }
if (options.before) { url += `&before=${options.before}`; }
}
if (options) {
if (options.limit) { url += `limit=${options.limit}`; }
if (options.after) { url += `&after=${options.after}`; }
if (options.before) { url += `&before=${options.before}`; }
}
return url;
return url;
}
export function GUILD_ROLE(guildId: Snowflake, roleId: Snowflake): string {
return `/guilds/${guildId}/roles/${roleId}`;
return `/guilds/${guildId}/roles/${roleId}`;
}
export function GUILD_ROLES(guildId: Snowflake): string {
return `/guilds/${guildId}/roles`;
return `/guilds/${guildId}/roles`;
}
export function USER_GUILDS(guildId?: Snowflake): string {
if (guildId) { return `/users/@me/guilds/${guildId}`; }
return `/users/@me/guilds/`;
if (guildId) { return `/users/@me/guilds/${guildId}`; }
return `/users/@me/guilds/`;
}
export function USER_DM() {
return `/users/@me/channels`;
return `/users/@me/channels`;
}
export function GUILD_EMOJIS(guildId: Snowflake): string {
return `/guilds/${guildId}/emojis`;
return `/guilds/${guildId}/emojis`;
}
export interface GetAuditLogs {
userId?: Snowflake;
actionType?: AuditLogEvents
before?: Snowflake;
limit?: number;
}
export function GUILD_AUDIT_LOGS(guildId: Snowflake, options?: GetAuditLogs) {
let url = `/guilds/${guildId}/audit-logs?`;
if (options) {
const obj = {
user_id: options.userId,
action_type: options.actionType,
before: options.before,
limit: options.limit
};
for (const [key, value] of Object.entries(obj)) {
if (!value) continue;
url += `&${key}=${value}`
}
}
return url;
}
export function GUILD_EMOJI(guildId: Snowflake, emojiId: Snowflake): string {
return `/guilds/${guildId}/emojis/${emojiId}`;
return `/guilds/${guildId}/emojis/${emojiId}`;
}
export interface GetInvite {
withCounts?: boolean;
withExpiration?: boolean;
scheduledEventId?: Snowflake;
withCounts?: boolean;
withExpiration?: boolean;
scheduledEventId?: Snowflake;
}
export function GUILDS(guildId?: Snowflake): string {
if (guildId) { return `/guilds/${guildId}`; }
return `/guilds`;
if (guildId) { return `/guilds/${guildId}`; }
return `/guilds`;
}
export function AUTO_MODERATION_RULES(guildId: Snowflake, ruleId?: Snowflake): string {
if (ruleId) {
return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`;
}
return `/guilds/${guildId}/auto-moderation/rules`;
if (ruleId) {
return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`;
}
return `/guilds/${guildId}/auto-moderation/rules`;
}
export function INVITE(inviteCode: string, options?: GetInvite): string {
let url = `/invites/${inviteCode}?`;
let url = `/invites/${inviteCode}?`;
if (options) {
if (options.withCounts) { url += `with_counts=${options.withCounts}`; }
if (options.withExpiration) { url += `&with_expiration=${options.withExpiration}`; }
if (options.scheduledEventId) { url += `&guild_scheduled_event_id=${options.scheduledEventId}`; }
}
if (options) {
if (options.withCounts) { url += `with_counts=${options.withCounts}`; }
if (options.withExpiration) { url += `&with_expiration=${options.withExpiration}`; }
if (options.scheduledEventId) { url += `&guild_scheduled_event_id=${options.scheduledEventId}`; }
}
return url;
return url;
}
export function GUILD_INVITES(guildId: Snowflake): string {
return `/guilds/${guildId}/invites`;
return `/guilds/${guildId}/invites`;
}
export function INTERACTION_ID_TOKEN(interactionId: Snowflake, token: string): string {
return `/interactions/${interactionId}/${token}/callback`;
return `/interactions/${interactionId}/${token}/callback`;
}
export function WEBHOOK_MESSAGE_ORIGINAL(webhookId: Snowflake, token: string, options?: { threadId?: bigint }): string {
let url = `/webhooks/${webhookId}/${token}/messages/@original?`;
let url = `/webhooks/${webhookId}/${token}/messages/@original?`;
if (options) {
if (options.threadId) { url += `thread_id=${options.threadId}`; }
}
if (options) {
if (options.threadId) { url += `thread_id=${options.threadId}`; }
}
return url;
return url;
}
export function WEBHOOK_MESSAGE(
webhookId: Snowflake,
token: string,
messageId: Snowflake,
options?: { threadId?: Snowflake },
webhookId: Snowflake,
token: string,
messageId: Snowflake,
options?: { threadId?: Snowflake },
): string {
let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`;
let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`;
if (options) {
if (options.threadId) { url += `thread_id=${options.threadId}`; }
}
if (options) {
if (options.threadId) { url += `thread_id=${options.threadId}`; }
}
return url;
return url;
}
export function WEBHOOK_TOKEN(webhookId: Snowflake, token?: string): string {
if (!token) { return `/webhooks/${webhookId}`; }
return `/webhooks/${webhookId}/${token}`;
if (!token) { return `/webhooks/${webhookId}`; }
return `/webhooks/${webhookId}/${token}`;
}
export interface WebhookOptions {
wait?: boolean;
threadId?: Snowflake;
wait?: boolean;
threadId?: Snowflake;
}
export function WEBHOOK(webhookId: Snowflake, token: string, options?: WebhookOptions): string {
let url = `/webhooks/${webhookId}/${token}`;
let url = `/webhooks/${webhookId}/${token}`;
if (options?.wait) { url += `?wait=${options.wait}`; }
if (options?.threadId) { url += `?thread_id=${options.threadId}`; }
if (options?.wait && options.threadId) { url += `?wait=${options.wait}&thread_id=${options.threadId}`; }
if (options?.wait) { url += `?wait=${options.wait}`; }
if (options?.threadId) { url += `?thread_id=${options.threadId}`; }
if (options?.wait && options.threadId) { url += `?wait=${options.wait}&thread_id=${options.threadId}`; }
return url;
return url;
}
export function USER_NICK(guildId: Snowflake): string {
return `/guilds/${guildId}/members/@me`;
return `/guilds/${guildId}/members/@me`;
}
/**
* @link https://discord.com/developers/docs/resources/guild#get-guild-prune-count
*/
export interface GetGuildPruneCountQuery {
days?: number;
includeRoles?: Snowflake | Snowflake[];
days?: number;
includeRoles?: Snowflake | Snowflake[];
}
export function GUILD_PRUNE(guildId: Snowflake, options?: GetGuildPruneCountQuery): string {
let url = `/guilds/${guildId}/prune?`;
let url = `/guilds/${guildId}/prune?`;
if (options?.days) { url += `days=${options.days}`; }
if (options?.includeRoles) { url += `&include_roles=${options.includeRoles}`; }
if (options?.days) { url += `days=${options.days}`; }
if (options?.includeRoles) { url += `&include_roles=${options.includeRoles}`; }
return url;
return url;
}
export function CHANNEL_PIN(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/pins/${messageId}`;
return `/channels/${channelId}/pins/${messageId}`;
}
export function CHANNEL_PINS(channelId: Snowflake): string {
return `/channels/${channelId}/pins`;
return `/channels/${channelId}/pins`;
}
export function CHANNEL_MESSAGE_REACTION_ME(channelId: Snowflake, messageId: Snowflake, emoji: string): string {
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`;
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`;
}
export function CHANNEL_MESSAGE_REACTION_USER(
channelId: Snowflake,
messageId: Snowflake,
emoji: string,
userId: Snowflake,
channelId: Snowflake,
messageId: Snowflake,
emoji: string,
userId: Snowflake,
) {
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/${userId}`;
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/${userId}`;
}
export function CHANNEL_MESSAGE_REACTIONS(channelId: Snowflake, messageId: Snowflake) {
return `/channels/${channelId}/messages/${messageId}/reactions`;
return `/channels/${channelId}/messages/${messageId}/reactions`;
}
/**
* @link https://discord.com/developers/docs/resources/channel#get-reactions-query-string-params
*/
export interface GetReactions {
after?: string;
limit?: number;
after?: string;
limit?: number;
}
export function CHANNEL_MESSAGE_REACTION(
channelId: Snowflake,
messageId: Snowflake,
emoji: string,
options?: GetReactions,
channelId: Snowflake,
messageId: Snowflake,
emoji: string,
options?: GetReactions,
): string {
let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`;
let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`;
if (options?.after) { url += `after=${options.after}`; }
if (options?.limit) { url += `&limit=${options.limit}`; }
if (options?.after) { url += `after=${options.after}`; }
if (options?.limit) { url += `&limit=${options.limit}`; }
return url;
return url;
}
export function CHANNEL_MESSAGE_CROSSPOST(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}/crosspost`;
return `/channels/${channelId}/messages/${messageId}/crosspost`;
}
export function GUILD_MEMBER_ROLE(guildId: Snowflake, memberId: Snowflake, roleId: Snowflake): string {
return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`;
return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`;
}
export function CHANNEL_WEBHOOKS(channelId: Snowflake): string {
return `/channels/${channelId}/webhooks`;
return `/channels/${channelId}/webhooks`;
}
export function THREAD_START_PUBLIC(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}/threads`;
return `/channels/${channelId}/messages/${messageId}/threads`;
}
export function THREAD_START_PRIVATE(channelId: Snowflake): string {
return `/channels/${channelId}/threads`;
return `/channels/${channelId}/threads`;
}
export function THREAD_ACTIVE(guildId: Snowflake): string {
return `/guilds/${guildId}/threads/active`;
return `/guilds/${guildId}/threads/active`;
}
export interface ListArchivedThreads {
before?: number;
limit?: number;
before?: number;
limit?: number;
}
export function THREAD_ME(channelId: Snowflake): string {
return `/channels/${channelId}/thread-members/@me`;
return `/channels/${channelId}/thread-members/@me`;
}
export function THREAD_MEMBERS(channelId: Snowflake): string {
return `/channels/${channelId}/thread-members`;
return `/channels/${channelId}/thread-members`;
}
export function THREAD_USER(channelId: Snowflake, userId: Snowflake): string {
return `/channels/${channelId}/thread-members/${userId}`;
return `/channels/${channelId}/thread-members/${userId}`;
}
export function THREAD_ARCHIVED(channelId: Snowflake): string {
return `/channels/${channelId}/threads/archived`;
return `/channels/${channelId}/threads/archived`;
}
export function THREAD_ARCHIVED_PUBLIC(channelId: Snowflake, options?: ListArchivedThreads): string {
let url = `/channels/${channelId}/threads/archived/public?`;
let url = `/channels/${channelId}/threads/archived/public?`;
if (options) {
if (options.before) { url += `before=${new Date(options.before).toISOString()}`; }
if (options.limit) { url += `&limit=${options.limit}`; }
}
if (options) {
if (options.before) { url += `before=${new Date(options.before).toISOString()}`; }
if (options.limit) { url += `&limit=${options.limit}`; }
}
return url;
return url;
}
export function THREAD_ARCHIVED_PRIVATE(channelId: Snowflake, options?: ListArchivedThreads): string {
let url = `/channels/${channelId}/threads/archived/private?`;
let url = `/channels/${channelId}/threads/archived/private?`;
if (options) {
if (options.before) { url += `before=${new Date(options.before).toISOString()}`; }
if (options.limit) { url += `&limit=${options.limit}`; }
}
if (options) {
if (options.before) { url += `before=${new Date(options.before).toISOString()}`; }
if (options.limit) { url += `&limit=${options.limit}`; }
}
return url;
return url;
}
export function THREAD_ARCHIVED_PRIVATE_JOINED(channelId: Snowflake, options?: ListArchivedThreads): string {
let url = `/channels/${channelId}/users/@me/threads/archived/private?`;
let url = `/channels/${channelId}/users/@me/threads/archived/private?`;
if (options) {
if (options.before) { url += `before=${new Date(options.before).toISOString()}`; }
if (options.limit) { url += `&limit=${options.limit}`; }
}
if (options) {
if (options.before) { url += `before=${new Date(options.before).toISOString()}`; }
if (options.limit) { url += `&limit=${options.limit}`; }
}
return url;
return url;
}
export function FORUM_START(channelId: Snowflake): string {
return `/channels/${channelId}/threads?has_message=true`;
return `/channels/${channelId}/threads?has_message=true`;
}
export function STAGE_INSTANCES(): string {
return `/stage-instances`;
return `/stage-instances`;
}
export function STAGE_INSTANCE(channelId: Snowflake): string {
return `/stage-instances/${channelId}`;
return `/stage-instances/${channelId}`;
}
export function APPLICATION_COMMANDS(appId: Snowflake, commandId?: Snowflake): string {
if (commandId) { return `/applications/${appId}/commands/${commandId}`; }
return `/applications/${appId}/commands`;
if (commandId) { return `/applications/${appId}/commands/${commandId}`; }
return `/applications/${appId}/commands`;
}
export function GUILD_APPLICATION_COMMANDS(appId: Snowflake, guildId: Snowflake, commandId?: Snowflake): string {
if (commandId) { return `/applications/${appId}/guilds/${guildId}/commands/${commandId}`; }
return `/applications/${appId}/guilds/${guildId}/commands`;
if (commandId) { return `/applications/${appId}/guilds/${guildId}/commands/${commandId}`; }
return `/applications/${appId}/guilds/${guildId}/commands`;
}
export function GUILD_APPLICATION_COMMANDS_PERMISSIONS(
appId: Snowflake,
guildId: Snowflake,
commandId?: Snowflake,
appId: Snowflake,
guildId: Snowflake,
commandId?: Snowflake,
): string {
if (commandId) { return `/applications/${appId}/guilds/${guildId}/commands/${commandId}/permissions`; }
return `/applications/${appId}/guilds/${guildId}/commands/permissions`;
if (commandId) { return `/applications/${appId}/guilds/${guildId}/commands/${commandId}/permissions`; }
return `/applications/${appId}/guilds/${guildId}/commands/permissions`;
}
export function APPLICATION_COMMANDS_LOCALIZATIONS(
appId: Snowflake,
commandId: Snowflake,
withLocalizations?: boolean,
appId: Snowflake,
commandId: Snowflake,
withLocalizations?: boolean,
): string {
let url = `/applications/${appId}/commands/${commandId}?`;
let url = `/applications/${appId}/commands/${commandId}?`;
if (withLocalizations !== undefined) {
url += `withLocalizations=${withLocalizations}`;
}
if (withLocalizations !== undefined) {
url += `withLocalizations=${withLocalizations}`;
}
return url;
return url;
}
export function GUILD_APPLICATION_COMMANDS_LOCALIZATIONS(
appId: Snowflake,
guildId: Snowflake,
commandId: Snowflake,
withLocalizations?: boolean,
appId: Snowflake,
guildId: Snowflake,
commandId: Snowflake,
withLocalizations?: boolean,
): string {
let url = `/applications/${appId}/guilds/${guildId}/commands/${commandId}?`;
let url = `/applications/${appId}/guilds/${guildId}/commands/${commandId}?`;
if (withLocalizations !== undefined) {
url += `with_localizations=${withLocalizations}`;
}
if (withLocalizations !== undefined) {
url += `with_localizations=${withLocalizations}`;
}
return url;
return url;
}
export function STICKER(id: Snowflake): string {
return `stickers/${id}`;
return `stickers/${id}`;
}
export function STICKER_PACKS(): string {
return `stickers-packs`;
return `stickers-packs`;
}
export function GUILD_STICKERS(guildId: Snowflake, stickerId?: Snowflake): string {
if (stickerId) { return `/guilds/${guildId}/stickers/${stickerId}`; }
return `/guilds/${guildId}/stickers`;
if (stickerId) { return `/guilds/${guildId}/stickers/${stickerId}`; }
return `/guilds/${guildId}/stickers`;
}
/**
@ -443,7 +467,7 @@ export function GUILD_STICKERS(guildId: Snowflake, stickerId?: Snowflake): strin
* @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
*/
export interface GetWidget {
get: 'json' | 'image' | 'settings';
get: 'json' | 'image' | 'settings';
}
/**
@ -451,19 +475,19 @@ export interface GetWidget {
* @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
*/
export function GUILD_WIDGET(guildId: Snowflake, options: GetWidget = { get: 'settings' }): string {
let url = `/guilds/${guildId}/widget`;
if (options.get === 'json') {
url += '.json';
} else if (options.get === 'image') {
url += '.png';
}
let url = `/guilds/${guildId}/widget`;
if (options.get === 'json') {
url += '.json';
} else if (options.get === 'image') {
url += '.png';
}
return url;
return url;
}
/** @link https://discord.com/developers/docs/resources/guild#get-guild-voice-regions */
export function GUILD_VOICE_REGIONS(guildId: Snowflake): string {
return `/guilds/${guildId}/regions`;
return `/guilds/${guildId}/regions`;
}
/**
@ -472,7 +496,7 @@ export function GUILD_VOICE_REGIONS(guildId: Snowflake): string {
* @returns Get vanity URL
*/
export function GUILD_VANITY(guildId: Snowflake): string {
return `/guilds/${guildId}/vanity-url`;
return `/guilds/${guildId}/vanity-url`;
}
/**
@ -481,7 +505,7 @@ export function GUILD_VANITY(guildId: Snowflake): string {
* @returns Get guild preview url
*/
export function GUILD_PREVIEW(guildId: Snowflake): string {
return `/guilds/${guildId}/preview`;
return `/guilds/${guildId}/preview`;
}
/**
@ -490,5 +514,5 @@ export function GUILD_PREVIEW(guildId: Snowflake): string {
* @returns Get guild channels url.
*/
export function GUILD_CHANNELS(guildId: Snowflake): string {
return `/guilds/${guildId}/channels`;
}
return `/guilds/${guildId}/channels`;
}

View File

@ -295,7 +295,7 @@ export interface DiscordTeamMember {
team_id: string;
/** The avatar, discriminator, id, and username of the user */
user: Partial<DiscordUser> &
Pick<DiscordUser, 'avatar' | 'discriminator' | 'id' | 'username'>;
Pick<DiscordUser, 'avatar' | 'discriminator' | 'id' | 'username'>;
}
/** https://discord.com/developers/docs/topics/gateway#webhooks-update-webhook-update-event-fields */
@ -1149,30 +1149,30 @@ export interface DiscordActionRow {
type: 1;
/** The components in this row */
components:
| [
| DiscordSelectMenuComponent
| DiscordButtonComponent
| DiscordInputTextComponent
]
| [DiscordButtonComponent, DiscordButtonComponent]
| [
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent
]
| [
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent
]
| [
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent
];
| [
| DiscordSelectMenuComponent
| DiscordButtonComponent
| DiscordInputTextComponent
]
| [DiscordButtonComponent, DiscordButtonComponent]
| [
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent
]
| [
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent
]
| [
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent,
DiscordButtonComponent
];
}
export interface DiscordSelectMenuComponent {
@ -1311,10 +1311,10 @@ export interface DiscordInteraction {
data?: DiscordInteractionData;
/** The guild's preferred locale, if invoked in a guild */
guild_locale?: string;
/** Bitwise set of permissions the app or bot has within the channel the interaction was sent from */
app_permissions?: string;
/** Selected language of the invoking user */
locale?: string;
/** Bitwise set of permissions the app or bot has within the channel the interaction was sent from */
app_permissions?: string;
/** Selected language of the invoking user */
locale?: string;
}
/** https://discord.com/developers/docs/resources/guild#guild-member-object */
@ -1374,12 +1374,12 @@ export type DiscordInteractionDataOption = {
type: ApplicationCommandOptionTypes;
/** Value of the option resulting from user input */
value?:
| string
| boolean
| number
| DiscordMember
| DiscordChannel
| DiscordRole;
| string
| boolean
| number
| DiscordMember
| DiscordChannel
| DiscordRole;
/** Present if this option is a group or subcommand */
options?: DiscordInteractionDataOption[];
/** `true` if this option is the currently focused option for autocomplete */
@ -1439,7 +1439,12 @@ export interface DiscordAuditLog {
/** List of audit log entries, sorted from most to least recent */
audit_log_entries: DiscordAuditLogEntry[];
/** List of partial integration objects */
integrations: Partial<DiscordIntegration>[];
integrations: ({
type: 'youtube' | 'twitch' | 'discord';
id: string;
name: string;
account: DiscordIntegrationAccount;
} & Partial<DiscordIntegration>)[];
/**
* List of threads found in the audit log.
* Threads referenced in `THREAD_CREATE` and `THREAD_UPDATE` events are included in the threads map since archived threads might not be kept in memory by clients.
@ -1576,97 +1581,97 @@ export interface DiscordAuditLogEntry {
/** https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-structure */
export type DiscordAuditLogChange =
| {
new_value: string;
old_value: string;
key:
| 'name'
| 'description'
| 'discovery_splash_hash'
| 'banner_hash'
| 'preferred_locale'
| 'rules_channel_id'
| 'public_updates_channel_id'
| 'icon_hash'
| 'image_hash'
| 'splash_hash'
| 'owner_id'
| 'region'
| 'afk_channel_id'
| 'vanity_url_code'
| 'widget_channel_id'
| 'system_channel_id'
| 'topic'
| 'application_id'
| 'permissions'
| 'allow'
| 'deny'
| 'code'
| 'channel_id'
| 'inviter_id'
| 'nick'
| 'avatar_hash'
| 'id'
| 'location'
| 'command_id';
}
new_value: string;
old_value: string;
key:
| 'name'
| 'description'
| 'discovery_splash_hash'
| 'banner_hash'
| 'preferred_locale'
| 'rules_channel_id'
| 'public_updates_channel_id'
| 'icon_hash'
| 'image_hash'
| 'splash_hash'
| 'owner_id'
| 'region'
| 'afk_channel_id'
| 'vanity_url_code'
| 'widget_channel_id'
| 'system_channel_id'
| 'topic'
| 'application_id'
| 'permissions'
| 'allow'
| 'deny'
| 'code'
| 'channel_id'
| 'inviter_id'
| 'nick'
| 'avatar_hash'
| 'id'
| 'location'
| 'command_id';
}
| {
new_value: number;
old_value: number;
key:
| 'afk_timeout'
| 'mfa_level'
| 'verification_level'
| 'explicit_content_filter'
| 'default_message_notifications'
| 'prune_delete_days'
| 'position'
| 'bitrate'
| 'rate_limit_per_user'
| 'color'
| 'max_uses'
| 'uses'
| 'max_age'
| 'expire_behavior'
| 'expire_grace_period'
| 'user_limit'
| 'privacy_level'
| 'auto_archive_duration'
| 'default_auto_archive_duration'
| 'entity_type'
| 'status'
| 'communication_disabled_until';
}
new_value: number;
old_value: number;
key:
| 'afk_timeout'
| 'mfa_level'
| 'verification_level'
| 'explicit_content_filter'
| 'default_message_notifications'
| 'prune_delete_days'
| 'position'
| 'bitrate'
| 'rate_limit_per_user'
| 'color'
| 'max_uses'
| 'uses'
| 'max_age'
| 'expire_behavior'
| 'expire_grace_period'
| 'user_limit'
| 'privacy_level'
| 'auto_archive_duration'
| 'default_auto_archive_duration'
| 'entity_type'
| 'status'
| 'communication_disabled_until';
}
| {
new_value: Partial<DiscordRole>[];
old_value?: Partial<DiscordRole>[];
key: '$add' | '$remove';
}
new_value: Partial<DiscordRole>[];
old_value?: Partial<DiscordRole>[];
key: '$add' | '$remove';
}
| {
new_value: boolean;
old_value: boolean;
key:
| 'widget_enabled'
| 'nsfw'
| 'hoist'
| 'mentionable'
| 'temporary'
| 'deaf'
| 'mute'
| 'enable_emoticons'
| 'archived'
| 'locked'
| 'invitable';
}
new_value: boolean;
old_value: boolean;
key:
| 'widget_enabled'
| 'nsfw'
| 'hoist'
| 'mentionable'
| 'temporary'
| 'deaf'
| 'mute'
| 'enable_emoticons'
| 'archived'
| 'locked'
| 'invitable';
}
| {
new_value: DiscordOverwrite[];
old_value: DiscordOverwrite[];
key: 'permission_overwrites';
}
new_value: DiscordOverwrite[];
old_value: DiscordOverwrite[];
key: 'permission_overwrites';
}
| {
new_value: string | number;
old_value: string | number;
key: 'type';
};
new_value: string | number;
old_value: string | number;
key: 'type';
};
/** https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info */
export interface DiscordOptionalAuditEntryInfo {
@ -2127,7 +2132,7 @@ export interface DiscordGuildBanAddRemove {
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove */
export interface DiscordMessageReactionRemove
extends Omit<DiscordMessageReactionAdd, 'member'> {}
extends Omit<DiscordMessageReactionAdd, 'member'> { }
/** https://discord.com/developers/docs/topics/gateway#message-reaction-add */
export interface DiscordMessageReactionAdd {
@ -2203,12 +2208,12 @@ export interface DiscordReady {
shard?: [number, number];
/** Contains id and flags */
application: Partial<DiscordApplication> &
Pick<DiscordApplication, 'id' | 'flags'>;
Pick<DiscordApplication, 'id' | 'flags'>;
}
/** https://discord.com/developers/docs/resources/guild#unavailable-guild-object */
export interface DiscordUnavailableGuild
extends Pick<DiscordGuild, 'id' | 'unavailable'> {}
extends Pick<DiscordGuild, 'id' | 'unavailable'> { }
/** https://discord.com/developers/docs/topics/gateway#message-delete-bulk */
export interface DiscordMessageDeleteBulk {
@ -2380,9 +2385,9 @@ export interface DiscordGuildMemberUpdate {
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-all */
export interface DiscordMessageReactionRemoveAll
extends Pick<
DiscordMessageReactionAdd,
'channel_id' | 'message_id' | 'guild_id'
> {}
DiscordMessageReactionAdd,
'channel_id' | 'message_id' | 'guild_id'
> { }
// TODO: add docs link
export interface DiscordValidateDiscoverySearchTerm {

View File

@ -25,7 +25,12 @@ import {
VideoQualityModes,
GetBans,
GetInvite,
ListGuildMembers,
ListGuildMembers,
GetAuditLogs,
GUILD_AUDIT_LOGS,
DiscordAuditLog,
AuditLogEvents,
DiscordAuditLogChange,
} from '@biscuitland/api-types';
import type { ImageFormat, ImageSize } from '../utils/util';
import { GuildFeatures, PremiumTiers } from '@biscuitland/api-types';
@ -46,7 +51,7 @@ import {
GUILD_PRUNE,
GUILD_INVITES,
GUILD_MEMBER,
GUILD_MEMBERS,
GUILD_MEMBERS,
GUILD_MEMBER_ROLE,
GUILD_ROLE,
GUILD_ROLES,
@ -69,6 +74,9 @@ import { Widget } from './widget';
import { Sticker } from './sticker';
import { WelcomeScreen } from './welcome';
import { AutoModerationRule } from './automod';
import { Webhook } from './webhook';
import { ScheduledEvent } from './scheduled-events';
import Integration from './integration';
/** BaseGuild */
/**
@ -286,11 +294,11 @@ export class GuildPreview implements Model {
? Util.iconHashToBigInt(data.icon)
: undefined;
this.splashHash = data.splash
this.splashHash = data.splash
? Util.iconHashToBigInt(data.splash)
: undefined;
this.discoverySplashHash = data.discovery_splash
this.discoverySplashHash = data.discovery_splash
? Util.iconHashToBigInt(data.discovery_splash)
: undefined;
@ -298,7 +306,7 @@ export class GuildPreview implements Model {
x => new GuildEmoji(this.session, x, this.id)
);
this.features = data.features;
this.features = data.features;
this.approximateMemberCount = data.approximate_member_count;
this.approximatePresenceCount = data.approximate_presence_count;
this.stickers = data.stickers.map(x => new Sticker(this.session, x));
@ -435,9 +443,9 @@ export interface GuildCreateOptionsChannel {
id?: Snowflake;
parentId?: Snowflake;
type?:
| ChannelTypes.GuildText
| ChannelTypes.GuildVoice
| ChannelTypes.GuildCategory;
| ChannelTypes.GuildText
| ChannelTypes.GuildVoice
| ChannelTypes.GuildCategory;
name: string;
topic?: string | null;
nsfw?: boolean;
@ -482,6 +490,38 @@ export interface GuildEditOptions extends Partial<GuildCreateOptions> {
premiumProgressBarEnabled?: boolean;
}
export interface AuditLogResult {
auditLogEntries: {
targetId: string | null;
changes: {
key: DiscordAuditLogChange['key'];
oldValue: DiscordOverwrite[] | Role[] | string | number | boolean | null;
newValue: DiscordOverwrite[] | Role[] | string | number | boolean | null;
}[] | undefined;
userId: string | null;
id: string;
actionType: AuditLogEvents;
options: {
deleteMemberDays: string;
membersRemoved: string;
channelId: string;
messageId: string;
count: string;
id: string;
type: string;
roleName: string;
applicationId: string;
} | null;
reason: string | undefined;
}[];
autoModerationRules: AutoModerationRule[] | undefined;
guildScheduledEvents: ScheduledEvent[] | undefined;
integrations: Integration[];
threads: ThreadChannel[];
users: User[];
webhooks: Webhook[];
}
/**
* Represents a guild.
* @see {@link BaseGuild}.
@ -502,7 +542,7 @@ export class Guild extends BaseGuild implements Model {
this.widgetChannelId = data.widget_channel_id
? data.widget_channel_id
: undefined;
this.vefificationLevel = data.verification_level;
this.verificationLevel = data.verification_level;
this.defaultMessageNotificationLevel =
data.default_message_notifications;
this.explicitContentFilterLevel = data.explicit_content_filter;
@ -558,7 +598,7 @@ export class Guild extends BaseGuild implements Model {
* @see {@link VerificationLevels}
* @link https://discord.com/developers/docs/resources/guild#guild-object-verification-level
*/
vefificationLevel: VerificationLevels;
verificationLevel: VerificationLevels;
/**
* The default message notification level.
@ -872,9 +912,9 @@ export class Guild extends BaseGuild implements Model {
GUILD_BAN(this.id, memberId),
options
? {
delete_message_days: options.deleteMessageDays,
reason: options.reason,
}
delete_message_days: options.deleteMessageDays,
reason: options.reason,
}
: {}
);
}
@ -1124,10 +1164,10 @@ export class Guild extends BaseGuild implements Model {
* gets the auto moderation rules for the guild.
* @see {@link AutoModerationRule#getRules} sames
* @param ruleId The optional rule id
* @returns
* @returns
*/
fetchAutoModerationRules(ruleId?: Snowflake): Promise<AutoModerationRule | AutoModerationRule[]> {
return AutoModerationRule.prototype.getRules.call({session: this.session, guildId: this.id}, ruleId);
return AutoModerationRule.prototype.getRules.call({ session: this.session, guildId: this.id }, ruleId);
}
/**
@ -1239,21 +1279,75 @@ export class Guild extends BaseGuild implements Model {
return channels.map(channel => ChannelFactory.fromGuildChannel(this.session, channel));
}
/** fetches a member */
async fetchMember(memberId: Snowflake): Promise<Member> {
const member = await this.session.rest.get<DiscordMemberWithUser>(
GUILD_MEMBER(this.id, memberId)
);
async fetchAuditLogs(options?: GetAuditLogs): Promise<AuditLogResult> {
const auditLog = await this.session.rest.get<DiscordAuditLog>(GUILD_AUDIT_LOGS(this.id, options));
return {
auditLogEntries: auditLog.audit_log_entries.map(x => ({
targetId: x.target_id,
changes: x.changes?.map(j => ({
key: j.key,
oldValue: j.old_value
? j.key === 'permission_overwrites'
? (j.old_value as DiscordOverwrite[])
: ['$add', '$remove'].includes(j.key)
? (j.old_value as DiscordRole[]).map(j => new Role(this.session, { ...j, permissions: j.permissions || '0' }, this.id))
: j.old_value as string | number | boolean
: null,
newValue: j.new_value
? j.key === 'permission_overwrites'
? (j.new_value as DiscordOverwrite[])
: ['$add', '$remove'].includes(j.key)
? (j.new_value as DiscordRole[]).map(j => new Role(this.session, { ...j, permissions: j.permissions || '0' }, this.id))
: j.new_value as string | number | boolean
: null,
})),
userId: x.user_id,
id: x.id,
actionType: x.action_type,
options: x.options ? {
deleteMemberDays: x.options.delete_member_days,
membersRemoved: x.options.members_removed,
channelId: x.options.channel_id,
messageId: x.options.message_id,
count: x.options.count,
id: x.options.id,
type: x.options.type,
roleName: x.options.role_name,
applicationId: x.options.application_id
} : null,
reason: x.reason,
})),
autoModerationRules: auditLog.auto_moderation_rules?.map(x => new AutoModerationRule(this.session, x)),
guildScheduledEvents: auditLog.guild_scheduled_events?.map(x => new ScheduledEvent(this.session, x)),
integrations: auditLog.integrations.map(x => new Integration(this.session, {
guild_id: this.id,
...x,
})),
threads: auditLog.threads.map(x => ChannelFactory.fromGuildChannel(this.session, x) as ThreadChannel),
users: auditLog.users.map(x => new User(this.session, x)),
webhooks: auditLog.webhooks.map(x => new Webhook(this.session, x)),
}
}
return new Member(this.session, member, this.id);
}
async fetchOwner(): Promise<Member> {
return this.fetchMember(this.ownerId);
}
/** fetches multiple members */
async fetchMembers(options?: ListGuildMembers): Promise<Member[]> {
const members = await this.session.rest.get<DiscordMemberWithUser[]>(
GUILD_MEMBERS(this.id, options)
);
/** fetches a member */
async fetchMember(memberId: Snowflake): Promise<Member> {
const member = await this.session.rest.get<DiscordMemberWithUser>(
GUILD_MEMBER(this.id, memberId)
);
return members.map((member) => new Member(this.session, member, this.id));
}
return new Member(this.session, member, this.id);
}
/** fetches multiple members */
async fetchMembers(options?: ListGuildMembers): Promise<Member[]> {
const members = await this.session.rest.get<DiscordMemberWithUser[]>(
GUILD_MEMBERS(this.id, options)
);
return members.map((member) => new Member(this.session, member, this.id));
}
}