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

feat(templates): add interaction handler templates #166

Closed
wants to merge 8 commits into from
Closed

feat(templates): add interaction handler templates #166

wants to merge 8 commits into from

Conversation

devramsean0
Copy link
Contributor

Title says it all,
all TS ones are tested and the JS ones are from the guide

@devramsean0 devramsean0 requested a review from enxg as a code owner September 30, 2022 19:06

Verified

This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Collaborator

@enxg enxg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add newlines to the end of the files.

@SerenModz21
Copy link

SerenModz21 commented Sep 30, 2022

the indents on these templates are pretty messy, some of the editReply keywords are missing the await keyword and spacing should be added around the objects. eg.

- interaction.editReply({content: "Hello World"})
+ await interaction.editReply({ content: "Hello World" })

Note: this is just my opinion

@favna favna changed the title Feat(templates): Add Interaction-handler templates feat(templates): add interaction handler templates Sep 30, 2022
"category": "interaction-handlers",
}
---
const { InteractionHandler, InteractionHandlerTypes } = require('@sapphire/framework');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all template files use the Sapphire prettier config to format them. Copy the template code to the prettier playground then paste the result back.

Also for all JS template files please add JSDoc comments similar to the already existing ones to add some basic types to JS code

Copy link
Contributor Author

@devramsean0 devramsean0 Oct 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So adding

	/**
		* @param {InteractionHandler.Context} context
	*/

to every JS interaction-handler template

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Comment on lines +13 to +23
public override async run(interaction: AutocompleteInteraction) {
// Do Whatever
await interaction.editReply({ content: 'Hello World' });
}

public override async parse(interaction: AutocompleteInteraction) {
// Make sure the interaction you want is what you get
if (!interaction.customId.startsWith('{{name}}')) return this.none();
await interaction.deferReply();
return this.some();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should do the same as the JS template!

@ApplyOptions<InteractionHandler.Options>({
type: InteractionHandlerTypes.Autocomplete
})
export default class extends InteractionHandler {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do export defaults in other templates

Comment on lines +5 to +29
const { InteractionHandler, InteractionHandlerTypes } = require('@sapphire/framework');
class ButtonHandler extends InteractionHandler {
/**
* @param {InteractionHandler.Context} context
*/
constructor(ctx, options) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.Button
});
}

parse(interaction) {
if (interaction.customId !== 'my-awesome-button') return this.none();
return this.some();
}

async run(interaction) {
await interaction.reply({
content: 'Hello from a button interaction handler!',
// Let's make it so only the person who pressed the button can see this message!
ephemeral: true
});
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting is not done

});
}

parse(interaction) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to be consistent with the parse vs run location in the files!

Comment on lines +6 to +28
class ModalHandler extends InteractionHandler {
/**
* @param {InteractionHandler.Context} context
*/
constructor(ctx, options) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.ModalSubmit
});
}

parse(interaction) {
if (interaction.customId !== 'hello-popup') return this.none();
return this.some();
}

async run(interaction) {
await interaction.reply({
content: 'Thank you for submitting the form!',
ephemeral: true
});
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Comment on lines +6 to +28
class MenuHandler extends InteractionHandler {
/**
* @param {InteractionHandler.Context} context
*/
constructor(ctx, options) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.SelectMenu
});
}

parse(interaction) {
if (interaction.customId !== 'my-echo-select') return this.none();
return this.some();
}

async run(interaction) {
await interaction.reply({
// Remember how we can have multiple values? Let's get the first one!
content: `You selected: ${interaction.values[0]}`
});
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@swiizyy
Copy link
Contributor

swiizyy commented Apr 10, 2023

To be closed has been moved to #216

@favna favna closed this in #216 Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants