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

refactor(interactions): Interactions Refactor #1309

Closed
wants to merge 127 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
b39c438
application command options rewrite
DonovanDMC Nov 28, 2021
b533a92
lint the shit
DonovanDMC Nov 28, 2021
f52ee99
strongly type interaction response data
DonovanDMC Nov 28, 2021
a78119a
remove PingInteraction from `interactionCreate`
DonovanDMC Nov 28, 2021
e1bcd4c
remove UnknownInteraction
DonovanDMC Nov 28, 2021
053351a
remove value from ApplicationCommandOptionsGeneric
DonovanDMC Nov 28, 2021
b3f6904
apparently this doesn't work?
DonovanDMC Nov 28, 2021
d21684a
unpluralize
DonovanDMC Nov 28, 2021
a5e4619
do the thing
DonovanDMC Nov 28, 2021
13a507d
Apply suggestions from code review
DonovanDMC Nov 29, 2021
e0c3273
generic `InteractionDataOptionWithValue` -> `InteractionDataOptionGen…
DonovanDMC Nov 29, 2021
2a8ceaa
lint
DonovanDMC Nov 29, 2021
4d26a0e
finish removing UnknownInteraction
DonovanDMC Nov 29, 2021
4f84249
Interaction client reference & stringify formatting
DonovanDMC Nov 29, 2021
c954875
fix AutocompleteInteraction typings
DonovanDMC Dec 10, 2021
77dffaa
catboy did some shit
DonovanDMC Dec 23, 2021
fb26e5d
we don't do that here
DonovanDMC Dec 23, 2021
258575b
do the thing
DonovanDMC Dec 23, 2021
1ab045b
make `data` optional in InteractionDeferredResponse
DonovanDMC Dec 31, 2021
fee8232
Merge remote-tracking branch 'origin/dev' into interactions-rewrite
DonovanDMC Jan 7, 2022
7de4fe8
resolved.members has `user`
DonovanDMC Jan 7, 2022
b9fabe3
interaction locales
DonovanDMC Jan 13, 2022
791be08
`default_permission` -> `defaultPermission` (#1325)
DonovanDMC Jan 17, 2022
645481b
move locale into #1335
DonovanDMC Feb 9, 2022
e86f0ae
Merge remote-tracking branch 'origin/dev' into interactions-rewrite
DonovanDMC Feb 10, 2022
6322db6
shorten `InteractionDataOptionGeneric`
DonovanDMC Feb 24, 2022
2655fa1
utility types for some unions
DonovanDMC Feb 25, 2022
934cf67
`ApplicationCommandOptionGeneric` -> `*Base`
DonovanDMC Mar 25, 2022
97045bf
funnel everything through base
DonovanDMC Mar 25, 2022
49c8df9
generic for `getCommand`
DonovanDMC Mar 25, 2022
f63662e
generic for `createCommand`
DonovanDMC Mar 25, 2022
595ed47
merge upstream
DonovanDMC Mar 25, 2022
d209cb5
Merge branch 'abalabahaha:dev' into interactions-rewrite
DonovanDMC Mar 31, 2022
34e4407
genericize InteractionData & other things
DonovanDMC Apr 12, 2022
dbbb496
Merge remote-tracking branch 'remotes/upstream/dev' into interactions…
DonovanDMC Apr 12, 2022
52a6b84
remove old interfaces
DonovanDMC Apr 12, 2022
45be2dc
another utility union
DonovanDMC Apr 12, 2022
15008ee
implement suggestion
DonovanDMC Apr 12, 2022
e1614ba
alphabetize & fix some stuff
DonovanDMC Apr 12, 2022
dd64c3e
Merge branch 'interactions-rewrite' of https://github.com/DonovanDMC/…
DonovanDMC Apr 12, 2022
2796779
remove erraneous whitespace
DonovanDMC Apr 12, 2022
6c542e6
pluralize
DonovanDMC Apr 13, 2022
ea7a9bf
`ApplicationCommandBase` -> `ApplicationCommandOptionsBase`
DonovanDMC Apr 13, 2022
a2f0e6c
flags are not a boolean
DonovanDMC Apr 13, 2022
9e2e56f
remove some unions
DonovanDMC Apr 13, 2022
3636448
re-sort
DonovanDMC Apr 13, 2022
cd74450
remove dup
DonovanDMC Apr 13, 2022
96b90d5
do the thing
DonovanDMC Apr 13, 2022
1446037
bsian a bitch
DonovanDMC Apr 13, 2022
c11a153
I never lint, apparently
DonovanDMC Apr 13, 2022
f144ff5
I bestoweth thy name of `ApplicationCommandOption`
DonovanDMC Apr 13, 2022
a1f5410
Fix Mutually Exclusive options
bsian03 Apr 14, 2022
b558a1b
donovan a bitch
bsian03 Apr 14, 2022
999ca7e
I did the thing again
DonovanDMC Apr 14, 2022
ac129a1
do more thing
DonovanDMC Apr 14, 2022
ebe62ad
alphabetize interfaces
DonovanDMC Apr 14, 2022
d32b8dc
createGuildCommand generic
DonovanDMC Apr 14, 2022
e3f8da1
do the pong
DonovanDMC Apr 14, 2022
eff0ad9
`ApplicationCommandOptionsChoice` unknown fallback
DonovanDMC Apr 14, 2022
2444161
extract `data` types into their own interfaces
DonovanDMC Apr 14, 2022
6ba24dd
stuff
DonovanDMC Apr 14, 2022
6048d30
remove command name regex
DonovanDMC Apr 15, 2022
3f617c2
push old changes
DonovanDMC Apr 16, 2022
d98087a
extract `resolved` into an interface
DonovanDMC Apr 19, 2022
2b67b10
sort stuff yet again
DonovanDMC Apr 19, 2022
ae51d14
move AutocompleteInteractionData
DonovanDMC Apr 19, 2022
144306d
deaf & mute do not exist on the member object either way
DonovanDMC Apr 23, 2022
3b217a1
include generic on getGuildCommand
DonovanDMC May 7, 2022
02e7ba9
explicitly type Interaction#types
DonovanDMC May 7, 2022
889a633
add error check to getGuildCommands
DonovanDMC May 7, 2022
c233ec7
remove PingInteraction from interactionCreate
DonovanDMC May 7, 2022
8aa4b66
merge upstream
DonovanDMC May 9, 2022
3a73689
Merge remote-tracking branch 'upstream/dev' into interactions-rewrite
DonovanDMC May 10, 2022
40bd68e
don't know how I ended up with `ApplicationCommandOptionsTypes`
DonovanDMC May 10, 2022
d823da2
fix Role constructor in CommandInteraction
DonovanDMC May 13, 2022
a9aa32f
Upstream Update
DonovanDMC May 15, 2022
2fa5f87
fix Structure omissions
DonovanDMC May 18, 2022
e1235b4
properly exclude value from InteractionDataOptionsBase
DonovanDMC May 19, 2022
6f3067e
InteractionDataOptionsWithOptions
DonovanDMC May 20, 2022
c1d6a8b
properly change camel cased properties in bulk
DonovanDMC May 21, 2022
19a1c97
webhooks cannot use components
DonovanDMC May 21, 2022
71f264e
application comands no longer take an hour to sync
DonovanDMC May 21, 2022
8eeef2c
Revert "webhooks cannot use components"
DonovanDMC May 21, 2022
e28ac6a
add webhook creation notice
DonovanDMC May 21, 2022
2787bc2
man I love that no one told me *I pushed a token*
DonovanDMC May 23, 2022
4e8472c
remove parameter checks
DonovanDMC May 23, 2022
9333e2a
merge upstream
DonovanDMC May 28, 2022
0fe1272
I'll finally stop ignoring this
DonovanDMC May 28, 2022
2cd42a6
Properties in PartialEmoji are required
DonovanDMC May 30, 2022
daeb85d
resolved.channels PartialChannel -> AnyChannel
DonovanDMC Jun 1, 2022
346afb8
sort resolved
DonovanDMC Jun 1, 2022
9965bed
add or incase no channel type
DonovanDMC Jun 1, 2022
f1dcc00
Fold abalabahaha/eris#1335
DonovanDMC Jun 1, 2022
42d70ac
ApplicationCommand class and more
DonovanDMC Jun 1, 2022
fbe7355
touchups
DonovanDMC Jun 1, 2022
f8d5748
remove id from application command structure
DonovanDMC Jun 2, 2022
da6b147
e
DonovanDMC Jun 2, 2022
88400d4
exclude subcommand/subcommandgroup from InteractionDataOption types
DonovanDMC Jun 5, 2022
66db522
Merge remote-tracking branch 'upstream/dev' into interactions-rewrite
DonovanDMC Jun 5, 2022
3ab3cd1
ApplicationCommand#toJSON
DonovanDMC Jun 6, 2022
abd0ff8
Interaction#toJSON
DonovanDMC Jun 6, 2022
03997c0
Consistency & QoL
DonovanDMC Jun 6, 2022
c9fe6c7
Merge remote-tracking branch 'upstream/dev' into interactions-rewrite
DonovanDMC Jun 6, 2022
0d2fa4b
remove useless constructors
DonovanDMC Jun 6, 2022
c3322a3
Merge remote-tracking branch 'upstream/dev' into interactions-rewrite
DonovanDMC Jun 8, 2022
b713654
add back InteractionContentEdit
DonovanDMC Jun 8, 2022
33c4826
fix(editChannel): fix `videoQualityMode` & add `permissionOverwrites`
aicushman Jun 8, 2022
fe5ca98
Merge remote-tracking branch 'upstream/dev' into interactions-rewrite
DonovanDMC Jun 8, 2022
27c068c
Fix `dmPermission` typings
DonovanDMC Jun 9, 2022
011b2e9
Fix `edit` typings
DonovanDMC Jun 9, 2022
ce86013
actiually assign type
DonovanDMC Jun 9, 2022
9002626
fix ApplicationCommand `type`
DonovanDMC Jun 9, 2022
403a952
fully split up application command structures
DonovanDMC Jun 16, 2022
504ee50
use generic
DonovanDMC Jun 16, 2022
08de869
Merge branch 'dev' into interactions-rewrite
DonovanDMC Jun 18, 2022
e4f632a
Merge remote-tracking branch 'upstream/dev' into interactions-rewrite
DonovanDMC Jun 30, 2022
407d057
make Interaction#channel optional
DonovanDMC Jun 30, 2022
09aaa12
allow string in `editParent`
DonovanDMC Jul 5, 2022
8c35c7c
Merge remote-tracking branch 'upstream/dev' into interactions-rewrite
DonovanDMC Jul 5, 2022
4e7313d
string min-max
DonovanDMC Jul 9, 2022
090a648
lint
DonovanDMC Jul 9, 2022
9f11ccb
make `user` always present
DonovanDMC Jul 18, 2022
5d5666a
make `channel_types` like the others
DonovanDMC Jul 24, 2022
f4ea2f6
OrGaNiZaTiOn
DonovanDMC Jul 24, 2022
587538a
min/max string length
DonovanDMC Jul 24, 2022
7614b78
lint
DonovanDMC Jul 24, 2022
9c4abe1
Merge branch 'dev' into interactions-rewrite
DonovanDMC Aug 18, 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
2 changes: 1 addition & 1 deletion esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default function(token, options) {
}

export const {
ApplicationCommand,
AutocompleteInteraction,
Base,
Bucket,
Expand Down Expand Up @@ -53,7 +54,6 @@ export const {
ThreadChannel,
ThreadMember,
UnavailableGuild,
UnknownInteraction,
User,
VERSION,
VoiceChannel,
Expand Down
2 changes: 0 additions & 2 deletions examples/applicationCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const bot = new Eris("BOT TOKEN", {
bot.on("ready", async () => { // When the bot is ready
console.log("Ready!"); // Log "Ready!"

//Note: You should use guild commands to test, as they update instantly. Global commands can take up to an hour to update.

const commands = await bot.getCommands();

if(!commands.length) {
Expand Down
475 changes: 240 additions & 235 deletions index.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function Eris(token, options) {
return new Client(token, options);
}

Eris.ApplicationCommand = require("./lib/structures/ApplicationCommand");
Eris.AutocompleteInteraction = require("./lib/structures/AutocompleteInteraction");
Eris.Base = require("./lib/structures/Base");
Eris.Bucket = require("./lib/util/Bucket");
Expand Down Expand Up @@ -54,7 +55,6 @@ Eris.TextVoiceChannel = require("./lib/structures/TextVoiceChannel");
Eris.ThreadChannel = require("./lib/structures/ThreadChannel");
Eris.ThreadMember = require("./lib/structures/ThreadMember");
Eris.UnavailableGuild = require("./lib/structures/UnavailableGuild");
Eris.UnknownInteraction = require("./lib/structures/UnknownInteraction");
Eris.User = require("./lib/structures/User");
Eris.VERSION = require("./package.json").version;
Eris.VoiceChannel = require("./lib/structures/VoiceChannel");
Expand Down
336 changes: 117 additions & 219 deletions lib/Client.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2338,7 +2338,7 @@ class Shard extends EventEmitter {
/**
* Fired when an interaction is created
* @event Client#interactionCreate
* @prop {PingInteraction | CommandInteraction | ComponentInteraction | AutocompleteInteraction | UnknownInteraction} Interaction The Interaction that was created
* @prop {CommandInteraction | ComponentInteraction | AutocompleteInteraction} Interaction The Interaction that was created
*/
this.emit("interactionCreate", Interaction.from(packet.d, this.client));
break;
Expand Down
95 changes: 95 additions & 0 deletions lib/structures/ApplicationCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const Base = require("./Base");

/**
* Represents an application command
* @prop {String} applicationID The ID of the application that this command belongs to
* @prop {String?} defaultMemberPermissions The [permissions](https://discord.com/developers/docs/topics/permissions) required by default for this command to be usable
* @prop {String} description The description of the command (empty for user & message commands)
* @prop {Object?} descriptionLocalizations A map of [locales](https://discord.com/developers/docs/reference#locales) to descriptions for that locale
* @prop {Boolean?} dmPermission If this command can be used in direct messages (global commands only)
* @prop {String?} guildID The ID of the guild associated with this command (guild commands only)
* @prop {String} id The ID of the application command
* @prop {String} name The name of the command
* @prop {Object?} nameLocalizations A map of [locales](https://discord.com/developers/docs/reference#locales) to names for that locale
* @prop {Object[]?} options The [options](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure) associated with this command
* @prop {Number} type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types)
* @prop {String} version The id of the version of this command
*/
class ApplicationCommand extends Base {
constructor(data, client) {
super(data.id);
this._client = client;
this.applicationID = data.application_id;
this.name = data.name;
this.description = data.description;
this.type = data.type;
this.version = data.version;

if(data.guild_id !== undefined) {
this.guildID = data.guild_id;
}

if(data.name_localizations !== undefined) {
this.nameLocalizations = data.name_localizations;
}

if(data.description_localizations !== undefined) {
this.descriptionLocalizations = data.description_localizations;
}

if(data.options !== undefined) {
this.options = data.options;
}

if(data.default_member_permissions !== undefined) {
this.defaultMemberPermissions = data.default_member_permissions;
}

if(data.dm_permission !== undefined) {
this.dmPermission = data.dm_permission;
}
}

/**
* Delete This command
* @returns {Promise}
*/
delete() {
return this.guildID === undefined ? this._client.deleteCommand.call(this._client, this.id) : this._client.deleteGuildCommand.call(this._client, this.guildID, this.id);
}

/**
* Edit this application command
* @arg {Object} options The properties to edit
* @arg {String} [options.name] The command name
* @arg {Object} [options.nameLocalizations] A map of [locales](https://discord.com/developers/docs/reference#locales) to names for that locale
* @arg {String} [options.description] The command description (chat input commands only)
* @arg {Object} [options.descriptionLocalizations] A map of [locales](https://discord.com/developers/docs/reference#locales) to descriptions for that locale
* @arg {Array<Object>} [options.options] An array of [command options](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure)
* @arg {String} [options.defaultMemberPermissions] The [permissions](https://discord.com/developers/docs/topics/permissions) required by default for this command to be usable
* @arg {Boolean} [options.dmPermission] If this command can be used in direct messages (global commands only)
* @returns {Promise}
*/
edit(options) {
return this.guildID === undefined ? this._client.editCommand.call(this._client, this.id, options) : this._client.editGuildCommand.call(this._client, this.id, this.guildID, options);
}

toJSON(props = []) {
return super.toJSON([
"applicationID",
"defaultMemberPermissions",
"description",
"descriptionLocalizations",
"dmPermission",
"guildID",
"name",
"nameLocalizations",
"options",
"type",
"version",
...props
]);
}
}

module.exports = ApplicationCommand;
51 changes: 6 additions & 45 deletions lib/structures/AutocompleteInteraction.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,24 @@
"use strict";

const Interaction = require("./Interaction");
const Member = require("./Member");
const Permission = require("./Permission");
const {InteractionResponseTypes} = require("../Constants");

/**
* Represents an application command autocomplete interaction. See Interaction for more properties.
* @extends Interaction
* @prop {Permission?} appPermissions The permissions the app or bot has within the channel the interaction was sent from
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached.
* @prop {Object} data The data attached to the interaction
* @prop {String} data.id The ID of the Application Command
* @prop {String} data.name The command name
* @prop {Number} data.type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types)
* @prop {String?} data.target_id The id the of user or message targetted by a context menu command
* @prop {Array<Object>?} data.options The run Application Command options
* @prop {String} data.options[].name The name of the Application Command option
* @prop {Number} data.options[].type Command option type, 1-10
* @prop {(String | Number | Boolean)?} data.options[].value The value of the run Application Command (Mutually exclusive with options)
* @prop {Boolean?} data.options[].focused Whether or not the option is focused
* @prop {Array<Object>?} data.options[].options The run Application Command options (Mutually exclusive with value)
* @prop {String?} guildID The ID of the guild in which the interaction was created
* @prop {Member?} member The member who triggered the interaction (This is only sent when the interaction is invoked within a guild)
* @prop {User?} user The user who triggered the interaction (This is only sent when the interaction is invoked within a dm)
* @prop {Number} data.options[].type The [option type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type)
* @prop {(String | Number | Boolean)?} data.options[].value The option value (Mutually exclusive with options)
* @prop {Boolean?} data.options[].focused If the option is focused
* @prop {Array<Object>?} data.options[].options Sub-options (Mutually exclusive with value, subcommand/subcommandgroup)
*/
class AutocompleteInteraction extends Interaction {
constructor(info, client) {
super(info, client);

this.channel = this._client.getChannel(info.channel_id) || {
id: info.channel_id
};

this.data = info.data;

if(info.guild_id !== undefined) {
this.guildID = info.guild_id;
}

if(info.member !== undefined) {
if(this.channel.guild) {
info.member.id = info.member.user.id;
this.member = this.channel.guild.members.update(info.member, this.channel.guild);
} else {
const guild = this._client.guilds.get(info.guild_id);
this.member = new Member(info.member, guild, this._client);
}
}

if(info.user !== undefined) {
this.user = this._client.users.update(info.user, client);
}

if(info.app_permissions !== undefined) {
this.appPermissions = new Permission(info.app_permissions);
}
}

/**
* Acknowledges the autocomplete interaction with a result of choices.
Expand All @@ -66,7 +28,7 @@ class AutocompleteInteraction extends Interaction {
* @arg {String} choices[].value The choice value to return to the bot
* @returns {Promise}
*/
async acknowledge(choices) {
acknowledge(choices) {
return this.result(choices);
}

Expand All @@ -78,7 +40,7 @@ class AutocompleteInteraction extends Interaction {
* @arg {String} choices[].value The choice value to return to the bot
* @returns {Promise}
*/
async result(choices) {
result(choices) {
if(this.acknowledged === true) {
throw new Error("You have already acknowledged this interaction.");
}
Expand All @@ -87,7 +49,6 @@ class AutocompleteInteraction extends Interaction {
data: {choices}
}).then(() => this.update());
}

}

module.exports = AutocompleteInteraction;
Loading