more slash improvements

master
Kit Kasune 3 years ago
parent b4b06961fe
commit 084eb2352a
  1. 33
      .idea/workspace.xml
  2. 76
      package-lock.json
  3. 1
      package.json
  4. 6
      util/slash.d.ts
  5. 4
      util/slash.js
  6. 8
      util/slashmanager.js
  7. 8
      util/ts/slash.ts
  8. 11
      util/ts/slashmanager.ts

@ -4,13 +4,15 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="826c705b-a7fa-4ece-b82a-e278fca7d494" name="Changes" comment="more generous daily windows"> <list default="true" id="826c705b-a7fa-4ece-b82a-e278fca7d494" name="Changes" comment="slash improvements">
<change afterPath="$PROJECT_DIR$/slash/fun/deathnote.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bot.js" beforeDir="false" afterPath="$PROJECT_DIR$/bot.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/events/ready.js" beforeDir="false" afterPath="$PROJECT_DIR$/events/ready.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/slash/8ball.js" beforeDir="false" afterPath="$PROJECT_DIR$/slash/fun/8ball.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/util/slash.d.ts" beforeDir="false" afterPath="$PROJECT_DIR$/util/slash.d.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/slashmanager.d.ts" beforeDir="false" afterPath="$PROJECT_DIR$/util/slashmanager.d.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/util/slash.js" beforeDir="false" afterPath="$PROJECT_DIR$/util/slash.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/slashmanager.js" beforeDir="false" afterPath="$PROJECT_DIR$/util/slashmanager.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/util/slashmanager.js" beforeDir="false" afterPath="$PROJECT_DIR$/util/slashmanager.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/ts/slash.ts" beforeDir="false" afterPath="$PROJECT_DIR$/util/ts/slash.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/ts/slashmanager.ts" beforeDir="false" afterPath="$PROJECT_DIR$/util/ts/slashmanager.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/util/ts/slashmanager.ts" beforeDir="false" afterPath="$PROJECT_DIR$/util/ts/slashmanager.ts" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -18,6 +20,13 @@
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="JavaScript File" />
</list>
</option>
</component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
@ -99,7 +108,7 @@
<workItem from="1642537991410" duration="3454000" /> <workItem from="1642537991410" duration="3454000" />
<workItem from="1642638383959" duration="700000" /> <workItem from="1642638383959" duration="700000" />
<workItem from="1642707112676" duration="1337000" /> <workItem from="1642707112676" duration="1337000" />
<workItem from="1644446122031" duration="2837000" /> <workItem from="1644446122031" duration="6700000" />
</task> </task>
<task id="LOCAL-00001" summary="not even gonna explain"> <task id="LOCAL-00001" summary="not even gonna explain">
<created>1640148826800</created> <created>1640148826800</created>
@ -171,7 +180,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1642708137867</updated> <updated>1642708137867</updated>
</task> </task>
<option name="localTasksCounter" value="11" /> <task id="LOCAL-00011" summary="slash improvements">
<created>1644449776897</created>
<option name="number" value="00011" />
<option name="presentableId" value="LOCAL-00011" />
<option name="project" value="LOCAL" />
<updated>1644449776897</updated>
</task>
<option name="localTasksCounter" value="12" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -201,6 +217,7 @@
<MESSAGE value="way more stable char commands" /> <MESSAGE value="way more stable char commands" />
<MESSAGE value="SCM package scripts" /> <MESSAGE value="SCM package scripts" />
<MESSAGE value="more generous daily windows" /> <MESSAGE value="more generous daily windows" />
<option name="LAST_COMMIT_MESSAGE" value="more generous daily windows" /> <MESSAGE value="slash improvements" />
<option name="LAST_COMMIT_MESSAGE" value="slash improvements" />
</component> </component>
</project> </project>

76
package-lock.json generated

@ -8,6 +8,7 @@
"name": "natsuki", "name": "natsuki",
"version": "1.0.0", "version": "1.0.0",
"dependencies": { "dependencies": {
"@discordjs/builders": "^0.12.0",
"@discordjs/rest": "^0.1.0-canary.0", "@discordjs/rest": "^0.1.0-canary.0",
"@discordjs/voice": "^0.6.0", "@discordjs/voice": "^0.6.0",
"canvas": "^2.9.0", "canvas": "^2.9.0",
@ -35,25 +36,24 @@
} }
}, },
"node_modules/@discordjs/builders": { "node_modules/@discordjs/builders": {
"version": "0.11.0", "version": "0.12.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz", "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.12.0.tgz",
"integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==", "integrity": "sha512-Vx2MjUZd6QVo1uS2uWt708Fd6cHWGFblAvbpL5EBO+kLl0BADmPwwvts+YJ/VfSywed6Vsk6K2cEooR/Ytjhjw==",
"dependencies": { "dependencies": {
"@sindresorhus/is": "^4.2.0", "@sindresorhus/is": "^4.3.0",
"discord-api-types": "^0.26.0", "discord-api-types": "^0.26.1",
"ts-mixer": "^6.0.0", "ts-mixer": "^6.0.0",
"tslib": "^2.3.1", "tslib": "^2.3.1",
"zod": "^3.11.6" "zod": "^3.11.6"
}, },
"engines": { "engines": {
"node": ">=16.0.0", "node": ">=16.9.0"
"npm": ">=7.0.0"
} }
}, },
"node_modules/@discordjs/builders/node_modules/discord-api-types": { "node_modules/@discordjs/builders/node_modules/discord-api-types": {
"version": "0.26.0", "version": "0.26.1",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.0.tgz", "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz",
"integrity": "sha512-bnUltSHpQLzTVZTMjm+iNgVhAbtm5oAKHrhtiPaZoxprbm1UtuCZCsG0yXM61NamWfeSz7xnLvgFc50YzVJ5cQ==", "integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==",
"engines": { "engines": {
"node": ">=12" "node": ">=12"
} }
@ -152,9 +152,9 @@
} }
}, },
"node_modules/@sindresorhus/is": { "node_modules/@sindresorhus/is": {
"version": "4.2.0", "version": "4.4.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.2.0.tgz", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.4.0.tgz",
"integrity": "sha512-VkE3KLBmJwcCaVARtQpfuKcKv8gcBmUubrfHGF84dXuuW6jgsRYxPtzcIhPyK9WAPpRt2/xY6zkD9MnRaJzSyw==", "integrity": "sha512-QppPM/8l3Mawvh4rn9CNEYIU9bxpXUCRMaX9yUpvBk1nMKusLKpfXGDEKExKaPhLzcn3lzil7pR6rnJ11HgeRQ==",
"engines": { "engines": {
"node": ">=10" "node": ">=10"
}, },
@ -590,6 +590,22 @@
"npm": ">=7.0.0" "npm": ">=7.0.0"
} }
}, },
"node_modules/discord.js/node_modules/@discordjs/builders": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz",
"integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==",
"dependencies": {
"@sindresorhus/is": "^4.2.0",
"discord-api-types": "^0.26.0",
"ts-mixer": "^6.0.0",
"tslib": "^2.3.1",
"zod": "^3.11.6"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
}
},
"node_modules/discord.js/node_modules/@types/ws": { "node_modules/discord.js/node_modules/@types/ws": {
"version": "8.2.2", "version": "8.2.2",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.2.tgz", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.2.tgz",
@ -1708,21 +1724,21 @@
}, },
"dependencies": { "dependencies": {
"@discordjs/builders": { "@discordjs/builders": {
"version": "0.11.0", "version": "0.12.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz", "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.12.0.tgz",
"integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==", "integrity": "sha512-Vx2MjUZd6QVo1uS2uWt708Fd6cHWGFblAvbpL5EBO+kLl0BADmPwwvts+YJ/VfSywed6Vsk6K2cEooR/Ytjhjw==",
"requires": { "requires": {
"@sindresorhus/is": "^4.2.0", "@sindresorhus/is": "^4.3.0",
"discord-api-types": "^0.26.0", "discord-api-types": "^0.26.1",
"ts-mixer": "^6.0.0", "ts-mixer": "^6.0.0",
"tslib": "^2.3.1", "tslib": "^2.3.1",
"zod": "^3.11.6" "zod": "^3.11.6"
}, },
"dependencies": { "dependencies": {
"discord-api-types": { "discord-api-types": {
"version": "0.26.0", "version": "0.26.1",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.0.tgz", "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz",
"integrity": "sha512-bnUltSHpQLzTVZTMjm+iNgVhAbtm5oAKHrhtiPaZoxprbm1UtuCZCsG0yXM61NamWfeSz7xnLvgFc50YzVJ5cQ==" "integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ=="
} }
} }
}, },
@ -1797,9 +1813,9 @@
"integrity": "sha512-QnzuLp+p9D7agynVub/zqlDVriDza9y3STArBhNiNBUgIX8+GL5FpQxstRfw1jDr5jkZUjcuKYAHxjIuXKdJAg==" "integrity": "sha512-QnzuLp+p9D7agynVub/zqlDVriDza9y3STArBhNiNBUgIX8+GL5FpQxstRfw1jDr5jkZUjcuKYAHxjIuXKdJAg=="
}, },
"@sindresorhus/is": { "@sindresorhus/is": {
"version": "4.2.0", "version": "4.4.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.2.0.tgz", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.4.0.tgz",
"integrity": "sha512-VkE3KLBmJwcCaVARtQpfuKcKv8gcBmUubrfHGF84dXuuW6jgsRYxPtzcIhPyK9WAPpRt2/xY6zkD9MnRaJzSyw==" "integrity": "sha512-QppPM/8l3Mawvh4rn9CNEYIU9bxpXUCRMaX9yUpvBk1nMKusLKpfXGDEKExKaPhLzcn3lzil7pR6rnJ11HgeRQ=="
}, },
"@types/bson": { "@types/bson": {
"version": "4.0.3", "version": "4.0.3",
@ -2152,6 +2168,18 @@
"ws": "^8.4.0" "ws": "^8.4.0"
}, },
"dependencies": { "dependencies": {
"@discordjs/builders": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz",
"integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==",
"requires": {
"@sindresorhus/is": "^4.2.0",
"discord-api-types": "^0.26.0",
"ts-mixer": "^6.0.0",
"tslib": "^2.3.1",
"zod": "^3.11.6"
}
},
"@types/ws": { "@types/ws": {
"version": "8.2.2", "version": "8.2.2",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.2.tgz", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.2.tgz",

@ -5,6 +5,7 @@
"main": "bot.js", "main": "bot.js",
"author": "NatsukiDev", "author": "NatsukiDev",
"dependencies": { "dependencies": {
"@discordjs/builders": "^0.12.0",
"@discordjs/rest": "^0.1.0-canary.0", "@discordjs/rest": "^0.1.0-canary.0",
"@discordjs/voice": "^0.6.0", "@discordjs/voice": "^0.6.0",
"canvas": "^2.9.0", "canvas": "^2.9.0",

6
util/slash.d.ts vendored

@ -1,8 +1,8 @@
import { REST } from '@discordjs/rest'; import { REST } from '@discordjs/rest';
import { SlashCommandBuilder } from '@discordjs/builders'; import { SlashCommandBuilder } from '@discordjs/builders';
import { Client, CommandInteraction } from 'discord.js'; import { Client, CommandInteraction, Guild } from 'discord.js';
export declare class SlashCommand { export declare class SlashCommand {
response: (client: Client, interaction: CommandInteraction) => any; response: (client: Client, interaction: CommandInteraction, guild: false | Guild, prefix: string) => any;
command: SlashCommandBuilder; command: SlashCommandBuilder;
registerMode: RegisterMode; registerMode: RegisterMode;
enabled: boolean; enabled: boolean;
@ -16,7 +16,7 @@ export declare class SlashCommand {
setResponse(newResponse: (client: Client, interaction: CommandInteraction) => any): SlashCommand; setResponse(newResponse: (client: Client, interaction: CommandInteraction) => any): SlashCommand;
disable(): Promise<void>; disable(): Promise<void>;
setDefaultRegisterMode(mode: RegisterMode): SlashCommand; setDefaultRegisterMode(mode: RegisterMode): SlashCommand;
respond(client: Client, interaction: CommandInteraction): Promise<any>; respond(client: Client, interaction: CommandInteraction, guild: false | Guild, prefix: string): Promise<any>;
setCommand(newCommand: SlashCommandBuilder): SlashCommand; setCommand(newCommand: SlashCommandBuilder): SlashCommand;
} }
export declare type RegisterMode = { export declare type RegisterMode = {

@ -53,8 +53,8 @@ class SlashCommand {
return this; return this;
} }
; ;
async respond(client, interaction) { async respond(client, interaction, guild, prefix) {
return this.response(client, interaction); return this.response(client, interaction, guild, prefix);
} }
; ;
setCommand(newCommand) { setCommand(newCommand) {

@ -113,11 +113,15 @@ class SlashManager {
async handle(interaction) { async handle(interaction) {
this.beforeHandle(this.client, interaction); this.beforeHandle(this.client, interaction);
let success = true; let success = true;
// @ts-ignore
let defaultPrefix = this.client.misc.config.dev ? 'n!' : 'n?';
try { try {
await this.commands[this.getCommand(interaction.commandName)].respond(this.client, interaction).catch((e) => { console.log(e); success = false; }); await this.commands[this.getCommand(interaction.commandName)]
.respond(this.client, interaction, interaction.inGuild() ? interaction.guild : false,
// @ts-ignore
interaction.inGuild() ? this.client.guildconfig.prefixes.has(interaction.guild.id) ? this.client.guildconfig.prefixes.get(interaction.guild.id) !== null ? this.client.guildconfig.prefixes.get(interaction.guild.id) : defaultPrefix : defaultPrefix : defaultPrefix).catch((e) => { console.log(e); success = false; });
} }
catch (e) { catch (e) {
console.log(e);
success = false; success = false;
} }
this.afterHandle(this.client, interaction, success); this.afterHandle(this.client, interaction, success);

@ -1,11 +1,11 @@
import {REST} from '@discordjs/rest'; import {REST} from '@discordjs/rest';
import {Routes} from 'discord-api-types/v9'; import {Routes} from 'discord-api-types/v9';
import {SlashCommandBuilder} from '@discordjs/builders'; import {SlashCommandBuilder} from '@discordjs/builders';
import {Client, CommandInteraction} from 'discord.js'; import {Client, CommandInteraction, Guild} from 'discord.js';
export class SlashCommand { export class SlashCommand {
response: (client: Client, interaction: CommandInteraction) => any; response: (client: Client, interaction: CommandInteraction, guild: false | Guild, prefix: string) => any;
command: SlashCommandBuilder; command: SlashCommandBuilder;
registerMode: RegisterMode = 'global'; registerMode: RegisterMode = 'global';
enabled: boolean = false; enabled: boolean = false;
@ -64,8 +64,8 @@ export class SlashCommand {
return this; return this;
}; };
public async respond(client: Client, interaction: CommandInteraction): Promise<any> { public async respond(client: Client, interaction: CommandInteraction, guild: false | Guild, prefix: string): Promise<any> {
return this.response(client, interaction); return this.response(client, interaction, guild, prefix);
}; };
public setCommand(newCommand: SlashCommandBuilder): SlashCommand { public setCommand(newCommand: SlashCommandBuilder): SlashCommand {

@ -106,10 +106,17 @@ export class SlashManager {
private async handle(interaction: Discord.CommandInteraction): Promise<any> { private async handle(interaction: Discord.CommandInteraction): Promise<any> {
this.beforeHandle(this.client, interaction); this.beforeHandle(this.client, interaction);
let success = true; let success = true;
// @ts-ignore
let defaultPrefix = this.client.misc.config.dev ? 'n!' : 'n?';
try { try {
await this.commands[this.getCommand(interaction.commandName)].respond(this.client, interaction).catch((e) => {console.log(e); success = false;}); await this.commands[this.getCommand(interaction.commandName)]
.respond(this.client, interaction,
interaction.inGuild() ? interaction.guild : false,
// @ts-ignore
interaction.inGuild() ? this.client.guildconfig.prefixes.has(interaction.guild.id) ? this.client.guildconfig.prefixes.get(interaction.guild.id) !== null ? this.client.guildconfig.prefixes.get(interaction.guild.id) : defaultPrefix : defaultPrefix : defaultPrefix
).catch((e) => {console.log(e); success = false;});
} }
catch (e) {console.log(e); success = false;} catch (e) {success = false;}
this.afterHandle(this.client, interaction, success); this.afterHandle(this.client, interaction, success);
}; };

Loading…
Cancel
Save