Skip to content

Commit

Permalink
feat: thread updates (#167)
Browse files Browse the repository at this point in the history
* feat: thread updates

* feat: update Routes

BREAKING CHANGE: `Routes#channelJoinedArchivedThreads` is now spelled right (from `Routes#channelJoinedArhivedThreads`)
  • Loading branch information
advaith1 committed Jul 31, 2021
1 parent a93235c commit 47100bc
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 8 deletions.
43 changes: 41 additions & 2 deletions deno/payloads/v9/auditLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import type { Snowflake } from '../../globals.ts';
import type { APIOverwrite } from './channel.ts';
import type { APIChannel, APIOverwrite } from './channel.ts';
import type {
APIGuildIntegration,
GuildDefaultMessageNotifications,
Expand Down Expand Up @@ -46,6 +46,14 @@ export interface APIAuditLog {
* See https://discord.com/developers/docs/resources/guild#integration-object
*/
integrations: APIGuildIntegration[];
/**
* 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.
*
* See https://discord.com/developers/docs/resources/channel#channel-object
*/
threads: APIChannel[];
}

/**
Expand Down Expand Up @@ -144,6 +152,10 @@ export enum AuditLogEvent {
StickerCreate = 90,
StickerUpdate,
StickerDelete,

ThreadCreate = 110,
ThreadUpdate,
ThreadDelete,
}

/**
Expand Down Expand Up @@ -302,7 +314,11 @@ export type APIAuditLogChange =
| APIAuditLogChangeKeyFormatType
| APIAuditLogChangeKeyAsset
| APIAuditLogChangeKeyAvailable
| APIAuditLogChangeKeyGuildId;
| APIAuditLogChangeKeyGuildId
| APIAuditLogChangeKeyArchived
| APIAuditLogChangeKeyLocked
| APIAuditLogChangeKeyAutoArchiveDuration
| APIAuditLogChangeKeyDefaultAutoArchiveDuration;

/**
* Returned when an entity's name is changed
Expand Down Expand Up @@ -611,6 +627,29 @@ export type APIAuditLogChangeKeyAvailable = AuditLogChangeData<'available', bool
*/
export type APIAuditLogChangeKeyGuildId = AuditLogChangeData<'guild_id', Snowflake>;

/*
* Returned when a thread's archive status is changed
*/
export type APIAuditLogChangeKeyArchived = AuditLogChangeData<'archived', boolean>;

/*
* Returned when a thread's lock status is changed
*/
export type APIAuditLogChangeKeyLocked = AuditLogChangeData<'locked', boolean>;

/*
* Returned when a thread's auto archive duration is changed
*/
export type APIAuditLogChangeKeyAutoArchiveDuration = AuditLogChangeData<'auto_archive_duration', number>;

/*
* Returned when a channel's default auto archive duration for newly created threads is changed
*/
export type APIAuditLogChangeKeyDefaultAutoArchiveDuration = AuditLogChangeData<
'default_auto_archive_duration',
number
>;

interface AuditLogChangeData<K extends string, D extends unknown> {
key: K;
/**
Expand Down
5 changes: 5 additions & 0 deletions deno/payloads/v9/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export interface APIChannel extends APIPartialChannel {
/**
* Amount of seconds a user has to wait before sending another message (0-21600);
* bots, as well as users with the permission `MANAGE_MESSAGES` or `MANAGE_CHANNELS`, are unaffected
*
* `rate_limit_per_user` also applies to thread creation. Users can send one message and create one thread during each `rate_limit_per_user` interval.
*
* For thread channels, `rate_limit_per_user` is only returned if the field is set to a non-zero and non-null value.
* The absence of this field in API calls and Gateway events should indicate that slowmode has been reset to the default value.
*/
rate_limit_per_user?: number;
/**
Expand Down
13 changes: 12 additions & 1 deletion deno/rest/v9/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ export interface RESTPostAPIChannelMessagesThreadsJSONBody {
name: string;
/**
* The amount of time in minutes to wait before automatically archiving the thread
*
* The 3 day and 7 day archive durations require the server to be boosted. The [guild features](https://discord.com/developers/docs/resources/guild#guild-object-guild-features) will indicate if a server is able to use those settings.
*/
auto_archive_duration: ThreadAutoArchiveDuration;
}
Expand All @@ -592,8 +594,15 @@ export type RESTPostAPIChannelMessagesThreadsResult = APIChannel;
export interface RESTPostAPIChannelThreadsJSONBody extends RESTPostAPIChannelMessagesThreadsJSONBody {
/**
* The type of thread to create
*
* In API v9, `type` defaults to `PRIVATE_THREAD`.
* In API v10 this will be changed to be a required field, with no default.
*
* See https://discord.com/developers/docs/resources/channel#channel-object-channel-types
*
* @default 12
*/
type: ChannelType.GuildNewsThread | ChannelType.GuildPublicThread | ChannelType.GuildPrivateThread;
type?: ChannelType.GuildNewsThread | ChannelType.GuildPublicThread | ChannelType.GuildPrivateThread;
}

/**
Expand Down Expand Up @@ -632,6 +641,8 @@ export interface RESTGetAPIChannelThreadsArchivedQuery {

/**
* https://discord.com/developers/docs/resources/channel#list-active-threads
*
* @deprecated Use [List Active Guild Threads](https://discord.com/developers/docs/resources/guild#list-active-threads) instead. Will be removed in v10.
*/
export type RESTGetAPIChannelThreadsResult = APIThreadList;

Expand Down
6 changes: 6 additions & 0 deletions deno/rest/v9/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
APIGuildWidget,
APIGuildWidgetSettings,
APIRole,
APIThreadList,
APIVoiceRegion,
GuildDefaultMessageNotifications,
GuildExplicitContentFilter,
Expand Down Expand Up @@ -303,6 +304,11 @@ export type RESTPatchAPIGuildChannelPositionsJSONBody = Array<{
*/
export type RESTPatchAPIGuildChannelPositionsResult = never;

/**
* https://discord.com/developers/docs/resources/guild#list-active-threads
*/
export type RESTGetAPIGuildThreadsResult = Omit<APIThreadList, 'has_more'>;

/**
* https://discord.com/developers/docs/resources/guild#get-guild-member
*/
Expand Down
12 changes: 11 additions & 1 deletion deno/rest/v9/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,19 @@ export const Routes = {
return parts.join('/') as `/channels/${Snowflake}/threads` | `/channels/${Snowflake}/messages/${Snowflake}/threads`;
},

/**
* Route for:
* - GET `/guilds/{guild.id}/threads/active`
*/
guildActiveThreads(guildId: Snowflake) {
return `/guilds/${guildId}/threads/active` as const;
},

/**
* Route for:
* - GET `/channels/{channel.id}/threads/active`
* (deprecated, use [List Active Guild Threads](https://discord.com/developers/docs/resources/guild#list-active-threads) instead.
* Will be removed in v10.)
* - GET `/channels/{channel.id}/threads/archived/public`
* - GET `/channels/{channel.id}/threads/archived/private`
*/
Expand All @@ -456,7 +466,7 @@ export const Routes = {
* Route for:
* - GET `/channels/{channel.id}/users/@me/threads/archived/prviate`
*/
channelJoinedArhivedThreads(channelId: Snowflake) {
channelJoinedArchivedThreads(channelId: Snowflake) {
return `/channels/${channelId}/users/@me/threads/archived/private` as const;
},

Expand Down
43 changes: 41 additions & 2 deletions payloads/v9/auditLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import type { Snowflake } from '../../globals';
import type { APIOverwrite } from './channel';
import type { APIChannel, APIOverwrite } from './channel';
import type {
APIGuildIntegration,
GuildDefaultMessageNotifications,
Expand Down Expand Up @@ -46,6 +46,14 @@ export interface APIAuditLog {
* See https://discord.com/developers/docs/resources/guild#integration-object
*/
integrations: APIGuildIntegration[];
/**
* 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.
*
* See https://discord.com/developers/docs/resources/channel#channel-object
*/
threads: APIChannel[];
}

/**
Expand Down Expand Up @@ -144,6 +152,10 @@ export const enum AuditLogEvent {
StickerCreate = 90,
StickerUpdate,
StickerDelete,

ThreadCreate = 110,
ThreadUpdate,
ThreadDelete,
}

/**
Expand Down Expand Up @@ -302,7 +314,11 @@ export type APIAuditLogChange =
| APIAuditLogChangeKeyFormatType
| APIAuditLogChangeKeyAsset
| APIAuditLogChangeKeyAvailable
| APIAuditLogChangeKeyGuildId;
| APIAuditLogChangeKeyGuildId
| APIAuditLogChangeKeyArchived
| APIAuditLogChangeKeyLocked
| APIAuditLogChangeKeyAutoArchiveDuration
| APIAuditLogChangeKeyDefaultAutoArchiveDuration;

/**
* Returned when an entity's name is changed
Expand Down Expand Up @@ -611,6 +627,29 @@ export type APIAuditLogChangeKeyAvailable = AuditLogChangeData<'available', bool
*/
export type APIAuditLogChangeKeyGuildId = AuditLogChangeData<'guild_id', Snowflake>;

/*
* Returned when a thread's archive status is changed
*/
export type APIAuditLogChangeKeyArchived = AuditLogChangeData<'archived', boolean>;

/*
* Returned when a thread's lock status is changed
*/
export type APIAuditLogChangeKeyLocked = AuditLogChangeData<'locked', boolean>;

/*
* Returned when a thread's auto archive duration is changed
*/
export type APIAuditLogChangeKeyAutoArchiveDuration = AuditLogChangeData<'auto_archive_duration', number>;

/*
* Returned when a channel's default auto archive duration for newly created threads is changed
*/
export type APIAuditLogChangeKeyDefaultAutoArchiveDuration = AuditLogChangeData<
'default_auto_archive_duration',
number
>;

interface AuditLogChangeData<K extends string, D extends unknown> {
key: K;
/**
Expand Down
5 changes: 5 additions & 0 deletions payloads/v9/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export interface APIChannel extends APIPartialChannel {
/**
* Amount of seconds a user has to wait before sending another message (0-21600);
* bots, as well as users with the permission `MANAGE_MESSAGES` or `MANAGE_CHANNELS`, are unaffected
*
* `rate_limit_per_user` also applies to thread creation. Users can send one message and create one thread during each `rate_limit_per_user` interval.
*
* For thread channels, `rate_limit_per_user` is only returned if the field is set to a non-zero and non-null value.
* The absence of this field in API calls and Gateway events should indicate that slowmode has been reset to the default value.
*/
rate_limit_per_user?: number;
/**
Expand Down
13 changes: 12 additions & 1 deletion rest/v9/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ export interface RESTPostAPIChannelMessagesThreadsJSONBody {
name: string;
/**
* The amount of time in minutes to wait before automatically archiving the thread
*
* The 3 day and 7 day archive durations require the server to be boosted. The [guild features](https://discord.com/developers/docs/resources/guild#guild-object-guild-features) will indicate if a server is able to use those settings.
*/
auto_archive_duration: ThreadAutoArchiveDuration;
}
Expand All @@ -592,8 +594,15 @@ export type RESTPostAPIChannelMessagesThreadsResult = APIChannel;
export interface RESTPostAPIChannelThreadsJSONBody extends RESTPostAPIChannelMessagesThreadsJSONBody {
/**
* The type of thread to create
*
* In API v9, `type` defaults to `PRIVATE_THREAD`.
* In API v10 this will be changed to be a required field, with no default.
*
* See https://discord.com/developers/docs/resources/channel#channel-object-channel-types
*
* @default 12
*/
type: ChannelType.GuildNewsThread | ChannelType.GuildPublicThread | ChannelType.GuildPrivateThread;
type?: ChannelType.GuildNewsThread | ChannelType.GuildPublicThread | ChannelType.GuildPrivateThread;
}

/**
Expand Down Expand Up @@ -632,6 +641,8 @@ export interface RESTGetAPIChannelThreadsArchivedQuery {

/**
* https://discord.com/developers/docs/resources/channel#list-active-threads
*
* @deprecated Use [List Active Guild Threads](https://discord.com/developers/docs/resources/guild#list-active-threads) instead. Will be removed in v10.
*/
export type RESTGetAPIChannelThreadsResult = APIThreadList;

Expand Down
6 changes: 6 additions & 0 deletions rest/v9/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
APIGuildWidget,
APIGuildWidgetSettings,
APIRole,
APIThreadList,
APIVoiceRegion,
GuildDefaultMessageNotifications,
GuildExplicitContentFilter,
Expand Down Expand Up @@ -303,6 +304,11 @@ export type RESTPatchAPIGuildChannelPositionsJSONBody = Array<{
*/
export type RESTPatchAPIGuildChannelPositionsResult = never;

/**
* https://discord.com/developers/docs/resources/guild#list-active-threads
*/
export type RESTGetAPIGuildThreadsResult = Omit<APIThreadList, 'has_more'>;

/**
* https://discord.com/developers/docs/resources/guild#get-guild-member
*/
Expand Down
12 changes: 11 additions & 1 deletion rest/v9/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,19 @@ export const Routes = {
return parts.join('/') as `/channels/${Snowflake}/threads` | `/channels/${Snowflake}/messages/${Snowflake}/threads`;
},

/**
* Route for:
* - GET `/guilds/{guild.id}/threads/active`
*/
guildActiveThreads(guildId: Snowflake) {
return `/guilds/${guildId}/threads/active` as const;
},

/**
* Route for:
* - GET `/channels/{channel.id}/threads/active`
* (deprecated, use [List Active Guild Threads](https://discord.com/developers/docs/resources/guild#list-active-threads) instead.
* Will be removed in v10.)
* - GET `/channels/{channel.id}/threads/archived/public`
* - GET `/channels/{channel.id}/threads/archived/private`
*/
Expand All @@ -456,7 +466,7 @@ export const Routes = {
* Route for:
* - GET `/channels/{channel.id}/users/@me/threads/archived/prviate`
*/
channelJoinedArhivedThreads(channelId: Snowflake) {
channelJoinedArchivedThreads(channelId: Snowflake) {
return `/channels/${channelId}/users/@me/threads/archived/private` as const;
},

Expand Down

0 comments on commit 47100bc

Please sign in to comment.