slash improvements

master
Kit Kasune 3 years ago
parent 4e35a7fdb6
commit b4b06961fe
  1. 16
      .idea/workspace.xml
  2. 21
      bot.js
  3. 3
      events/ready.js
  4. 68
      slash/fun/8ball.js
  5. 2
      util/slashmanager.d.ts
  6. 19
      util/slashmanager.js
  7. 19
      util/ts/slashmanager.ts

@ -5,7 +5,13 @@
</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="more generous daily windows">
<change beforePath="$PROJECT_DIR$/commands/anime/haswatched.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/haswatched.js" 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$/events/ready.js" beforeDir="false" afterPath="$PROJECT_DIR$/events/ready.js" 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/slashmanager.d.ts" beforeDir="false" afterPath="$PROJECT_DIR$/util/slashmanager.d.ts" 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/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" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -43,14 +49,14 @@
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" /> <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/util/ts" /> <property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="node.js.detected.package.eslint" value="true" /> <property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.tslint" value="true" /> <property name="node.js.detected.package.tslint" value="true" />
<property name="node.js.selected.package.eslint" value="(autodetect)" /> <property name="node.js.selected.package.eslint" value="(autodetect)" />
<property name="node.js.selected.package.tslint" value="(autodetect)" /> <property name="node.js.selected.package.tslint" value="(autodetect)" />
<property name="nodejs_package_manager_path" value="npm" /> <property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="MTConfigurable" /> <property name="settings.editor.selected.configurable" value="MTConfigurable" />
<property name="ts.external.directory.path" value="C:\Users\clarkjr1836\Downloads\WebStorm-2021.2.2.win\plugins\JavaScriptLanguage\jsLanguageServicesImpl\external" /> <property name="ts.external.directory.path" value="C:\Program Files\JetBrains\WebStorm 2021.2\plugins\JavaScriptLanguage\jsLanguageServicesImpl\external" />
<property name="ts.rename.search.for.dynamic.occurrences" value="true" /> <property name="ts.rename.search.for.dynamic.occurrences" value="true" />
<property name="vue.rearranger.settings.migration" value="true" /> <property name="vue.rearranger.settings.migration" value="true" />
</component> </component>
@ -58,6 +64,9 @@
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\clarkjr1836\Desktop\bot\Natsuki\util\ts" /> <recent name="C:\Users\clarkjr1836\Desktop\bot\Natsuki\util\ts" />
</key> </key>
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\wubzy\Desktop\bot\Natsuki\slash\fun" />
</key>
</component> </component>
<component name="RunAnythingCache"> <component name="RunAnythingCache">
<option name="myCommands"> <option name="myCommands">
@ -90,6 +99,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" />
</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>

@ -74,11 +74,8 @@ client.misc = {
fullyReady: false fullyReady: false
}; };
//const config = require('./config.js');
const auth = require('./auth.json'); const auth = require('./auth.json');
//client.config = config;
async function init() { async function init() {
const cliargs = new TagFilter([ const cliargs = new TagFilter([
new Tag(['cli', 'c', 'nc', 'nocli'], 'nocli', 'toggle'), new Tag(['cli', 'c', 'nc', 'nocli'], 'nocli', 'toggle'),
@ -108,10 +105,6 @@ async function init() {
client.misc.startupNoConnect = new Date(); client.misc.startupNoConnect = new Date();
client.config = auth; client.config = auth;
client.slash = new SlashManager(client).setTestServer('691122844339404800').importCommands().init();
client.slash.register();
client = client.slash.client;
let mloginsp = ora(chalk.magentaBright('Connecting to Mongo client...')).start(); let mloginsp = ora(chalk.magentaBright('Connecting to Mongo client...')).start();
let pmcc = new Date().getTime(); let pmcc = new Date().getTime();
const config = client.config; const config = client.config;
@ -140,6 +133,8 @@ async function init() {
client.utils.c = (text, a=true) => `${text.slice(0, 1).toUpperCase()}${a ? text.slice(1).toLowerCase() : text.slice(1)}`; client.utils.c = (text, a=true) => `${text.slice(0, 1).toUpperCase()}${a ? text.slice(1).toLowerCase() : text.slice(1)}`;
client.utils.ca = (text, a=true) => text.split(/\s+/gm).map(t => client.utils.c(t, a)).join(" "); client.utils.ca = (text, a=true) => text.split(/\s+/gm).map(t => client.utils.c(t, a)).join(" ");
client.utils.sm = (mpr, ago=true) => `${mpr.years ? `${mpr.years} year${client.utils.s(mpr.years)} ` : ''}${mpr.months ? `${mpr.months} month${client.utils.s(mpr.months)} ` : ''}${mpr.days} day${client.utils.s(mpr.days)}${ago ? ' ago' : ''}`; client.utils.sm = (mpr, ago=true) => `${mpr.years ? `${mpr.years} year${client.utils.s(mpr.years)} ` : ''}${mpr.months ? `${mpr.months} month${client.utils.s(mpr.months)} ` : ''}${mpr.days} day${client.utils.s(mpr.days)}${ago ? ' ago' : ''}`;
client.utils.p = (text) => text.endsWith('s') ? "'" : "'s";
client.utils.ps = (text) => `${text}${client.utils.p(text)}`;
['commands', 'aliases', 'executables'].forEach(x => client[x] = new Discord.Collection()); ['commands', 'aliases', 'executables'].forEach(x => client[x] = new Discord.Collection());
client.responses = {triggers: [], commands: new Discord.Collection()}; client.responses = {triggers: [], commands: new Discord.Collection()};
@ -151,7 +146,19 @@ async function init() {
.map(i => client.misc.config.gradients ? gs.instagram(i) : chalk.blue(i)) .map(i => client.misc.config.gradients ? gs.instagram(i) : chalk.blue(i))
.forEach((i, ind) => client.misc.cache.spin.add(iters[ind], {text: i})); .forEach((i, ind) => client.misc.cache.spin.add(iters[ind], {text: i}));
} }
for (let i = 0; i < iters.length; i++) {let x = iters[i]; await require(`./handle/${x}`)(client);} for (let i = 0; i < iters.length; i++) {let x = iters[i]; await require(`./handle/${x}`)(client);}
const spl = client.misc.config.spinners ? (i) => client.misc.cache.spinLog.push(i) : (i) => console.log(i);
spl(`\n${chalk.gray('[BOOT]')} >> ${chalk.blue('Getting Slash Commands...')}\n`);
client.slash = new SlashManager(client)
.setTestServer('691122844339404800')
.importCommands(false, undefined, (cmd) => spl(`${chalk.gray('[LOAD]')} >> ${chalk.blueBright('Loaded Slash Command')} ${chalk.white(cmd.name)}`))
.init();
if (client.misc.config.dev) {await client.slash.devRegister();}
else {await client.slash.register();}
client = client.slash.client;
spl(`\n${chalk.gray('[BOOT]')} >> ${chalk.blue('Loaded all Slash Commands')}`);
if (client.misc.config.spinners) { if (client.misc.config.spinners) {
client.misc.cache.spinLog.forEach(log => console.log(log)); client.misc.cache.spinLog.forEach(log => console.log(log));
} }

@ -21,9 +21,6 @@ module.exports = async client => {
const config = client.config; const config = client.config;
/*let db = mongoose.connection;
await db.guild.update({}, {"$set": {'prefix': ''}}, false, true);*/
console.log(`\n${chalk.green('[BOOT]')} >> [${moment().format('L LTS')}] -> ${chalk.greenBright("Connected to Discord")}.`); console.log(`\n${chalk.green('[BOOT]')} >> [${moment().format('L LTS')}] -> ${chalk.greenBright("Connected to Discord")}.`);
let date = new Date; date = date.toString().slice(date.toString().search(":") - 2, date.toString().search(":") + 6); let date = new Date; date = date.toString().slice(date.toString().search(":") - 2, date.toString().search(":") + 6);
console.log(`\n${chalk.gray('[INFO]')} >> ${chalk.white(`Logged in at ${date}.`)}`); console.log(`\n${chalk.gray('[INFO]')} >> ${chalk.white(`Logged in at ${date}.`)}`);

@ -1,35 +1,35 @@
const {SlashCommand} = require('../util/slash'); const {SlashCommand} = require('../../util/slash');
const {SlashCommandBuilder} = require('@discordjs/builders'); const {SlashCommandBuilder} = require('@discordjs/builders');
const Discord = require('discord.js'); const Discord = require('discord.js');
module.exports = (client) => { module.exports = (client) => {
return new SlashCommand('8ball', client, return new SlashCommand('8ball', client,
new SlashCommandBuilder() new SlashCommandBuilder()
.setName('8ball') .setName('8ball')
.setDescription("Get a totally accurate and well-thought-out answer to your life's troubles.") .setDescription("Get a totally accurate and well-thought-out answer to your life's troubles.")
.addStringOption(option => { .addStringOption(option => {
return option.setName("question") return option.setName("question")
.setDescription("Your existential crisis.") .setDescription("Your existential crisis.")
.setRequired(true); .setRequired(true);
}) })
.addBooleanOption(option => { .addBooleanOption(option => {
return option.setName("send") return option.setName("send")
.setDescription("Should I send the answer to the channel?"); .setDescription("Should I send the answer to the channel?");
}), }),
async (client, interaction) => { async (client, interaction) => {
const responses = [ const responses = [
/*Positive Responses*/ "Yes!", "I think so", "Possibly", "Certainly", "Definitely", "Absolutely", "Sure!", "Most Likely", "I believe so", "If you're asking for my honest opinion... yes" /*Positive Responses*/ "Yes!", "I think so", "Possibly", "Certainly", "Definitely", "Absolutely", "Sure!", "Most Likely", "I believe so", "If you're asking for my honest opinion... yes"
/*Negative Responses*/ ,"No!", "I don't think so", "Probably not", "Impossible", "Nope", "Absolutely *not*", "Nah", "Doubt it", "I don't believe so", "If you're asking for my honest opinion... no" /*Negative Responses*/ ,"No!", "I don't think so", "Probably not", "Impossible", "Nope", "Absolutely *not*", "Nah", "Doubt it", "I don't believe so", "If you're asking for my honest opinion... no"
/*Neutral Responses */ ,"Maybe", "I'm not sure", "I'll think about it", "Uhh Natsuki isn't here right now. I can take a message?", "I'm sure if you look deep within your heart, which is currently all over that tree, you'll find the answer", "I mean, if you think so...", "I don't have an opinion on that.", "I'll choose to remain silent." /*Neutral Responses */ ,"Maybe", "I'm not sure", "I'll think about it", "Uhh Natsuki isn't here right now. I can take a message?", "I'm sure if you look deep within your heart, which is currently all over that tree, you'll find the answer", "I mean, if you think so...", "I don't have an opinion on that.", "I'll choose to remain silent."
]; ];
return await interaction.reply({embeds: [new Discord.MessageEmbed() return await interaction.reply({embeds: [new Discord.MessageEmbed()
.setAuthor({name: "8ball Question", iconURL: interaction.user.displayAvatarURL()}) .setAuthor({name: "8ball Question", iconURL: interaction.user.displayAvatarURL()})
.setDescription("**Question:** " + interaction.options.getString('question') + "\n**Answer:** " + responses[Math.floor(Math.random() * responses.length)]) .setDescription("**Question:** " + interaction.options.getString('question') + "\n**Answer:** " + responses[Math.floor(Math.random() * responses.length)])
.setColor("c375f0") .setColor("c375f0")
.setFooter({text: `Asked by ${interaction.guild ? interaction.member.displayName : interaction.user.username} | Natsuki`}) .setFooter({text: `Asked by ${interaction.guild ? interaction.member.displayName : interaction.user.username} | Natsuki`})
.setTimestamp() .setTimestamp()
], ephemeral: !interaction.options.getBoolean("send")}); ], ephemeral: !interaction.options.getBoolean("send")});
} }
); );
}; };

@ -21,7 +21,7 @@ export declare class SlashManager {
setAfterHandle(execute: (client: Discord.Client, interaction: Discord.CommandInteraction, success: Boolean) => any): SlashManager; setAfterHandle(execute: (client: Discord.Client, interaction: Discord.CommandInteraction, success: Boolean) => any): SlashManager;
setTestServer(id: string): SlashManager; setTestServer(id: string): SlashManager;
private handle; private handle;
importCommands(dir?: string): SlashManager; importCommands(register?: boolean | RegisterMode, dir?: string, log?: (command: SlashCommand, manager: SlashManager) => void): SlashManager;
} }
declare type CommandLookup = SlashCommand[] | SlashCommand | string | string[]; declare type CommandLookup = SlashCommand[] | SlashCommand | string | string[];
export {}; export {};

@ -123,12 +123,19 @@ class SlashManager {
this.afterHandle(this.client, interaction, success); this.afterHandle(this.client, interaction, success);
} }
; ;
importCommands(dir) { importCommands(register = false, dir = './slash', log = () => { }) {
dir = dir || './slash'; const search = (toSearch) => {
const commands = fs.readdirSync(dir).filter(file => file.endsWith('.js')); let cdir = fs.readdirSync(toSearch);
for (const command of commands) { const commands = cdir.filter(file => file.endsWith('.js'));
this.add(require(`../${dir}/${command}`)(this.client)); for (const command of commands) {
} const slashCommand = require(`../${toSearch}/${command}`)(this.client);
this.add(slashCommand, register);
log(slashCommand, this);
}
const subdirs = cdir.filter(file => fs.lstatSync(`${toSearch}/${file}`).isDirectory());
subdirs.forEach(subdir => search(`${toSearch}/${subdir}`));
};
search(dir);
return this; return this;
} }
; ;

@ -115,12 +115,19 @@ export class SlashManager {
public importCommands(dir?: string): SlashManager { public importCommands(register: boolean | RegisterMode = false, dir: string = './slash', log: (command: SlashCommand, manager: SlashManager) => void = () => {}): SlashManager {
dir = dir || './slash'; const search = (toSearch: string): void => {
const commands = fs.readdirSync(dir).filter(file => file.endsWith('.js')); let cdir = fs.readdirSync(toSearch);
for (const command of commands) { const commands = cdir.filter(file => file.endsWith('.js'));
this.add(require(`../${dir}/${command}`)(this.client)); for (const command of commands) {
} const slashCommand = require(`../${toSearch}/${command}`)(this.client);
this.add(slashCommand, register);
log(slashCommand, this);
}
const subdirs = cdir.filter(file => fs.lstatSync(`${toSearch}/${file}`).isDirectory());
subdirs.forEach(subdir => search(`${toSearch}/${subdir}`));
};
search(dir);
return this; return this;
}; };

Loading…
Cancel
Save