Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guild Scheduled Events #1275

Merged
merged 84 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
474aa2f
feat: initial structure
Loliticos Sep 6, 2021
be21548
chore: update typing name
Loliticos Sep 6, 2021
ab0e1cb
feat: typings for GuildEvent
Loliticos Sep 6, 2021
6565285
feat: fix option name
Loliticos Sep 6, 2021
d859185
chore: documment guild events
Loliticos Sep 6, 2021
652201e
feat: rename IDS to IDs
Loliticos Sep 6, 2021
f5b744d
chore: remove extra whitespaces
Loliticos Sep 6, 2021
149cbaf
chore: remove extra whitespaces
Loliticos Sep 6, 2021
75b108e
chore: run lint
Loliticos Sep 6, 2021
5dd0cba
chore: run ts lint
Loliticos Sep 6, 2021
4bb4049
chore: remove whitespace
Loliticos Sep 6, 2021
df8ea66
fix: rename property to events
Loliticos Sep 6, 2021
fb67aa4
fix: update skus type temp
Loliticos Sep 6, 2021
c40cc0a
fix: suggestions
Loliticos Sep 6, 2021
8b8ba84
fix: use ID instead of id
Loliticos Sep 6, 2021
44228da
fix: change event name
Loliticos Sep 6, 2021
714e775
fix: sort permission by increasing value
Loliticos Sep 6, 2021
acae845
fix: parse data to UnixTimestamp
Loliticos Sep 6, 2021
8715696
chore: rename id to ID
Loliticos Sep 6, 2021
e5c36ee
chore: link to discord documentation
Loliticos Sep 6, 2021
4f3e74a
fix: rename event to guildScheduledEventUpdate
Loliticos Sep 6, 2021
50830d6
fix: parse timestamp into an Unix Timestamp
Loliticos Sep 6, 2021
041d9f5
chore: update prop type
Loliticos Sep 6, 2021
8a27f6d
chore: fix jsdoc
Loliticos Sep 6, 2021
5c9ab84
Merge branch 'guild-events' of github.com:Loliticos/eris into guild-e…
Loliticos Sep 6, 2021
7722df4
chore: fix jsdoc and typings
Loliticos Sep 6, 2021
f083944
fix: logic for update event
Loliticos Sep 6, 2021
56814ff
chore: rename variable to cachedEvent
Loliticos Sep 6, 2021
43a2548
chore: add entityType reference link
Loliticos Sep 6, 2021
a44621f
chore: add status reference link
Loliticos Sep 6, 2021
8557b81
feat: guildScheduledEventUser* created
Loliticos Sep 8, 2021
0e2c7fb
chore: fix documentation
Loliticos Sep 8, 2021
4025aa7
documentation: add string union type
Loliticos Sep 8, 2021
6286e76
fix: make event a new GuildEvent
Loliticos Sep 8, 2021
128ec9f
fix: update jsdoc
Loliticos Sep 9, 2021
d319590
fix: update logic and jsdoc
Loliticos Sep 9, 2021
5d212d6
fix: typo
Loliticos Sep 9, 2021
0e74a88
fix: edit instead of create
Loliticos Sep 23, 2021
d8a16bc
typings: document methods
Loliticos Sep 23, 2021
7cdf1a3
typings: rename PartialGuildEvent to GuildEventOptions
Loliticos Sep 23, 2021
8a2655a
fix: correct description
Loliticos Sep 27, 2021
64fd89c
Merge branch 'dev' into guild-events
Loliticos Oct 6, 2021
73dfc6e
Update Constants.js
Loliticos Oct 6, 2021
c2ffb7a
fix: correct permission numbers and position
Loliticos Oct 7, 2021
5ae544c
fix: correct position
Loliticos Oct 7, 2021
d81ec9a
Merge branch 'dev' into guild-events
Loliticos Oct 17, 2021
9cb8a67
feat: rename events
Loliticos Nov 13, 2021
546b5ac
feat: add events to audit log
Loliticos Nov 13, 2021
6a4aca2
merge branch dev
Loliticos Nov 13, 2021
01eea12
fix: new line
Loliticos Nov 13, 2021
bba17b5
style: run lint
Loliticos Nov 13, 2021
5b4779c
fix: extra space
Loliticos Nov 13, 2021
44f5cff
merge branch dev
Loliticos Nov 14, 2021
72d5ceb
fix: merge conflict
Loliticos Nov 14, 2021
e269333
feat: change event position
Loliticos Nov 14, 2021
95c5032
merge branch dev
Loliticos Nov 14, 2021
544b5e3
fix: remove duplicate permissions
Loliticos Nov 14, 2021
5b251a9
Merge branch 'dev' into guild-events
Loliticos Nov 15, 2021
c92fa5b
feat: remove sku properties
Loliticos Nov 15, 2021
314b7bd
feat: add and remove properties
Loliticos Nov 15, 2021
f17ba6f
feat: update endpoints
Loliticos Nov 16, 2021
ce46145
fix: creator instead of creatorID
Loliticos Nov 16, 2021
a1bc115
feat: remove creatorID
Loliticos Nov 16, 2021
076ed21
feat: updates
Loliticos Nov 16, 2021
6e85219
Merge branch 'dev' into guild-events
Loliticos Dec 2, 2021
d828fe6
feat: add guild scheduled events intent
Loliticos Dec 2, 2021
47c5905
feat: remove speakerIDs
Loliticos Dec 2, 2021
c8278ab
feat: document guild method
Loliticos Dec 2, 2021
3fb841f
Merge branch 'dev' of https://github.com/bsian03/eris into 1275
bsian03 Apr 12, 2022
fd0a2ee
[INCOMPLETE] Fix PR
bsian03 Apr 13, 2022
3d143ad
[INCOMPLETE] Fix PR
bsian03 Apr 13, 2022
074af8e
[INCOMPLETE] Fix PR
bsian03 Apr 13, 2022
7f3157b
Fix PR
bsian03 Apr 13, 2022
e0ebb13
Apply suggestions from code review
bsian03 Apr 15, 2022
98314d2
Apply suggestions from code review
bsian03 Apr 15, 2022
a0e55e7
Fix types i hope
bsian03 May 10, 2022
0870d5d
Merge branch 'dev' into guild-events
bsian03 May 23, 2022
bf5cd7d
Merge branch 'dev' into guild-events
DonovanDMC Jun 7, 2022
dea37f0
lint ts
DonovanDMC Jun 7, 2022
fe09b0d
remove trailing comma
DonovanDMC Jun 7, 2022
842ccd0
recalculate perms
DonovanDMC Jun 7, 2022
1c604ed
Merge branch 'dev' into guild-events
DonovanDMC Jun 8, 2022
baebf52
Merge branch 'dev' into guild-events
DonovanDMC Jun 30, 2022
ce99ba7
Merge branch 'dev' into guild-events
DonovanDMC Aug 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const {
GuildChannel,
GuildIntegration,
GuildPreview,
GuildScheduledEvent,
GuildTemplate,
Interaction,
Invite,
Expand Down Expand Up @@ -59,5 +60,5 @@ export const {
VoiceChannel,
VoiceConnection,
VoiceConnectionManager,
VoiceState
VoiceState,
} = Eris;
137 changes: 133 additions & 4 deletions index.d.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Eris.Guild = require("./lib/structures/Guild");
Eris.GuildChannel = require("./lib/structures/GuildChannel");
Eris.GuildIntegration = require("./lib/structures/GuildIntegration");
Eris.GuildPreview = require("./lib/structures/GuildPreview");
Eris.GuildScheduledEvent = require("./lib/structures/GuildScheduledEvent");
Eris.GuildTemplate = require("./lib/structures/GuildTemplate");
Eris.Interaction = require("./lib/structures/Interaction");
Eris.Invite = require("./lib/structures/Invite");
Expand Down
154 changes: 143 additions & 11 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const GuildAuditLogEntry = require("./structures/GuildAuditLogEntry");
const GuildIntegration = require("./structures/GuildIntegration");
const GuildPreview = require("./structures/GuildPreview");
const GuildTemplate = require("./structures/GuildTemplate");
const GuildScheduledEvent = require("./structures/GuildScheduledEvent");
const Invite = require("./structures/Invite");
const Member = require("./structures/Member");
const Message = require("./structures/Message");
Expand Down Expand Up @@ -354,7 +355,7 @@ class Client extends EventEmitter {
/**
* Edits command permissions for a multiple commands in a guild.
* Note: You can only add up to 10 permission overwrites for a command.
* @arg {String} guildID The guild id
* @arg {String} guildID The guild ID
* @arg {Array<Object>} permissions An array of [partial guild command permissions](https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-guild-application-command-permissions-structure)
* @returns {Promise<Array<Object>>} Returns an array of [GuildApplicationCommandPermissions](https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-guild-application-command-permissions-structure) objects.
*/
Expand Down Expand Up @@ -680,6 +681,38 @@ class Client extends EventEmitter {
}).then((guild) => new Guild(guild, this));
}

bsian03 marked this conversation as resolved.
Show resolved Hide resolved
/**
* Create a guild scheduled event
* @arg {String} guildID The guild ID where the event will be created
* @arg {Object} event The event to be created
* @arg {String} [event.channelID] The channel ID of the event. This is optional if `entityType` is `3` (external)
* @arg {String} [event.description] The description of the event
* @arg {Object} [event.entityMetadata] The entity metadata for the scheduled event. This is required if `entityType` is `3` (external)
* @arg {String} [event.entityMetadata.location] Location of the event
* @arg {Number} event.entityType The [entity type](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-types) of the scheduled event
* @arg {String} [event.image] Base 64 encoded image for the scheduled event
* @arg {String} event.name The name of the event
* @arg {String} event.privacyLevel The privacy level of the event
* @arg {Date} [event.scheduledEndTime] The time when the event is scheduled to end. This is required if `entityType` is `3` (external)
* @arg {Date} event.scheduledStartTime The time the event will start
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<GuildScheduledEvent>}
*/
createGuildScheduledEvent(guildID, event, reason) {
return this.requestHandler.request("POST", Endpoints.GUILD_SCHEDULED_EVENTS(guildID), true, {
channel_id: event.channelID,
description: event.description,
entity_metadata: event.entityMetadata,
entity_type: event.entityType,
image: event.image,
name: event.name,
privacy_level: event.privacyLevel,
scheduled_end_time: event.scheduledEndTime,
scheduled_start_time: event.scheduledStartTime,
reason: reason
}).then((data) => new GuildScheduledEvent(data, this));
}

/**
* Create a guild sticker
* @arg {Object} options Sticker options
Expand Down Expand Up @@ -996,7 +1029,7 @@ class Client extends EventEmitter {

/**
* Delete a guild application command
* @arg {String} guildID The guild id
* @arg {String} guildID The guild ID
* @arg {String} commandID The command id
* @returns {Promise}
*/
Expand Down Expand Up @@ -1044,6 +1077,16 @@ class Client extends EventEmitter {
return this.requestHandler.request("DELETE", Endpoints.GUILD_INTEGRATION(guildID, integrationID), true);
}

/**
* Delete a guild scheduled event
* @arg {String} guildID The ID of the guild
* @arg {String} eventID The ID of the event
* @returns {Promise}
*/
deleteGuildScheduledEvent(guildID, eventID) {
return this.requestHandler.request("DELETE", Endpoints.GUILD_SCHEDULED_EVENT(guildID, eventID), true);
}

/**
* Delete a guild sticker
* @arg {String} guildID The ID of the guild
Expand Down Expand Up @@ -1374,7 +1417,7 @@ class Client extends EventEmitter {
/**
* Edits command permissions for a specific command in a guild.
* Note: You can only add up to 10 permission overwrites for a command.
* @arg {String} guildID The guild id
* @arg {String} guildID The guild ID
* @arg {String} commandID The command id
* @arg {Array<Object>} permissions An array of [permissions objects](https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permissions-structure)
* @returns {Promise<Object>} Resolves with a [GuildApplicationCommandPermissions](https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-guild-application-command-permissions-structure) object.
Expand Down Expand Up @@ -1440,7 +1483,7 @@ class Client extends EventEmitter {

/**
* Edit a guild application command
* @arg {String} guildID The guild id
* @arg {String} guildID The guild ID
* @arg {Object} command A command object
* @arg {String} command.name The command name
* @arg {String} [command.description] The command description (Slash Commands Only)
Expand Down Expand Up @@ -1542,6 +1585,41 @@ class Client extends EventEmitter {
}).then((member) => new Member(member, this.guilds.get(guildID), this));
}

/**
* Edit a guild scheduled event
* @arg {String} guildID The guild ID where the event will be edited
* @arg {String} eventID The guild scheduled event ID to be edited
* @arg {Object} event The new guild scheduled event object
* @arg {String} [event.channelID] The channel ID of the event. If updating `entityType` to `3` (external), this **must** be set to `null`
* @arg {String} [event.description] The description of the event
* @arg {Object} [event.entityMetadata] The entity metadata for the scheduled event. This is required if updating `entityType` to `3` (external)
* @arg {String} [event.entityMetadata.location] Location of the event. This is required if updating `entityType` to `3` (external)
* @arg {Number} [event.entityType] The [entity type](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-types) of the scheduled event
* @arg {String} [event.image] Base 64 encoded image for the event
* @arg {String} [event.name] The name of the event
* @arg {String} [event.privacyLevel] The privacy level of the event
* @arg {Date} [event.scheduledEndTime] The time when the scheduled event is scheduled to end. This is required if updating `entityType` to `3` (external)
* @arg {Date} [event.scheduledStartTime] The time the event will start
* @arg {Number} [event.status] The [status](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-status) of the scheduled event
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<GuildScheduledEvent>}
*/
editGuildScheduledEvent(guildID, eventID, event, reason) {
return this.requestHandler.request("PATCH", Endpoints.GUILD_SCHEDULED_EVENT(guildID, eventID), true, {
channel_id: event.channelID,
description: event.description,
entity_metadata: event.entityMetadata,
entity_type: event.entityType,
image: event.image,
name: event.name,
privacy_level: event.privacyLevel,
scheduled_end_time: event.scheduledEndTime,
scheduled_start_time: event.scheduledStartTime,
status: event.status,
reason: reason
});
}

/**
* Edit a guild sticker
* @arg {String} stickerID The ID of the sticker
Expand Down Expand Up @@ -1581,6 +1659,7 @@ class Client extends EventEmitter {
code
});
}

/**
* Update a user's voice state - See [caveats](https://discord.com/developers/docs/resources/guild#modify-user-voice-state-caveats)
* @arg {String} guildID The ID of the guild
Expand Down Expand Up @@ -1903,9 +1982,6 @@ class Client extends EventEmitter {
});
}




/**
* Edit a webhook
* @arg {String} webhookID The ID of the webhook
Expand Down Expand Up @@ -2206,7 +2282,7 @@ class Client extends EventEmitter {

/**
* Get the a guild's application command permissions
* @arg {String} guildID The guild id
* @arg {String} guildID The guild ID
* @arg {String} commandID The command id
* @returns {Promise<Object>} Resolves with a guild application command permissions object.
*/
Expand Down Expand Up @@ -2358,7 +2434,7 @@ class Client extends EventEmitter {

/**
* Get a guild application command
* @arg {String} guildID The guild id
* @arg {String} guildID The guild ID
* @arg {String} commandID The command id
* @returns {Promise<Object>} Resolves with an command object.
*/
Expand All @@ -2371,7 +2447,7 @@ class Client extends EventEmitter {

/**
* Get the all of a guild's application command permissions
* @arg {String} guildID The guild id
* @arg {String} guildID The guild ID
* @returns {Promise<Array<Object>>} Resolves with an array of guild application command permissions objects.
*/
getGuildCommandPermissions(guildID) {
Expand All @@ -2383,7 +2459,7 @@ class Client extends EventEmitter {

/**
* Get a guild's application commands
* @arg {String} guildID The guild id
* @arg {String} guildID The guild ID
* @returns {Promise<Array<Object>>} Resolves with an array of command objects.
*/
getGuildCommands(guildID) {
Expand Down Expand Up @@ -2427,6 +2503,45 @@ class Client extends EventEmitter {
return this.requestHandler.request("GET", Endpoints.GUILD_PREVIEW(guildID), true).then((data) => new GuildPreview(data, this));
}

/**
* Get a guild's scheduled events
* @arg {String} guildID The ID of the guild
* @arg {Object} [options] Options for the request
* @arg {Boolean} [options.withUserCount] Whether to include the number of users subscribed to each event
* @returns {Promise<Array<GuildScheduledEvent>>}
*/
getGuildScheduledEvents(guildID, options = {}) {
options.with_user_count = options.withUserCount;
return this.requestHandler.request("GET", Endpoints.GUILD_SCHEDULED_EVENTS(guildID), true, options).then((data) => data.map((event) => new GuildScheduledEvent(event, this)));
}

/**
* Get a list of users subscribed to a guild scheduled event
* @arg {String} guildID The ID of the guild
* @arg {String} eventID The ID of the event
* @arg {Object} [options] Options for the request
* @arg {String} [options.after] Get users after this user ID. If `options.before` is provided, this will be ignored. Fetching users in between `before` and `after` is not supported
* @arg {String} [options.before] Get users before this user ID
* @arg {Number} [options.limit=100] The number of users to get (max 100). Pagination will only work if one of `options.after` or `options.after` is also provided
* @arg {Boolean} [options.withMember] Include guild member data
* @returns {Promise<Array<{guildScheduledEventID: String, member?: Member, user: User}>>}
*/
getGuildScheduledEventUsers(guildID, eventID, options = {}) {
const guild = this.guilds.get(guildID);

options.with_member = options.withMember;
return this.requestHandler.request("GET", Endpoints.GUILD_SCHEDULED_EVENT_USERS(guildID, eventID), true, options).then((data) => data.map((eventUser) => {
if(eventUser.member) {
eventUser.member.id = eventUser.user.id;
}
return {
guildScheduledEventID: eventUser.guild_scheduled_event_id,
member: eventUser.member && guild ? guild.members.update(eventUser.member) : new Member(eventUser.member),
user: this.users.update(eventUser.user)
};
}));
}

/**
* Get a guild template
* @arg {String} code The template code
Expand Down Expand Up @@ -2815,6 +2930,23 @@ class Client extends EventEmitter {
return this.requestHandler.request("GET", Endpoints.USER_GUILDS("@me"), true, options).then((guilds) => guilds.map((guild) => new Guild(guild, this)));
}

/**
* Get a guild scheduled event via the REST API. REST mode is required to use this endpoint.
* @arg {String} guildID The ID of the guild
* @arg {String} eventID The ID of the guild scheduled event
* @arg {Object} [options] Options for the request
* @arg {Boolean} [options.withUserCount] Whether to include the number of users subscribed to the event
* @returns {Promise<GuildScheduledEvent>}
*/
getRESTGuildScheduledEvent(guildID, eventID, options = {}) {
if(!this.options.restMode) {
return Promise.reject(new Error("Eris REST mode is not enabled"));
}

options.with_user_count = options.withUserCount;
return this.requestHandler.request("GET", Endpoints.GUILD_SCHEDULED_EVENT(guildID, eventID), true, options).then((data) => new GuildScheduledEvent(data, this));
}

/**
* Get a guild sticker via the REST API. REST mode is required to use this endpoint.
* @arg {String} guildID The ID of the guild
Expand Down
25 changes: 23 additions & 2 deletions lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ const Intents = {
guildMessageTyping: 1 << 11,
directMessages: 1 << 12,
directMessageReactions: 1 << 13,
directMessageTyping: 1 << 14
directMessageTyping: 1 << 14,

bsian03 marked this conversation as resolved.
Show resolved Hide resolved
guildScheduledEvents: 1 << 16
};
Intents.allNonPrivileged = Intents.guilds
| Intents.guildBans
Expand All @@ -247,7 +249,8 @@ Intents.allNonPrivileged = Intents.guilds
| Intents.guildMessageTyping
| Intents.directMessages
| Intents.directMessageReactions
| Intents.directMessageTyping;
| Intents.directMessageTyping
| Intents.guildScheduledEvents;
Intents.allPrivileged = Intents.guildMembers
| Intents.guildPresences;
Intents.all = Intents.allNonPrivileged | Intents.allPrivileged;
Expand Down Expand Up @@ -442,6 +445,24 @@ module.exports.PremiumTiers = {
TIER_3: 3
};

module.exports.GuildScheduledEventStatus = {
SCHEDULED: 1,
ACTIVE: 2,
COMPLETED: 3,
CANCELED: 4
};

module.exports.GuildScheduledEventEntityTypes = {
STAGE_INSTANCE: 1,
VOICE: 2,
EXTERNAL: 3
};

module.exports.GuildScheduledEventPrivacyLevel = {
PUBLIC: 1,
bsian03 marked this conversation as resolved.
Show resolved Hide resolved
GUILD_ONLY: 2
};

module.exports.PremiumTypes = {
NONE: 0,
NITRO_CLASSIC: 1,
Expand Down
Loading