New way to handle args
This commit is contained in:
parent
f82ff3d380
commit
8d59ac37a6
14 changed files with 55 additions and 59 deletions
|
@ -13,11 +13,11 @@ export default {
|
||||||
async execute(interaction, args, client) {
|
async execute(interaction, args, client) {
|
||||||
const leave = await db.leaveChannel.findOne({ where: { guildID: interaction.guild.id } });
|
const leave = await db.leaveChannel.findOne({ where: { guildID: interaction.guild.id } });
|
||||||
|
|
||||||
if (!leave && !args[0]) {
|
if (!leave && !args.message) {
|
||||||
return interaction.reply({ content: 'You need a message for me to say anything!', ephemeral: true });
|
return interaction.reply({ content: 'You need a message for me to say anything!', ephemeral: true });
|
||||||
}
|
}
|
||||||
else if (!leave) {
|
else if (!leave) {
|
||||||
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
|
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message };
|
||||||
await db.leaveChannel.create(body);
|
await db.leaveChannel.create(body);
|
||||||
return interaction.reply({ content: `The leave message have been set with ${args.message}`, ephemeral: true });
|
return interaction.reply({ content: `The leave message have been set with ${args.message}`, ephemeral: true });
|
||||||
}
|
}
|
||||||
|
@ -48,12 +48,12 @@ export default {
|
||||||
if (!interactionMenu.isButton) return;
|
if (!interactionMenu.isButton) return;
|
||||||
interactionMenu.update({ components: [] });
|
interactionMenu.update({ components: [] });
|
||||||
if (interactionMenu.customId === 'edit') {
|
if (interactionMenu.customId === 'edit') {
|
||||||
if (!args[0]) {
|
if (!args.message) {
|
||||||
return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true });
|
return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true });
|
||||||
}
|
}
|
||||||
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
|
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message };
|
||||||
await db.leaveChannel.update(body, { where: { guildID: interaction.guild.id } });
|
await db.leaveChannel.update(body, { where: { guildID: interaction.guild.id } });
|
||||||
return interaction.editReply({ content: `The leave message has been set to ${args[0]}`, ephemeral: true });
|
return interaction.editReply({ content: `The leave message has been set to ${args.message}`, ephemeral: true });
|
||||||
}
|
}
|
||||||
else if (interactionMenu.customId === 'remove') {
|
else if (interactionMenu.customId === 'remove') {
|
||||||
db.leaveChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } });
|
db.leaveChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } });
|
||||||
|
|
|
@ -13,13 +13,13 @@ export default {
|
||||||
async execute(interaction, args, client) {
|
async execute(interaction, args, client) {
|
||||||
const join = await db.joinChannel.findOne({ where: { guildID: interaction.guild.id } });
|
const join = await db.joinChannel.findOne({ where: { guildID: interaction.guild.id } });
|
||||||
|
|
||||||
if (!join && !args[0]) {
|
if (!join && !args.message) {
|
||||||
return interaction.reply({ content: 'You need a message for me to say anything!', ephemeral: true });
|
return interaction.reply({ content: 'You need a message for me to say anything!', ephemeral: true });
|
||||||
}
|
}
|
||||||
else if (!join) {
|
else if (!join) {
|
||||||
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
|
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message };
|
||||||
await db.joinChannel.create(body);
|
await db.joinChannel.create(body);
|
||||||
return interaction.reply({ content: `The join message have been set with ${args[0]}`, ephemeral: true });
|
return interaction.reply({ content: `The join message have been set with ${args.message}`, ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,12 +49,12 @@ export default {
|
||||||
if (!interactionMenu.isButton) return;
|
if (!interactionMenu.isButton) return;
|
||||||
interactionMenu.update({ components: [] });
|
interactionMenu.update({ components: [] });
|
||||||
if (interactionMenu.customId === 'edit') {
|
if (interactionMenu.customId === 'edit') {
|
||||||
if (!args[0]) {
|
if (!args.message) {
|
||||||
return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true });
|
return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true });
|
||||||
}
|
}
|
||||||
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
|
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message };
|
||||||
await db.joinChannel.update(body, { where: { guildID: interaction.guild.id } });
|
await db.joinChannel.update(body, { where: { guildID: interaction.guild.id } });
|
||||||
return interaction.editReply({ content: `The join message has been set to ${args[0]}`, ephemeral: true });
|
return interaction.editReply({ content: `The join message has been set to ${args.message}`, ephemeral: true });
|
||||||
}
|
}
|
||||||
else if (interactionMenu.customId === 'remove') {
|
else if (interactionMenu.customId === 'remove') {
|
||||||
db.joinChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } });
|
db.joinChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } });
|
||||||
|
|
|
@ -16,7 +16,7 @@ export default {
|
||||||
.setRequired(true)),
|
.setRequired(true)),
|
||||||
category: 'fun',
|
category: 'fun',
|
||||||
async execute(interaction, args) {
|
async execute(interaction, args) {
|
||||||
let board = args[0];
|
let board = args.board;
|
||||||
|
|
||||||
if (fourChan[board] == undefined) {
|
if (fourChan[board] == undefined) {
|
||||||
return interaction.reply({ content: 'Uh oh! The board you are looking for does not exist? You think this is a mistake? Please send a feedback telling me so!', ephemeral: true });
|
return interaction.reply({ content: 'Uh oh! The board you are looking for does not exist? You think this is a mistake? Please send a feedback telling me so!', ephemeral: true });
|
||||||
|
|
|
@ -20,12 +20,12 @@ export default {
|
||||||
clientPermissions: [ PermissionFlagsBits.ManageWebhooks ],
|
clientPermissions: [ PermissionFlagsBits.ManageWebhooks ],
|
||||||
async execute(interaction, args) {
|
async execute(interaction, args) {
|
||||||
await interaction.deferReply({ ephemeral: true });
|
await interaction.deferReply({ ephemeral: true });
|
||||||
const member = args[0];
|
const member = args.user;
|
||||||
const message = args[1];
|
const message = args.message;
|
||||||
const attachment = args[2];
|
const attachment = args.image;
|
||||||
|
|
||||||
|
const webhook = await interaction.channel.createWebhook({
|
||||||
const webhook = await interaction.channel.createWebhook(member.user.username, {
|
name: member.user.username,
|
||||||
avatar: member.user.displayAvatarURL(),
|
avatar: member.user.displayAvatarURL(),
|
||||||
reason: `Fakebot/user command triggered by: ${interaction.user.username}`,
|
reason: `Fakebot/user command triggered by: ${interaction.user.username}`,
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,7 +13,7 @@ export default {
|
||||||
category: 'fun',
|
category: 'fun',
|
||||||
async execute(interaction, args) {
|
async execute(interaction, args) {
|
||||||
await interaction.deferReply({ ephemeral: false });
|
await interaction.deferReply({ ephemeral: false });
|
||||||
const subreddit = args[0];
|
const subreddit = args.subreddit;
|
||||||
fetch('https://www.reddit.com/r/' + subreddit + '.json?limit=100').then((response) => {
|
fetch('https://www.reddit.com/r/' + subreddit + '.json?limit=100').then((response) => {
|
||||||
return response.json();
|
return response.json();
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
|
|
|
@ -27,8 +27,8 @@ export default {
|
||||||
ratelimit: 3,
|
ratelimit: 3,
|
||||||
cooldown: 3600,
|
cooldown: 3600,
|
||||||
async execute(interaction, args, client) {
|
async execute(interaction, args, client) {
|
||||||
const content = args[0];
|
const content = args.content;
|
||||||
const attachment = args[1];
|
const attachment = args.image;
|
||||||
|
|
||||||
if (!content && !attachment) {
|
if (!content && !attachment) {
|
||||||
return interaction.reply({ content: 'Uh oh! You are missing any content for me to tweet!', ephemeral: true });
|
return interaction.reply({ content: 'Uh oh! You are missing any content for me to tweet!', ephemeral: true });
|
||||||
|
|
|
@ -16,7 +16,7 @@ export default {
|
||||||
.setRequired(false)),
|
.setRequired(false)),
|
||||||
category: 'fun',
|
category: 'fun',
|
||||||
async execute(interaction, args) {
|
async execute(interaction, args) {
|
||||||
if (!interaction.channel.nsfw && !args[0]) return interaction.reply(`Please execute this command in an NSFW channel ( Content might not be NSFW but since the video are user submitted better safe than sorry ) OR do \`\`${prefixs[0]}ytp --force\`\` to make the command work outside of nsfw channel BE AWARE THAT IT WON'T CHANGE THE FINAL RESULT SO NSFW CAN STILL HAPPEN`);
|
if (!interaction.channel.nsfw && !args.force) return interaction.reply(`Please execute this command in an NSFW channel ( Content might not be NSFW but since the video are user submitted better safe than sorry ) OR do \`\`${prefixs[0]}ytp --force\`\` to make the command work outside of nsfw channel BE AWARE THAT IT WON'T CHANGE THE FINAL RESULT SO NSFW CAN STILL HAPPEN`);
|
||||||
|
|
||||||
// Read userVid folder and select random vid and only take .mp4
|
// Read userVid folder and select random vid and only take .mp4
|
||||||
const mp4 = [];
|
const mp4 = [];
|
||||||
|
@ -50,7 +50,7 @@ export default {
|
||||||
resources: './asset/ytp/resources/',
|
resources: './asset/ytp/resources/',
|
||||||
temp: os.tmpdir(),
|
temp: os.tmpdir(),
|
||||||
sourceList: asset,
|
sourceList: asset,
|
||||||
intro: args[0] ? './asset/ytp/intro.mp4' : null,
|
intro: args.force ? './asset/ytp/intro.mp4' : null,
|
||||||
outro: './asset/ytp/outro.mp4',
|
outro: './asset/ytp/outro.mp4',
|
||||||
OUTPUT_FILE: `${os.tmpdir()}/${interaction.id}_YTP.mp4`,
|
OUTPUT_FILE: `${os.tmpdir()}/${interaction.id}_YTP.mp4`,
|
||||||
MAX_CLIPS: MAX_CLIPS,
|
MAX_CLIPS: MAX_CLIPS,
|
||||||
|
|
|
@ -10,7 +10,7 @@ export default {
|
||||||
.setRequired(true)),
|
.setRequired(true)),
|
||||||
category: 'secret',
|
category: 'secret',
|
||||||
async execute(interaction, args) {
|
async execute(interaction, args) {
|
||||||
const command = args[0];
|
const command = args.something;
|
||||||
|
|
||||||
if (command === 'levertowned') {
|
if (command === 'levertowned') {
|
||||||
interaction.reply('Hello buddy bro <:youngtroll:488559163832795136> <@434762632004894746>');
|
interaction.reply('Hello buddy bro <:youngtroll:488559163832795136> <@434762632004894746>');
|
||||||
|
|
|
@ -28,9 +28,9 @@ export default {
|
||||||
|
|
||||||
async execute(interaction, args, c) {
|
async execute(interaction, args, c) {
|
||||||
client = c;
|
client = c;
|
||||||
const url = args[0];
|
const url = args.url;
|
||||||
const format = args[1];
|
const format = args.format;
|
||||||
interaction.doCompress = args[2];
|
interaction.doCompress = args.compress;
|
||||||
if (interaction.cleanUp) {
|
if (interaction.cleanUp) {
|
||||||
cleanUp = interaction.cleanUp;
|
cleanUp = interaction.cleanUp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ export default {
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
||||||
if (interaction.guild) Embed.addFields({ name: 'Guild', value: `${interaction.guild.name} (${interaction.guild.id})`, inline: true });
|
if (interaction.guild) Embed.addFields({ name: 'Guild', value: `${interaction.guild.name} (${interaction.guild.id})`, inline: true });
|
||||||
Embed.addFields({ name: 'Feedback', value: args[0], inline: true });
|
Embed.addFields({ name: 'Feedback', value: args.feedback, inline: true });
|
||||||
|
|
||||||
// Don't let new account use this command to prevent spam
|
// Don't let new account use this command to prevent spam
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
|
|
|
@ -7,11 +7,15 @@ const prefixs = prefix.split(',');
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('help')
|
.setName('help')
|
||||||
.setDescription('Displays a list of commands or information about a command.'),
|
.setDescription('Displays a list of commands or information about a command.')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option.setName('command')
|
||||||
|
.setDescription('The command you want more details about.')),
|
||||||
category: 'utility',
|
category: 'utility',
|
||||||
async execute(interaction, args, client) {
|
async execute(interaction, args, client) {
|
||||||
if (args[0]) {
|
if (args.command) {
|
||||||
const command = client.commands.get(args[0]);
|
const command = client.commands.get(args.command);
|
||||||
|
if (!command) return interaction.reply(`Did not found any command named \`\`${args.command}\`\`. Please make sure it is a valid command and not an alias.`);
|
||||||
const description = Object.assign({
|
const description = Object.assign({
|
||||||
content: 'No description available.',
|
content: 'No description available.',
|
||||||
usage: '',
|
usage: '',
|
||||||
|
|
|
@ -17,7 +17,7 @@ export default {
|
||||||
category: 'utility',
|
category: 'utility',
|
||||||
async execute(interaction, args) {
|
async execute(interaction, args) {
|
||||||
await interaction.deferReply({ ephemeral: false });
|
await interaction.deferReply({ ephemeral: false });
|
||||||
const url = args[0];
|
const url = args.url;
|
||||||
|
|
||||||
if (!await utils.stringIsAValidurl(url)) {
|
if (!await utils.stringIsAValidurl(url)) {
|
||||||
console.error(`Not a url!!! ${url}`);
|
console.error(`Not a url!!! ${url}`);
|
||||||
|
|
|
@ -75,15 +75,17 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const args = [];
|
const args = {};
|
||||||
|
// https://discord-api-types.dev/api/discord-api-types-v10/enum/ApplicationCommandOptionType
|
||||||
interaction.options.data.forEach(arg => {
|
interaction.options.data.forEach(arg => {
|
||||||
if (arg.type === 'MENTIONABLE') {
|
let payload = arg.value;
|
||||||
return args.push(arg.member);
|
if (arg.type === 9) {
|
||||||
|
payload = arg.member;
|
||||||
}
|
}
|
||||||
else if (arg.type === 'ATTACHMENT') {
|
else if (arg.type === 11) {
|
||||||
return args.push(arg.attachment);
|
payload = arg.attachment;
|
||||||
}
|
}
|
||||||
args.push(arg.value);
|
args[arg.name] = payload;
|
||||||
});
|
});
|
||||||
|
|
||||||
await command.execute(interaction, args, client);
|
await command.execute(interaction, args, client);
|
||||||
|
|
|
@ -262,7 +262,7 @@ export default {
|
||||||
|
|
||||||
const messageArray = message.content.match(/"[^"]*"|\S+/g).map(m => m.slice(0, 1) === '"' ? m.slice(1, -1) : m);
|
const messageArray = message.content.match(/"[^"]*"|\S+/g).map(m => m.slice(0, 1) === '"' ? m.slice(1, -1) : m);
|
||||||
let commandName = messageArray[1].toLowerCase();
|
let commandName = messageArray[1].toLowerCase();
|
||||||
let messageArgs = messageArray.splice(2, messageArray.length);
|
const messageArgs = messageArray.splice(2, messageArray.length);
|
||||||
|
|
||||||
// Search for alias
|
// Search for alias
|
||||||
client.commands.find(c => {
|
client.commands.find(c => {
|
||||||
|
@ -368,31 +368,21 @@ export default {
|
||||||
msg.delete();
|
msg.delete();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const args = {};
|
||||||
|
|
||||||
if (command.data.options.length > 0) {
|
for (let i = 0; i < command.data.options.length; i++) {
|
||||||
// if (command.data.options.length === 1 || command.data.options[command.data.options.length - 1].constructor.name.toLowerCase().includes('attachment')) {
|
const arg = command.data.options[i];
|
||||||
if (command.data.options.length === 1) {
|
const type = arg.constructor.name.toLowerCase();
|
||||||
const test = messageArgs.join(' ');
|
let payload = messageArgs[i];
|
||||||
messageArgs = [];
|
if (type.includes('mentionable')) {
|
||||||
messageArgs.push(test);
|
payload = message.mentions.members.first();
|
||||||
}
|
}
|
||||||
|
else if (type.includes('attachment')) {
|
||||||
for (let i = 0; i < messageArgs.length; i++) {
|
payload = message.attachments.first();
|
||||||
const constructorName = command.data.options[i].constructor.name.toLowerCase();
|
|
||||||
if (constructorName.includes('boolean')) {
|
|
||||||
messageArgs[i] = (messageArgs[i].toLowerCase() === 'true');
|
|
||||||
}
|
}
|
||||||
|
args[arg.name] = payload;
|
||||||
if (constructorName.includes('mentionable')) {
|
|
||||||
messageArgs[i] = message.mentions.members.first();
|
|
||||||
}
|
}
|
||||||
}
|
await command.execute(message, args, client);
|
||||||
if (message.attachments) {
|
|
||||||
messageArgs.push(Array.from(message.attachments.values())[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await command.execute(message, messageArgs, client);
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
Loading…
Reference in a new issue