Skip to content

Commit

Permalink
feat: add guild scheduled event (#186)
Browse files Browse the repository at this point in the history
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
  • Loading branch information
iShibi and vladfrangu authored Nov 25, 2021
1 parent f2d62e3 commit d333962
Show file tree
Hide file tree
Showing 42 changed files with 1,550 additions and 16 deletions.
55 changes: 55 additions & 0 deletions deno/gateway/v8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
APIChannel,
APIEmoji,
APIGuild,
APIGuildScheduledEvent,
APIGuildIntegration,
APIGuildMember,
APIMessage,
Expand Down Expand Up @@ -183,6 +184,7 @@ export enum GatewayIntentBits {
DirectMessages = 1 << 12,
DirectMessageReactions = 1 << 13,
DirectMessageTyping = 1 << 14,
GuildScheduledEvents = 1 << 16,
}

/**
Expand Down Expand Up @@ -233,6 +235,11 @@ export enum GatewayDispatchEvents {
VoiceServerUpdate = 'VOICE_SERVER_UPDATE',
VoiceStateUpdate = 'VOICE_STATE_UPDATE',
WebhooksUpdate = 'WEBHOOKS_UPDATE',
GuildScheduledEventCreate = 'GUILD_SCHEDULED_EVENT_CREATE',
GuildScheduledEventUpdate = 'GUILD_SCHEDULED_EVENT_UPDATE',
GuildScheduledEventDelete = 'GUILD_SCHEDULED_EVENT_DELETE',
GuildScheduledEventUserAdd = 'GUILD_SCHEDULED_EVENT_USER_ADD',
GuildScheduledEventUserRemove = 'GUILD_SCHEDULED_EVENT_USER_REMOVE',
}

export type GatewaySendPayload =
Expand Down Expand Up @@ -265,6 +272,11 @@ export type GatewayDispatchPayload =
| GatewayGuildModifyDispatch
| GatewayGuildRoleDeleteDispatch
| GatewayGuildRoleModifyDispatch
| GatewayGuildScheduledEventCreateDispatch
| GatewayGuildScheduledEventUpdateDispatch
| GatewayGuildScheduledEventDeleteDispatch
| GatewayGuildScheduledEventUserAddDispatch
| GatewayGuildScheduledEventUserRemoveDispatch
| GatewayGuildStickersUpdateDispatch
| GatewayIntegrationCreateDispatch
| GatewayIntegrationDeleteDispatch
Expand Down Expand Up @@ -808,6 +820,49 @@ export interface GatewayGuildRoleDeleteDispatchData {
role_id: Snowflake;
}

export type GatewayGuildScheduledEventCreateDispatch = DataPayload<
GatewayDispatchEvents.GuildScheduledEventCreate,
GatewayGuildScheduledEventCreateDispatchData
>;

export type GatewayGuildScheduledEventCreateDispatchData = APIGuildScheduledEvent;

export type GatewayGuildScheduledEventUpdateDispatch = DataPayload<
GatewayDispatchEvents.GuildScheduledEventUpdate,
GatewayGuildScheduledEventUpdateDispatchData
>;

export type GatewayGuildScheduledEventUpdateDispatchData = APIGuildScheduledEvent;

export type GatewayGuildScheduledEventDeleteDispatch = DataPayload<
GatewayDispatchEvents.GuildScheduledEventDelete,
GatewayGuildScheduledEventDeleteDispatchData
>;

export type GatewayGuildScheduledEventDeleteDispatchData = APIGuildScheduledEvent;

export type GatewayGuildScheduledEventUserAddDispatch = DataPayload<
GatewayDispatchEvents.GuildScheduledEventUserAdd,
GatewayGuildScheduledEventUserAddDispatchData
>;

export interface GatewayGuildScheduledEventUserAddDispatchData {
guild_scheduled_event_id: Snowflake;
user_id: Snowflake;
guild_id: Snowflake;
}

export type GatewayGuildScheduledEventUserRemoveDispatch = DataPayload<
GatewayDispatchEvents.GuildScheduledEventUserRemove,
GatewayGuildScheduledEventUserAddDispatchData
>;

export interface GatewayGuildScheduledEventUserRemoveDispatchData {
guild_scheduled_event_id: Snowflake;
user_id: Snowflake;
guild_id: Snowflake;
}

/**
* https://discord.com/developers/docs/topics/gateway#integration-create
*/
Expand Down
55 changes: 55 additions & 0 deletions deno/gateway/v9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
APIChannel,
APIEmoji,
APIGuild,
APIGuildScheduledEvent,
APIGuildIntegration,
APIGuildMember,
APIMessage,
Expand Down Expand Up @@ -186,6 +187,7 @@ export enum GatewayIntentBits {
DirectMessages = 1 << 12,
DirectMessageReactions = 1 << 13,
DirectMessageTyping = 1 << 14,
GuildScheduledEvents = 1 << 16,
}

/**
Expand Down Expand Up @@ -242,6 +244,11 @@ export enum GatewayDispatchEvents {
VoiceServerUpdate = 'VOICE_SERVER_UPDATE',
VoiceStateUpdate = 'VOICE_STATE_UPDATE',
WebhooksUpdate = 'WEBHOOKS_UPDATE',
GuildScheduledEventCreate = 'GUILD_SCHEDULED_EVENT_CREATE',
GuildScheduledEventUpdate = 'GUILD_SCHEDULED_EVENT_UPDATE',
GuildScheduledEventDelete = 'GUILD_SCHEDULED_EVENT_DELETE',
GuildScheduledEventUserAdd = 'GUILD_SCHEDULED_EVENT_USER_ADD',
GuildScheduledEventUserRemove = 'GUILD_SCHEDULED_EVENT_USER_REMOVE',
}

export type GatewaySendPayload =
Expand Down Expand Up @@ -274,6 +281,11 @@ export type GatewayDispatchPayload =
| GatewayGuildModifyDispatch
| GatewayGuildRoleDeleteDispatch
| GatewayGuildRoleModifyDispatch
| GatewayGuildScheduledEventCreateDispatch
| GatewayGuildScheduledEventUpdateDispatch
| GatewayGuildScheduledEventDeleteDispatch
| GatewayGuildScheduledEventUserAddDispatch
| GatewayGuildScheduledEventUserRemoveDispatch
| GatewayGuildStickersUpdateDispatch
| GatewayIntegrationCreateDispatch
| GatewayIntegrationDeleteDispatch
Expand Down Expand Up @@ -818,6 +830,49 @@ export interface GatewayGuildRoleDeleteDispatchData {
role_id: Snowflake;
}

export type GatewayGuildScheduledEventCreateDispatch = DataPayload<
GatewayDispatchEvents.GuildScheduledEventCreate,
GatewayGuildScheduledEventCreateDispatchData
>;

export type GatewayGuildScheduledEventCreateDispatchData = APIGuildScheduledEvent;

export type GatewayGuildScheduledEventUpdateDispatch = DataPayload<
GatewayDispatchEvents.GuildScheduledEventUpdate,
GatewayGuildScheduledEventUpdateDispatchData
>;

export type GatewayGuildScheduledEventUpdateDispatchData = APIGuildScheduledEvent;

export type GatewayGuildScheduledEventDeleteDispatch = DataPayload<
GatewayDispatchEvents.GuildScheduledEventDelete,
GatewayGuildScheduledEventDeleteDispatchData
>;

export type GatewayGuildScheduledEventDeleteDispatchData = APIGuildScheduledEvent;

export type GatewayGuildScheduledEventUserAddDispatch = DataPayload<
GatewayDispatchEvents.GuildScheduledEventUserAdd,
GatewayGuildScheduledEventUserAddDispatchData
>;

export interface GatewayGuildScheduledEventUserAddDispatchData {
guild_scheduled_event_id: Snowflake;
user_id: Snowflake;
guild_id: Snowflake;
}

export type GatewayGuildScheduledEventUserRemoveDispatch = DataPayload<
GatewayDispatchEvents.GuildScheduledEventUserRemove,
GatewayGuildScheduledEventUserAddDispatchData
>;

export interface GatewayGuildScheduledEventUserRemoveDispatchData {
guild_scheduled_event_id: Snowflake;
user_id: Snowflake;
guild_id: Snowflake;
}

/**
* https://discord.com/developers/docs/topics/gateway#integration-create
*/
Expand Down
31 changes: 27 additions & 4 deletions deno/payloads/v8/auditLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { StickerFormatType } from './sticker.ts';
import type { APIUser } from './user.ts';
import type { APIWebhook } from './webhook.ts';
import type { StageInstancePrivacyLevel } from './stageInstance.ts';
import type { GuildScheduledEventEntityType, GuildScheduledEventStatus } from './guildScheduledEvent.ts';

/**
* https://discord.com/developers/docs/resources/audit-log#audit-log-object-audit-log-structure
Expand Down Expand Up @@ -144,6 +145,10 @@ export enum AuditLogEvent {
StickerCreate = 90,
StickerUpdate,
StickerDelete,

GuildScheduledEventCreate = 100,
GuildScheduledEventUpdate,
GuildScheduledEventDelete,
}

/**
Expand Down Expand Up @@ -302,15 +307,18 @@ export type APIAuditLogChange =
| APIAuditLogChangeKeyFormatType
| APIAuditLogChangeKeyAsset
| APIAuditLogChangeKeyAvailable
| APIAuditLogChangeKeyGuildId;
| APIAuditLogChangeKeyGuildId
| APIAuditLogChangeKeyEntityType
| APIAuditLogChangeKeyStatus
| APIAuditLogChangeKeyLocation;

/**
* Returned when an entity's name is changed
*/
export type APIAuditLogChangeKeyName = AuditLogChangeData<'name', string>;

/**
* Returned when a guild's or sticker's description is changed
* Returned when a guild's or sticker's or guild scheduled event's description is changed
*/
export type APIAuditLogChangeKeyDescription = AuditLogChangeData<'description', string>;

Expand Down Expand Up @@ -502,7 +510,7 @@ export type APIAuditLogChangeKeyDeny = AuditLogChangeData<'deny', string>;
export type APIAuditLogChangeKeyCode = AuditLogChangeData<'code', string>;

/**
* Returned when an invite's channel_id is changed
* Returned when an invite's or guild scheduled event's channel_id is changed
*/
export type APIAuditLogChangeKeyChannelId = AuditLogChangeData<'channel_id', Snowflake>;

Expand Down Expand Up @@ -582,7 +590,7 @@ export type APIAuditLogChangeKeyExpireGracePeriod = AuditLogChangeData<'expire_g
export type APIAuditLogChangeKeyUserLimit = AuditLogChangeData<'user_limit', number>;

/**
* Returned when privacy level of a stage instance is changed
* Returned when privacy level of a stage instance or guild scheduled event is changed
*/
export type APIAuditLogChangeKeyPrivacyLevel = AuditLogChangeData<'privacy_level', StageInstancePrivacyLevel>;

Expand Down Expand Up @@ -611,6 +619,21 @@ export type APIAuditLogChangeKeyAvailable = AuditLogChangeData<'available', bool
*/
export type APIAuditLogChangeKeyGuildId = AuditLogChangeData<'guild_id', Snowflake>;

/**
* Returned when entity type of a guild scheduled event is changed
*/
export type APIAuditLogChangeKeyEntityType = AuditLogChangeData<'entity_type', GuildScheduledEventEntityType>;

/**
* Returned when status of a guild scheduled event is changed
*/
export type APIAuditLogChangeKeyStatus = AuditLogChangeData<'status', GuildScheduledEventStatus>;

/**
* Returned when location of a guild scheduled event is changed
*/
export type APIAuditLogChangeKeyLocation = AuditLogChangeData<'location', string>;

interface AuditLogChangeData<K extends string, D extends unknown> {
key: K;
/**
Expand Down
9 changes: 9 additions & 0 deletions deno/payloads/v8/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { APIStageInstance } from './stageInstance.ts';
import type { APISticker } from './sticker.ts';
import type { APIUser } from './user.ts';
import type { GatewayVoiceState } from './voice.ts';
import type { APIGuildScheduledEvent } from './guildScheduledEvent.ts';

/**
* https://discord.com/developers/docs/resources/guild#unavailable-guild-object
Expand Down Expand Up @@ -325,6 +326,14 @@ export interface APIGuild extends APIPartialGuild {
* See https://discord.com/developers/docs/resources/sticker#sticker-object
*/
stickers: APISticker[];
/**
* The scheduled events in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object
*/
guild_scheduled_events?: APIGuildScheduledEvent[];
}

/**
Expand Down
104 changes: 104 additions & 0 deletions deno/payloads/v8/guildScheduledEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import type { APIUser } from './user.ts';
import type { Snowflake } from '../../globals.ts';

export interface APIGuildScheduledEvent {
/**
* The id of the guild event
*/
id: Snowflake;
/**
* The guild id which the scheduled event belongs to
*/
guild_id: Snowflake;
/**
* The channel id in which the scheduled event will be hosted, or `null` if entity type is `EXTERNAL`
*/
channel_id: Snowflake | null;
/**
* The id of the user that created the scheduled event
*/
creator_id: Snowflake | null;
/**
* The name of the scheduled event
*/
name: string;
/**
* The description of the scheduled event
*/
description?: string;
/**
* The time the scheduled event will start
*/
scheduled_start_time: string;
/**
* The time at which the guild event will end, or `null` if the event does not have a scheduled time to end
*/
scheduled_end_time: string | null;
/**
* The privacy level of the scheduled event
*/
privacy_level: GuildScheduledEventPrivacyLevel;
/**
* The status of the scheduled event
*/
status: GuildScheduledEventStatus;
/**
* The type of hosting entity associated with the scheduled event
*/
entity_type: GuildScheduledEventEntityType;
/**
* The id of the hosting entity associated with the scheduled event
*/
entity_id: Snowflake | null;
/**
* The entity metadata for the scheduled event
*/
entity_metadata: APIGuildScheduledEventEntityMetadata;
/**
* The user that created the scheduled event
*/
creator?: APIUser;
/**
* The number of users subscribed to the scheduled event
*/
user_count?: number;
}

/**
* https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-metadata
*/
export interface APIGuildScheduledEventEntityMetadata {
/**
* The location of the scheduled event
*/
location?: string;
}

/**
* https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-types
*/
export enum GuildScheduledEventEntityType {
StageInstance = 1,
Voice,
External,
}

/**
* https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-status
*/
export enum GuildScheduledEventStatus {
Scheduled = 1,
Active,
Completed,
Canceled,
}

/**
* https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-privacy-level
*/
export enum GuildScheduledEventPrivacyLevel {
/**
* The scheduled event is only accessible to guild members
*/
GuildOnly = 2,
}
Loading

0 comments on commit d333962

Please sign in to comment.