From 399884e3f1d0c19a6ffab433456d2070614d2154 Mon Sep 17 00:00:00 2001 From: Jeroen Claassens Date: Mon, 5 Sep 2022 00:14:58 +0200 Subject: [PATCH 1/6] fix: fixed core templates --- templates/components/argument.js.sapphire | 28 ++++++++----- .../components/contextmenucommand.js.sapphire | 40 ++++++++++++------ .../components/contextmenucommand.ts.sapphire | 12 +++--- templates/components/listener.js.sapphire | 20 +++++---- .../components/messagecommand.js.sapphire | 27 ++++++++---- templates/components/precondition.js.sapphire | 23 ++++++++++- templates/components/precondition.ts.sapphire | 12 +++++- templates/components/slashcommand.js.sapphire | 41 +++++++++++++------ templates/components/slashcommand.ts.sapphire | 13 +++--- 9 files changed, 150 insertions(+), 66 deletions(-) diff --git a/templates/components/argument.js.sapphire b/templates/components/argument.js.sapphire index b361c6b..402aa2f 100644 --- a/templates/components/argument.js.sapphire +++ b/templates/components/argument.js.sapphire @@ -1,15 +1,23 @@ { "category": "arguments" } --- -import { Argument } from "@sapphire/framework"; +const { Argument } = require('@sapphire/framework'); -export class UserArgument extends Argument { - constructor(context, options) { - super(context, { - ...options - }); - } +class UserArgument extends Argument { + /** + * @param {Argument.Context} context + * @param {Argument.Options} options + */ + constructor(context, options) { + super(context, { + ...options + }); + } - async run(parameter) { - return this.ok(parameter); - } + async run(parameter) { + return this.ok(parameter); + } } + +module.exports = { + UserArgument +}; diff --git a/templates/components/contextmenucommand.js.sapphire b/templates/components/contextmenucommand.js.sapphire index 20390a4..20fa7f2 100644 --- a/templates/components/contextmenucommand.js.sapphire +++ b/templates/components/contextmenucommand.js.sapphire @@ -1,25 +1,39 @@ { "category": "commands" } --- -const { Command } = require('@sapphire/framework') +const { Command } = require('@sapphire/framework'); +const { ApplicationCommandType } = require('discord-api-types/v9'); class UserCommand extends Command { - constructor(context, options) { - super(context, { - ...options, + /** + * @param {Command.Context} context + * @param {Command.Options} options + */ + constructor(context, options) { + super(context, { + ...options, name: 'command' - }); - } + }); + } - registerApplicationCommands(registry) { - registry.registerContextMenuCommand({ - name: this.name, - type: 'MESSAGE' - }) + /** + * @param {Command.Registry} registry + */ + registerApplicationCommands(registry) { + registry.registerContextMenuCommand((builder) => + builder // + .setName(this.name) + .setType(ApplicationCommandType.Message) + ); } + /** + * @param {Command.ContextMenuInteraction} interaction + */ async contextMenuRun(interaction) { - return await interaction.reply({content: "Hello world!"}) + return await interaction.reply({ content: 'Hello world!' }); } } -exports.UserCommand = UserCommand; +module.exports = { + UserCommand +}; diff --git a/templates/components/contextmenucommand.ts.sapphire b/templates/components/contextmenucommand.ts.sapphire index e055fe6..18a25be 100644 --- a/templates/components/contextmenucommand.ts.sapphire +++ b/templates/components/contextmenucommand.ts.sapphire @@ -2,19 +2,21 @@ --- import { ApplyOptions } from '@sapphire/decorators'; import { Command } from '@sapphire/framework'; +import { ApplicationCommandType } from 'discord-api-types/v9'; @ApplyOptions({ description: 'A basic contextMenu command' }) export class UserCommand extends Command { public override registerApplicationCommands(registry: Command.Registry) { - registry.registerContextMenuCommand({ - name: this.name, - type: 'MESSAGE' - }) + registry.registerContextMenuCommand((builder) => + builder // + .setName(this.name) + .setType(ApplicationCommandType.Message) + ); } public async contextMenuRun(interaction: Command.ContextMenuInteraction) { - return await interaction.reply({content: "Hello world!"}); + return await interaction.reply({ content: 'Hello world!' }); } } diff --git a/templates/components/listener.js.sapphire b/templates/components/listener.js.sapphire index 891998c..bf61505 100644 --- a/templates/components/listener.js.sapphire +++ b/templates/components/listener.js.sapphire @@ -3,13 +3,19 @@ const { Listener } = require('@sapphire/framework'); class UserEvent extends Listener { - constructor(context, options = {}) { - super(context, { - ...options - }); - } + /** + * @param {Listener.Context} context + * @param {Listener.Options} options + */ + constructor(context, options = {}) { + super(context, { + ...options + }); + } - run() {} + run() {} } -exports.UserEvent = UserEvent; +module.exports = { + UserEvent +} diff --git a/templates/components/messagecommand.js.sapphire b/templates/components/messagecommand.js.sapphire index d798227..fd8915e 100644 --- a/templates/components/messagecommand.js.sapphire +++ b/templates/components/messagecommand.js.sapphire @@ -3,15 +3,24 @@ const { Command } = require('@sapphire/framework'); class UserCommand extends Command { - constructor(context, options) { - super(context, { - ...options - }); - } + /** + * @param {Command.Context} context + * @param {Command.Options} options + */ + constructor(context, options) { + super(context, { + ...options + }); + } - async messageRun(message) { - return message.channel.send('Hello world!'); - } + /** + * @param {import('discord.js').Message} message + */ + async messageRun(message) { + return message.channel.send('Hello world!'); + } } -exports.UserCommand = UserCommand; +module.exports = { + UserCommand +}; diff --git a/templates/components/precondition.js.sapphire b/templates/components/precondition.js.sapphire index 250068b..6735a92 100644 --- a/templates/components/precondition.js.sapphire +++ b/templates/components/precondition.js.sapphire @@ -3,9 +3,28 @@ const { Precondition } = require('@sapphire/framework'); class UserPrecondition extends Precondition { - run(message) { + /** + * @param {import('discord.js').Message} message + */ + messageRun(message) { + return this.ok(); + } + + /** + * @param {import('discord.js').CommandInteraction} interaction + */ + chatInputRun(interaction) { + return this.ok(); + } + + /** + * @param {import('discord.js').ContextMenuInteraction} interaction + */ + contextMenuRun(interaction) { return this.ok(); } } -module.exports.UserPrecondition = UserPrecondition; +module.exports = { + UserPrecondition +}; diff --git a/templates/components/precondition.ts.sapphire b/templates/components/precondition.ts.sapphire index f8f034c..209f3fe 100644 --- a/templates/components/precondition.ts.sapphire +++ b/templates/components/precondition.ts.sapphire @@ -1,10 +1,18 @@ { "category": "preconditions" } --- import { Precondition } from '@sapphire/framework'; -import type { Message } from 'discord.js'; +import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; export class UserPrecondition extends Precondition { - public run(message: Message) { + public override messageRun(message: Message) { + return this.ok(); + } + + public override chatInputRun(interaction: CommandInteraction) { + return this.ok(); + } + + public override contextMenuRun(interaction: ContextMenuInteraction) { return this.ok(); } } diff --git a/templates/components/slashcommand.js.sapphire b/templates/components/slashcommand.js.sapphire index c12b2f2..8cf30e7 100644 --- a/templates/components/slashcommand.js.sapphire +++ b/templates/components/slashcommand.js.sapphire @@ -3,24 +3,41 @@ const { Command } = require('@sapphire/framework') class UserCommand extends Command { - constructor(context, options) { - super(context, { - ...options, + /** + * @param {Command.Context} context + * @param {Command.Options} options + */ + constructor(context, options) { + super(context, { + ...options, name: 'command', description: 'A basic slash command' - }); - } + }); + } - registerApplicationCommands(registry) { - registry.registerChatInputCommand({ - name: this.name, - description: this.description - }) + /** + * @param {Command.Registry} registry + */ + registerApplicationCommands(registry) { + registry.registerChatInputCommand( + /** + * @param {import('@discordjs/builders').SlashCommandBuilder} builder + */ + (builder) => + builder // + .setName(this.name) + .setDescription(this.description) + ); } + /** + * @param {Command.ChatInputInteraction} interaction + */ async chatInputRun(interaction) { - return await interaction.reply({content: "Hello world!"}) + return await interaction.reply({ content: 'Hello world!' }); } } -exports.UserCommand = UserCommand; +module.exports = { + UserCommand +} diff --git a/templates/components/slashcommand.ts.sapphire b/templates/components/slashcommand.ts.sapphire index 5465cd6..98d02ee 100644 --- a/templates/components/slashcommand.ts.sapphire +++ b/templates/components/slashcommand.ts.sapphire @@ -8,13 +8,14 @@ import { Command } from '@sapphire/framework'; }) export class UserCommand extends Command { public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand({ - name: this.name, - description: this.description - }) + registry.registerChatInputCommand((builder) => + builder // + .setName(this.name) + .setDescription(this.description) + ); } - public async chatInputRun(interaction: Command.ChatInputInteraction) { - return await interaction.reply({content: "Hello world!"}); + public override async chatInputRun(interaction: Command.ChatInputInteraction) { + return await interaction.reply({ content: 'Hello world!' }); } } From ee2fb72d6170ab6d10fb3db19992f5802f4febb7 Mon Sep 17 00:00:00 2001 From: Jeroen Claassens Date: Mon, 5 Sep 2022 00:18:34 +0200 Subject: [PATCH 2/6] chore: this will definitely break in 2036 (todo) permalink: http://whatthecommit.com/584f576d96de8ec4c178fb00d5e45061 --- templates/.sapphirerc.json.sapphire | 24 ++-- templates/components/argument.ts.sapphire | 14 +-- templates/components/listener.ts.sapphire | 2 +- templates/components/precondition.ts.sapphire | 24 ++-- templates/schemas/.sapphirerc.scheme.json | 109 ++++++++---------- 5 files changed, 80 insertions(+), 93 deletions(-) diff --git a/templates/.sapphirerc.json.sapphire b/templates/.sapphirerc.json.sapphire index d918411..a7003e5 100644 --- a/templates/.sapphirerc.json.sapphire +++ b/templates/.sapphirerc.json.sapphire @@ -1,14 +1,14 @@ { - "projectLanguage": "{{language}}", - "locations": { - "base": "src", - "arguments": "arguments", - "commands": "commands", - "listeners": "listeners", - "preconditions": "preconditions" - }, - "customFileTemplates": { - "enabled": false, - "location": "" - } + "projectLanguage": "{{language}}", + "locations": { + "base": "src", + "arguments": "arguments", + "commands": "commands", + "listeners": "listeners", + "preconditions": "preconditions" + }, + "customFileTemplates": { + "enabled": false, + "location": "" + } } diff --git a/templates/components/argument.ts.sapphire b/templates/components/argument.ts.sapphire index 4ff5a9d..3b374f8 100644 --- a/templates/components/argument.ts.sapphire +++ b/templates/components/argument.ts.sapphire @@ -1,17 +1,17 @@ { "category": "arguments" } --- import { ApplyOptions } from '@sapphire/decorators'; -import { Argument, ArgumentOptions } from "@sapphire/framework"; +import { Argument, ArgumentOptions } from '@sapphire/framework'; @ApplyOptions({}) export class UserArgument extends Argument { - async run(parameter: string) { - return this.ok(parameter); - } + async run(parameter: string) { + return this.ok(parameter); + } } declare module '@sapphire/framework' { - interface ArgType { - {{name}}: string; - } + interface ArgType { + {{name}}: string; + } } diff --git a/templates/components/listener.ts.sapphire b/templates/components/listener.ts.sapphire index 287b1db..b04d46b 100644 --- a/templates/components/listener.ts.sapphire +++ b/templates/components/listener.ts.sapphire @@ -5,5 +5,5 @@ import { Listener, ListenerOptions } from '@sapphire/framework'; @ApplyOptions({}) export class UserEvent extends Listener { - public run() {} + public run() {} } diff --git a/templates/components/precondition.ts.sapphire b/templates/components/precondition.ts.sapphire index 209f3fe..a94a86e 100644 --- a/templates/components/precondition.ts.sapphire +++ b/templates/components/precondition.ts.sapphire @@ -4,21 +4,21 @@ import { Precondition } from '@sapphire/framework'; import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; export class UserPrecondition extends Precondition { - public override messageRun(message: Message) { - return this.ok(); - } + public override messageRun(message: Message) { + return this.ok(); + } - public override chatInputRun(interaction: CommandInteraction) { - return this.ok(); - } + public override chatInputRun(interaction: CommandInteraction) { + return this.ok(); + } - public override contextMenuRun(interaction: ContextMenuInteraction) { - return this.ok(); - } + public override contextMenuRun(interaction: ContextMenuInteraction) { + return this.ok(); + } } declare module '@sapphire/framework' { - interface Preconditions { - {{name}}: never; - } + interface Preconditions { + {{name}}: never; + } } diff --git a/templates/schemas/.sapphirerc.scheme.json b/templates/schemas/.sapphirerc.scheme.json index 9df3233..0093bfe 100644 --- a/templates/schemas/.sapphirerc.scheme.json +++ b/templates/schemas/.sapphirerc.scheme.json @@ -1,63 +1,50 @@ { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Sapphire CLI Config", - "description": "Scheme for Sapphire CLI Config (@sapphire/cli)", - "type": "object", - "properties": { - "projectLanguage": { - "description": "Project language (ts | js)", - "type": "string" - }, - "locations": { - "description": "Categories and their locations", - "type": "object", - "properties": { - "base": { - "type": "string" - }, - "arguments": { - "type": "string" - }, - "commands": { - "type": "string" - }, - "listeners": { - "type": "string" - }, - "preconditions": { - "type": "string" - } - }, - "required": [ - "base", - "arguments", - "commands", - "listeners", - "preconditions" - ] - }, - "customFileTemplates": { - "description": "Settings about custom component (piece) templates", - "type": "object", - "properties": { - "enabled": { - "description": "Enable custom file templates", - "type": "boolean" - }, - "location": { - "description": "Location of your custom file templates", - "type": "string" - } - }, - "required": [ - "enabled", - "location" - ] - } - }, - "required": [ - "projectLanguage", - "locations", - "customFileTemplates" - ] + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "Sapphire CLI Config", + "description": "Scheme for Sapphire CLI Config (@sapphire/cli)", + "type": "object", + "properties": { + "projectLanguage": { + "description": "Project language (ts | js)", + "type": "string" + }, + "locations": { + "description": "Categories and their locations", + "type": "object", + "properties": { + "base": { + "type": "string" + }, + "arguments": { + "type": "string" + }, + "commands": { + "type": "string" + }, + "listeners": { + "type": "string" + }, + "preconditions": { + "type": "string" + } + }, + "required": ["base", "arguments", "commands", "listeners", "preconditions"] + }, + "customFileTemplates": { + "description": "Settings about custom component (piece) templates", + "type": "object", + "properties": { + "enabled": { + "description": "Enable custom file templates", + "type": "boolean" + }, + "location": { + "description": "Location of your custom file templates", + "type": "string" + } + }, + "required": ["enabled", "location"] + } + }, + "required": ["projectLanguage", "locations", "customFileTemplates"] } From fcd872c9e1270216aba233dc0d692acf38bc6ae9 Mon Sep 17 00:00:00 2001 From: Jeroen Claassens Date: Mon, 5 Sep 2022 00:28:08 +0200 Subject: [PATCH 3/6] chore: fix --- templates/components/slashcommand.js.sapphire | 3 --- 1 file changed, 3 deletions(-) diff --git a/templates/components/slashcommand.js.sapphire b/templates/components/slashcommand.js.sapphire index 8cf30e7..45a00a6 100644 --- a/templates/components/slashcommand.js.sapphire +++ b/templates/components/slashcommand.js.sapphire @@ -20,9 +20,6 @@ class UserCommand extends Command { */ registerApplicationCommands(registry) { registry.registerChatInputCommand( - /** - * @param {import('@discordjs/builders').SlashCommandBuilder} builder - */ (builder) => builder // .setName(this.name) From 05c5a5f3b03b6519c6e147b4cf6d124a69124a9f Mon Sep 17 00:00:00 2001 From: Jeroen Claassens Date: Mon, 5 Sep 2022 00:35:54 +0200 Subject: [PATCH 4/6] chore: use v10 --- templates/components/contextmenucommand.js.sapphire | 2 +- templates/components/contextmenucommand.ts.sapphire | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/components/contextmenucommand.js.sapphire b/templates/components/contextmenucommand.js.sapphire index 20fa7f2..dce4a4c 100644 --- a/templates/components/contextmenucommand.js.sapphire +++ b/templates/components/contextmenucommand.js.sapphire @@ -1,7 +1,7 @@ { "category": "commands" } --- const { Command } = require('@sapphire/framework'); -const { ApplicationCommandType } = require('discord-api-types/v9'); +const { ApplicationCommandType } = require('discord-api-types/v10'); class UserCommand extends Command { /** diff --git a/templates/components/contextmenucommand.ts.sapphire b/templates/components/contextmenucommand.ts.sapphire index 18a25be..d022d7a 100644 --- a/templates/components/contextmenucommand.ts.sapphire +++ b/templates/components/contextmenucommand.ts.sapphire @@ -2,7 +2,7 @@ --- import { ApplyOptions } from '@sapphire/decorators'; import { Command } from '@sapphire/framework'; -import { ApplicationCommandType } from 'discord-api-types/v9'; +import { ApplicationCommandType } from 'discord-api-types/v10'; @ApplyOptions({ description: 'A basic contextMenu command' From e831d96cad1edaf2b7b119eab25da354b289a165 Mon Sep 17 00:00:00 2001 From: Jeroen Claassens Date: Mon, 5 Sep 2022 00:41:09 +0200 Subject: [PATCH 5/6] chore: no spread --- templates/components/argument.js.sapphire | 7 ++----- templates/components/contextmenucommand.js.sapphire | 4 +--- templates/components/listener.js.sapphire | 7 ++----- templates/components/messagecommand.js.sapphire | 7 ++----- templates/components/slashcommand.js.sapphire | 4 +--- 5 files changed, 8 insertions(+), 21 deletions(-) diff --git a/templates/components/argument.js.sapphire b/templates/components/argument.js.sapphire index 402aa2f..d0e2944 100644 --- a/templates/components/argument.js.sapphire +++ b/templates/components/argument.js.sapphire @@ -5,12 +5,9 @@ const { Argument } = require('@sapphire/framework'); class UserArgument extends Argument { /** * @param {Argument.Context} context - * @param {Argument.Options} options */ - constructor(context, options) { - super(context, { - ...options - }); + constructor(context) { + super(context); } async run(parameter) { diff --git a/templates/components/contextmenucommand.js.sapphire b/templates/components/contextmenucommand.js.sapphire index dce4a4c..37ad430 100644 --- a/templates/components/contextmenucommand.js.sapphire +++ b/templates/components/contextmenucommand.js.sapphire @@ -6,11 +6,9 @@ const { ApplicationCommandType } = require('discord-api-types/v10'); class UserCommand extends Command { /** * @param {Command.Context} context - * @param {Command.Options} options */ - constructor(context, options) { + constructor(context) { super(context, { - ...options, name: 'command' }); } diff --git a/templates/components/listener.js.sapphire b/templates/components/listener.js.sapphire index bf61505..3a90141 100644 --- a/templates/components/listener.js.sapphire +++ b/templates/components/listener.js.sapphire @@ -5,12 +5,9 @@ const { Listener } = require('@sapphire/framework'); class UserEvent extends Listener { /** * @param {Listener.Context} context - * @param {Listener.Options} options */ - constructor(context, options = {}) { - super(context, { - ...options - }); + constructor(context) { + super(context); } run() {} diff --git a/templates/components/messagecommand.js.sapphire b/templates/components/messagecommand.js.sapphire index fd8915e..f8d0c83 100644 --- a/templates/components/messagecommand.js.sapphire +++ b/templates/components/messagecommand.js.sapphire @@ -5,12 +5,9 @@ const { Command } = require('@sapphire/framework'); class UserCommand extends Command { /** * @param {Command.Context} context - * @param {Command.Options} options */ - constructor(context, options) { - super(context, { - ...options - }); + constructor(context) { + super(context); } /** diff --git a/templates/components/slashcommand.js.sapphire b/templates/components/slashcommand.js.sapphire index 45a00a6..ce7a82b 100644 --- a/templates/components/slashcommand.js.sapphire +++ b/templates/components/slashcommand.js.sapphire @@ -5,11 +5,9 @@ const { Command } = require('@sapphire/framework') class UserCommand extends Command { /** * @param {Command.Context} context - * @param {Command.Options} options */ - constructor(context, options) { + constructor(context) { super(context, { - ...options, name: 'command', description: 'A basic slash command' }); From 26ccb69f593a78bdfa94bd0fedd22fa19bd79b1b Mon Sep 17 00:00:00 2001 From: Jeroen Claassens Date: Mon, 5 Sep 2022 00:43:40 +0200 Subject: [PATCH 6/6] chore: add names --- templates/components/argument.js.sapphire | 4 +++- templates/components/contextmenucommand.js.sapphire | 1 + templates/components/listener.js.sapphire | 4 +++- templates/components/messagecommand.js.sapphire | 4 +++- templates/components/slashcommand.js.sapphire | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/templates/components/argument.js.sapphire b/templates/components/argument.js.sapphire index d0e2944..fd01f8f 100644 --- a/templates/components/argument.js.sapphire +++ b/templates/components/argument.js.sapphire @@ -7,7 +7,9 @@ class UserArgument extends Argument { * @param {Argument.Context} context */ constructor(context) { - super(context); + super(context, { + // Any Argument options you want here + }); } async run(parameter) { diff --git a/templates/components/contextmenucommand.js.sapphire b/templates/components/contextmenucommand.js.sapphire index 37ad430..8001281 100644 --- a/templates/components/contextmenucommand.js.sapphire +++ b/templates/components/contextmenucommand.js.sapphire @@ -9,6 +9,7 @@ class UserCommand extends Command { */ constructor(context) { super(context, { + // Any Command options you want here name: 'command' }); } diff --git a/templates/components/listener.js.sapphire b/templates/components/listener.js.sapphire index 3a90141..2ab4bb2 100644 --- a/templates/components/listener.js.sapphire +++ b/templates/components/listener.js.sapphire @@ -7,7 +7,9 @@ class UserEvent extends Listener { * @param {Listener.Context} context */ constructor(context) { - super(context); + super(context, { + // Any Listener options you want here + }); } run() {} diff --git a/templates/components/messagecommand.js.sapphire b/templates/components/messagecommand.js.sapphire index f8d0c83..33eb7ca 100644 --- a/templates/components/messagecommand.js.sapphire +++ b/templates/components/messagecommand.js.sapphire @@ -7,7 +7,9 @@ class UserCommand extends Command { * @param {Command.Context} context */ constructor(context) { - super(context); + super(context, { + // Any Command options you want here + }); } /** diff --git a/templates/components/slashcommand.js.sapphire b/templates/components/slashcommand.js.sapphire index ce7a82b..0157209 100644 --- a/templates/components/slashcommand.js.sapphire +++ b/templates/components/slashcommand.js.sapphire @@ -8,6 +8,7 @@ class UserCommand extends Command { */ constructor(context) { super(context, { + // Any Command options you want here name: 'command', description: 'A basic slash command' });