diff --git a/src/commands/command.js b/src/commands/command.js index ef96e82ef..c6406e638 100644 --- a/src/commands/command.js +++ b/src/commands/command.js @@ -16,6 +16,7 @@ const adminCommands = {}; const aliasToCommand = {}; const mcommands = {}; const commandGroups = {}; +const appCommandNameToCommand = {}; class Command { constructor(main) { @@ -144,6 +145,10 @@ class Command { this.main.bot.users.update(rawUser, this.main.bot); } } + + messageUserInteractionToCommand(interaction) { + return appCommandNameToCommand[interaction.name]; + } } async function executeCommand(main, p) { @@ -214,6 +219,13 @@ function initCommands() { six: command.six, group: command.group, }; + + command.appCommands?.forEach((appCommand) => { + // Message or User commands + if (appCommand.type === 3 || appCommand.type === 2) { + appCommandNameToCommand[appCommand.name] = name; + } + }); }; let addAdminCommand = function (command) { @@ -256,6 +268,7 @@ function initParam(msg, command, args, main, context) { let param = { msg: msg, options: msg.options || {}, + interaction: msg.interaction, args: args, context: context, command: command, diff --git a/src/commands/commandList/memegen/eject.js b/src/commands/commandList/memegen/eject.js index 1f1b227e8..692597017 100644 --- a/src/commands/commandList/memegen/eject.js +++ b/src/commands/commandList/memegen/eject.js @@ -7,6 +7,7 @@ const CommandInterface = require('../../CommandInterface.js'); +const commandGroups = require('../../../utils/commandGroups.js'); const request = require('request'); const rocketEmoji = '🚀'; @@ -25,13 +26,36 @@ module.exports = new CommandInterface({ group: ['memegeneration'], + appCommands: [ + commandGroups.addOption('eject', ['gen'], { + 'name': 'eject', + 'description': 'Eject the user into space', + 'type': 1, + 'options': [ + { + 'name': 'user', + 'description': 'The user to use', + 'type': 6, + 'required': true, + }, + ], + }), + { + 'type': 2, + 'name': 'Eject to space', + 'dm_permission': true, + 'integration_types': [0, 1], + 'contexts': [0, 1, 2], + }, + ], + cooldown: 30000, half: 100, six: 500, bot: true, execute: async function (p) { - let user = p.getMention(p.args[0]); + let user = p.options.user || p.getMention(p.args[0]); if (!user) { p.errorMsg(', you must tag a user!', 5000); p.setCooldown(5); diff --git a/src/commands/commandList/memegen/emergency.js b/src/commands/commandList/memegen/emergency.js index 246ff1611..457dae9b1 100644 --- a/src/commands/commandList/memegen/emergency.js +++ b/src/commands/commandList/memegen/emergency.js @@ -7,6 +7,7 @@ const CommandInterface = require('../../CommandInterface.js'); +const commandGroups = require('../../../utils/commandGroups.js'); const request = require('request'); const Vibrant = require('node-vibrant'); const rocketEmoji = '🚀'; @@ -26,6 +27,14 @@ module.exports = new CommandInterface({ group: ['memegeneration'], + appCommands: [ + commandGroups.addOption('emergency', ['gen'], { + 'name': 'emergency', + 'description': 'Call an emergency meeting', + 'type': 1, + }), + ], + cooldown: 30000, half: 100, six: 500, diff --git a/src/commands/commandList/memegen/headpat.js b/src/commands/commandList/memegen/headpat.js index 14913a14d..04ca7aeb4 100644 --- a/src/commands/commandList/memegen/headpat.js +++ b/src/commands/commandList/memegen/headpat.js @@ -35,13 +35,11 @@ module.exports = new CommandInterface({ 'name': 'user', 'description': "Generate a headpat emoji with a user's avatar", 'type': 1, - 'required': false, 'options': [ { 'name': 'user', 'description': 'The user to use', 'type': 6, - 'required': false, }, ], }, @@ -49,7 +47,6 @@ module.exports = new CommandInterface({ 'name': 'emoji', 'description': 'Generate a headpat emoji with an emoji', 'type': 1, - 'required': false, 'options': [ { 'name': 'emoji', @@ -61,6 +58,13 @@ module.exports = new CommandInterface({ }, ], }), + { + 'type': 2, + 'name': 'Headpat', + 'dm_permission': true, + 'integration_types': [0, 1], + 'contexts': [0, 1, 2], + }, ], cooldown: 30000, @@ -120,11 +124,13 @@ async function display(p, url, name) { collector.on('collect', async (component, user, ack) => { try { if (await emojiAdder.addEmoji(user.id)) { - (content.embed = createEmbed(p, url, name, emojiName, emojiAdder)), ack(content); + content.embed = createEmbed(p, url, name, emojiName, emojiAdder); + ack(content); } } catch (err) { if (!emojiAdder.successCount) { - (content.embed = createEmbed(p, url, name, emojiName, emojiAdder)), ack(content); + content.embed = createEmbed(p, url, name, emojiName, emojiAdder); + ack(content); } } }); diff --git a/src/commands/commandList/memegen/waddle.js b/src/commands/commandList/memegen/waddle.js index 7c105d90e..28ed4d62e 100644 --- a/src/commands/commandList/memegen/waddle.js +++ b/src/commands/commandList/memegen/waddle.js @@ -35,13 +35,11 @@ module.exports = new CommandInterface({ 'name': 'user', 'description': "Generate a waddle emoji with a user's avatar", 'type': 1, - 'required': false, 'options': [ { 'name': 'user', 'description': 'The user to use', 'type': 6, - 'required': false, }, ], }, @@ -49,7 +47,6 @@ module.exports = new CommandInterface({ 'name': 'emoji', 'description': 'Generate a waddle emoji with an emoji', 'type': 1, - 'required': false, 'options': [ { 'name': 'emoji', diff --git a/src/commands/commandList/social/emoji.js b/src/commands/commandList/social/emoji.js index 001a1a3eb..189135545 100644 --- a/src/commands/commandList/social/emoji.js +++ b/src/commands/commandList/social/emoji.js @@ -40,41 +40,20 @@ module.exports = new CommandInterface({ six: 500, execute: async function (p) { - /* Look at previous message */ - if ( - p.args.length == 0 || - (p.args[0] && - (p.args[0].toLowerCase() == 'prev' || - p.args[0].toLowerCase() == 'previous' || - p.args[0].toLowerCase() == 'p')) - ) { + // Special case for message interaction + if (this.interaction && this.options.message) { + const emojis = parseEmojis([this.options.message]); + await display(p, emojis); + + /* Look at previous message */ + } else if (!p.args.length || ['prev', 'previous', 'p'].includes(p.args[0]?.toLowerCase())) { let msgs = await p.global.getChannelMessages(p.msg.channel, 10); if (!msgs) { p.errorMsg(', There are no emojis! >:c', 3000); return; } - let emojis = ''; - for (let i in msgs) { - const msg = msgs[i]; - emojis += msg.content; - emojis += JSON.stringify(msg.embeds); - if (msg.reactions) { - for (let name in msg.reactions) { - const emoji = msg.reactions[name]; - emojis += `<${emoji.animated ? 'a' : ''}:${name}>`; - } - } - if (msg.stickerItems?.length) { - msg.stickerItems.forEach((sticker) => { - emojis += ``; - }); - } - } - - emojis = parseIDs(emojis); - if (emojis.length == 0) - p.errorMsg(', There are no emojis! I can only look at the previous 10 messages! >:c', 3000); - else await display(p, emojis); + const emojis = parseEmojis(msgs); + await display(p, emojis); // Set emoji steal guild } else if (['setguild', 'setserver', 'set', 'setsteal'].includes(p.args[0].toLowerCase())) { @@ -90,12 +69,32 @@ module.exports = new CommandInterface({ } else { let text = p.args.join(' '); let emojis = parseIDs(text); - if (emojis.length == 0) p.errorMsg(', There are no emojis! >:c', 3000); - else await display(p, emojis); + await display(p, emojis); } }, }); +function parseEmojis(msgs) { + let emojis = ''; + msgs.forEach((msg) => { + emojis += msg.content; + emojis += JSON.stringify(msg.embeds); + if (msg.reactions) { + for (let name in msg.reactions) { + const emoji = msg.reactions[name]; + emojis += `<${emoji.animated ? 'a' : ''}:${name}>`; + } + } + if (msg.stickerItems?.length) { + msg.stickerItems.forEach((sticker) => { + emojis += ``; + }); + } + }); + + return parseIDs(emojis); +} + function parseIDs(text) { let emojis = []; @@ -130,6 +129,9 @@ function parseIDs(text) { } async function display(p, emojis) { + if (emojis.length == 0) { + return p.errorMsg(', There are no emojis! >:c', 3000); + } const emojiAdders = []; const createEmbed = (currentPage, maxPage) => { const emoji = emojis[currentPage]; diff --git a/src/commands/commandList/social/level.js b/src/commands/commandList/social/level.js index 599f4784f..efae6743b 100644 --- a/src/commands/commandList/social/level.js +++ b/src/commands/commandList/social/level.js @@ -25,12 +25,39 @@ module.exports = new CommandInterface({ group: ['social'], + appCommands: [ + { + 'name': 'level', + 'type': 1, + 'description': 'Display your level', + 'integration_types': [0, 1], + 'contexts': [0, 1, 2], + 'options': [ + { + 'type': 3, + 'name': 'type', + 'description': 'Either server or global level', + 'choices': [ + { + 'name': 'Server', + 'value': 'server', + }, + { + 'name': 'Global', + 'value': 'global', + }, + ], + }, + ], + }, + ], + cooldown: 15000, half: 100, six: 500, execute: async function (p) { - let perms = p.msg.member.permissions; + let perms = p.msg.member?.permissions; if (p.args.length >= 1 && ['disable', 'disabletext', 'dt'].includes(p.args[0].toLowerCase())) { if (perms.has('manageChannels')) { let sql = `INSERT INTO guild_setting (id,levelup) VALUES (${p.msg.channel.guild.id},1) ON DUPLICATE KEY UPDATE levelup = 1;`; @@ -58,8 +85,16 @@ module.exports = new CommandInterface({ } else { //try{ let opt = {}; - if (p.args[0] == 's' || p.args[0] == 'server' || p.args[0] == 'g' || p.args[0] == 'guild') { - opt.guild = true; + if ( + this.options.type === 'server' || + p.args[0] == 's' || + p.args[0] == 'server' || + p.args[0] == 'g' || + p.args[0] == 'guild' + ) { + if (this.msg.channel.guild) { + opt.guild = true; + } } let uuid = await levelUtil.display(p, p.msg.author, opt); @@ -71,7 +106,7 @@ module.exports = new CommandInterface({ let url = `${process.env.GEN_HOST}/level/${uuid}.png`; let data = await p.DataResolver.urlToBuffer(url); await p.send('', null, { file: data, name: 'level.png' }); - if (!opt.guild) await levelRewards.distributeRewards(p.msg); + if (!opt.guild && this.msg.channel?.guild) await levelRewards.distributeRewards(p.msg); /* }catch(e){ console.error(e); diff --git a/src/commands/commandList/social/profile.js b/src/commands/commandList/social/profile.js index 16296172d..d53a9d41f 100644 --- a/src/commands/commandList/social/profile.js +++ b/src/commands/commandList/social/profile.js @@ -29,14 +29,43 @@ module.exports = new CommandInterface({ group: ['social'], + appCommands: [ + { + 'name': 'profile', + 'type': 1, + 'description': 'Display your profile', + 'options': [ + { + 'type': 6, + 'name': 'user', + 'description': "Display a user's profile", + }, + ], + 'integration_types': [0, 1], + 'contexts': [0, 1, 2], + }, + { + 'type': 2, + 'name': 'Display profile', + 'dm_permission': true, + 'integration_types': [0, 1], + 'contexts': [0, 1, 2], + }, + ], + cooldown: 3000, execute: async function (p) { - if (p.args.length <= 0) { + if (!p.options.user && p.args.length <= 0) { await profileUtil.displayProfile(p, p.msg.author); - } else if (p.global.isUser(p.args[0]) || p.global.isInt(p.args[0])) { - let user = p.args[0].match(/[0-9]+/)[0]; - user = await p.fetch.getUser(user); + } else if (p.options.user || p.global.isUser(p.args[0]) || p.global.isInt(p.args[0])) { + let user; + if (p.options.user) { + user = p.options.user; + } else { + user = p.args[0].match(/[0-9]+/)[0]; + user = await p.fetch.getUser(user); + } if (!user) p.errorMsg(", I couldn't find that user!", 3000); else { let sql = `SELECT private FROM user INNER JOIN user_profile ON user.uid = user_profile.uid WHERE id = ${user.id};`; diff --git a/src/commands/commandList/utils/avatar.js b/src/commands/commandList/utils/avatar.js index de2ae8a74..fcd139341 100644 --- a/src/commands/commandList/utils/avatar.js +++ b/src/commands/commandList/utils/avatar.js @@ -22,13 +22,39 @@ module.exports = new CommandInterface({ group: ['social'], + appCommands: [ + { + 'name': 'avatar', + 'type': 1, + 'description': 'Display your avatar', + 'options': [ + { + 'type': 6, + 'name': 'user', + 'description': "Display a user's avatar", + }, + ], + 'integration_types': [0, 1], + 'contexts': [0, 1, 2], + }, + { + 'type': 2, + 'name': 'Display avatar', + 'dm_permission': true, + 'integration_types': [0, 1], + 'contexts': [0, 1, 2], + }, + ], + cooldown: 2000, half: 100, six: 500, execute: async function (p) { let user; - if (p.args.length == 0) { + if (p.options.user) { + user = p.options.user; + } else if (p.args.length == 0) { user = p.msg.author; } else if (p.global.isUser(p.args[0]) || p.global.isInt(p.args[0])) { let id = p.args[0].match(/[0-9]+/)[0]; diff --git a/src/commands/commandList/utils/color.js b/src/commands/commandList/utils/color.js index 330fb901e..7dfc1d440 100644 --- a/src/commands/commandList/utils/color.js +++ b/src/commands/commandList/utils/color.js @@ -36,27 +36,77 @@ module.exports = new CommandInterface({ group: ['utility'], + appCommands: [ + { + 'name': 'color', + 'type': 1, + 'description': 'Show a random color!', + 'options': [ + { + 'type': 6, + 'name': 'user', + 'description': "Display a user's avatar color", + }, + { + 'type': 8, + 'name': 'role', + 'description': "Display a roles's color", + }, + { + 'type': 3, + 'name': 'value', + 'description': 'RGB, HEX, or HSL values', + }, + ], + 'integration_types': [0, 1], + 'contexts': [0, 1, 2], + }, + { + 'type': 2, + 'name': 'Grab avatar colors', + 'dm_permission': true, + 'integration_types': [0, 1], + 'contexts': [0, 1, 2], + }, + ], + cooldown: 4000, execute: async function (p) { let color, title, colors; // No argument = random color - if (!p.args.length) { + if (!p.args.length && !Object.keys(p.options).length) { color = randColor(); title = ', here is your random color!'; } else { - let args = p.args.join(' ').split(/[\s,]+/gi); - let args2 = p.args.join('').replace('#', '').toUpperCase(); - title = ', here is your color for "' + p.args.join(' ') + '"'; + let args = []; + let args2 = ''; + let name = p.args.join(' '); + if (this.options.value) { + args = p.options.value.split(/[\s,]+/gi); + args2 = p.options.value.replace('#', '').toUpperCase(); + name = p.options.value; + } else { + args = p.args.join(' ').split(/[\s,]+/gi); + args2 = p.args.join('').replace('#', '').toUpperCase(); + } + title = ', here is your color for "' + name + '"'; //parse user's avatar color if ( - args.length == 1 && - (p.global.isUser(p.args[0]) || (p.global.isInt(p.args[0]) && parseInt(p.args[0]) > maxInt)) + p.options.user || + (args.length == 1 && + (p.global.isUser(p.args[0]) || + (p.global.isInt(p.args[0]) && parseInt(p.args[0]) > maxInt))) ) { - let id = p.args[0].match(/[0-9]+/)[0]; - let user = await p.fetch.getUser(id); + let user; + if (p.options.user) { + user = p.options.user; + } else { + let id = p.args[0].match(/[0-9]+/)[0]; + user = await p.fetch.getUser(id); + } if (!user) { p.errorMsg(', That user does not exist!', 3000); return; @@ -95,23 +145,28 @@ module.exports = new CommandInterface({ } user = await p.fetch.getMember(p.msg.channel.guild, user.id); color = p.global.getRoleColor(user); + const name = user.username; if (!color) { p.errorMsg(', That user does not have a role color!', 3000); return; } - title = ', here is the role color for **' + user.username + '**'; + title = ', here is the role color for **' + name + '**'; color = parseHex(color.replace('#', '').toUpperCase().padStart(6, '0')); //randomHSL - } else if (p.args.join(' ').includes('%')) { - color = randHSL(p, p.args); + } else if (p.options.value?.includes('%') || p.args.join(' ').includes('%')) { + let args = p.args; + if (p.options.value) { + args = p.options.value.split(/[\s]+/gi); + } + color = randHSL(p, args); //rgb values } else if (args.length == 3 && args.every(p.global.isInt)) { color = parseRGB(args); //int values - } else if (p.args.length == 1 && p.global.isInt(p.args[0])) { + } else if (p.global.isInt(p.args[0] || p.options.value)) { color = parseIntValue(p.args[0]); //hex values @@ -120,10 +175,12 @@ module.exports = new CommandInterface({ // role mention } else if ( - p.msg.roleMentions.length && - (args.length == 1 || (args.length == 2 && ['r', 'role'].includes(args[0].toLowerCase()))) + p.options.role || + (p.msg.roleMentions?.length && + (args.length == 1 || (args.length == 2 && ['r', 'role'].includes(args[0].toLowerCase())))) ) { - let role = p.msg.channel.guild.roles.get(p.msg.roleMentions[0]); + let role = p.options.role || p.msg.channel.guild.roles.get(p.msg.roleMentions[0]); + title = ', here is your color for "' + role.name + '"'; color = parseIntValue(role.color); } } @@ -155,22 +212,46 @@ module.exports = new CommandInterface({ embed.image = { url: colors[page].avatar, }; + const components = [ + { + type: 1, + components: [ + { + type: 2, + style: 1, + custom_id: 'prev', + emoji: { + id: null, + name: prevPageEmoji, + }, + }, + { + type: 2, + style: 1, + custom_id: 'next', + emoji: { + id: null, + name: nextPageEmoji, + }, + }, + ], + }, + ]; let msg = await p.send({ content: colorEmoji + ' **| ' + p.getName() + '**' + title, embed, + components, }); - await msg.addReaction(prevPageEmoji); - await msg.addReaction(nextPageEmoji); - let filter = (emoji, userID) => - [nextPageEmoji, prevPageEmoji].includes(emoji.name) && userID == p.msg.author.id; - let collector = p.reactionCollector.create(msg, filter, { + let filter = (componentName, user) => + ['prev', 'next'].includes(componentName) && user.id == p.msg.author.id; + let collector = p.interactionCollector.create(msg, filter, { time: 900000, idle: 120000, }); - collector.on('collect', async function (emoji) { - if (emoji.name === nextPageEmoji) { + collector.on('collect', async (component, user, ack) => { + if (component === 'next') { if (page + 1 < colors.length) page++; else page = 0; embed = await constructEmbed(colors[page]); @@ -180,11 +261,12 @@ module.exports = new CommandInterface({ embed.image = { url: colors[page].avatar, }; - await msg.edit({ + await ack({ content: colorEmoji + ' **| ' + p.getName() + '**' + title, embed, + components, }); - } else if (emoji.name === prevPageEmoji) { + } else if (component === 'prev') { if (page > 0) page--; else page = colors.length - 1; embed = await constructEmbed(colors[page]); @@ -194,15 +276,18 @@ module.exports = new CommandInterface({ embed.image = { url: colors[page].avatar, }; - await msg.edit({ + await ack({ content: colorEmoji + ' **| ' + p.getName() + '**' + title, embed, + components, }); } }); collector.on('end', async function (_collected) { - await msg.edit({ content: 'This message is now inactive', embed }); + components[0].components[0].disabled = true; + components[0].components[1].disabled = true; + await msg.edit({ content: 'This message is now inactive', embed, components }); }); } }, diff --git a/src/commands/commandList/utils/mathWorker.js b/src/commands/commandList/utils/mathWorker.js index daed398b7..b796ae3b6 100644 --- a/src/commands/commandList/utils/mathWorker.js +++ b/src/commands/commandList/utils/mathWorker.js @@ -37,4 +37,6 @@ function compute(expression) { return limitedEvaluate(expression); } -workerpool.worker({ compute: compute }); +if (process.send) { + workerpool.worker({ compute: compute }); +} diff --git a/src/eventHandlers/interactionCreate.js b/src/eventHandlers/interactionCreate.js index 91e3eb64b..c5e2d4db7 100644 --- a/src/eventHandlers/interactionCreate.js +++ b/src/eventHandlers/interactionCreate.js @@ -22,6 +22,12 @@ function handleCommand(interaction) { case 1: handleSlash.bind(this)(interaction); break; + case 2: + handleUser.bind(this)(interaction); + break; + case 3: + handleMessage.bind(this)(interaction); + break; default: break; } @@ -43,6 +49,36 @@ function getSlashCommand(interaction) { return command || interaction.data.name; } +async function handleMessage(interaction) { + ackTimer(interaction); + interaction.command = getApplicationCommand.bind(this)(interaction); + interaction.author = interaction.member?.user || interaction.user; + interaction.interaction = true; + interaction.acked = false; + interaction.options = getInteractionArgs(interaction.data, interaction.data.resolved); + interaction.options.message = interaction.data.resolved?.messages?.entries().next().value[1]; + interaction.args = []; + this.command.executeInteraction(interaction); +} + +async function handleUser(interaction) { + ackTimer(interaction); + interaction.command = getApplicationCommand.bind(this)(interaction); + interaction.author = interaction.member?.user || interaction.user; + interaction.interaction = true; + interaction.acked = false; + interaction.options = getInteractionArgs(interaction.data, interaction.data.resolved); + interaction.options.member = interaction.data.resolved?.members?.entries().next().value[1]; + interaction.options.user = interaction.data.resolved?.users?.entries().next().value[1]; + interaction.args = []; + this.command.executeInteraction(interaction); +} + +function getApplicationCommand(interaction) { + let command = this.command.messageUserInteractionToCommand(interaction.data); + return command || interaction.data.name; +} + function getInteractionArgs(interaction, resolved, result = {}) { interaction.options?.forEach((option) => { /* eslint-disable no-fallthrough */ @@ -51,6 +87,9 @@ function getInteractionArgs(interaction, resolved, result = {}) { case 6: result[option.name] = resolved.users.get(option.value); break; + case 8: + result[option.name] = resolved.roles.get(option.value); + break; // Sub command case 2: // Command diff --git a/src/eventHandlers/rawWS.js b/src/eventHandlers/rawWS.js index ccfc3da8f..ee0ad8f10 100644 --- a/src/eventHandlers/rawWS.js +++ b/src/eventHandlers/rawWS.js @@ -4,17 +4,11 @@ * This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International * For more information, see README.md and LICENSE */ -const User = require('../../node_modules/eris/lib/structures/User'); const patreonUtil = require('../commands/commandList/patreon/utils/patreonUtil.js'); -const axios = require('axios'); exports.handle = function (packet, _id) { if (packet.t === 'INTERACTION_CREATE') { switch (packet.d.type) { - case 2: - handleApplicationCommand.bind(this)(packet); - break; - // Buttons case 3: handleMessageComponent.bind(this)(packet); @@ -29,96 +23,7 @@ exports.handle = function (packet, _id) { } }; -function handleApplicationCommand(packet) { - const interaction = new Interaction(this.bot, packet.d); - switch (packet.d.data.type) { - // Slash commands - case 1: - // this.command.executeInteraction(interaction); - break; - - // Message commands - case 3: - this.interactionHandlers.messages.emit(interaction); - break; - } -} - function handleMessageComponent(packet) { this.interactionHandlers.buttons.emit(packet.d.data.custom_id, packet.d) || this.interactionCollector.interact(packet.d); } - -class Interaction { - constructor(bot, data) { - this.interaction = true; - this.command = data.data.name; - this.id = data.id; - - this.channel = bot.getChannel(data.channel_id) || { - id: data.channel_id, - }; - - const author = data.member?.user || data.user; - if (author.discriminator !== '0000') { - this.author = bot.users.update(author, bot); - } else { - this.author = new User(author, bot); - } - - if (this.channel.guild) { - if (data.member) { - data.member.id = this.author.id; - this.member = this.channel.guild.members.update(data.member, this.channel.guild); - } else if (this.channel.guild.members.has(this.author.id)) { - this.member = this.channel.guild.members.get(this.author.id); - } else { - this.member = null; - } - - if (!this.guildID) { - this.guildID = this.channel.guild.id; - } - } else { - this.member = null; - } - - this.replied = false; - this.token = data.token; - this.url = `https://discord.com/api/v8/interactions/${data.id}/${data.token}/callback`; - this.followUpUrl = `https://discord.com/api/v8/webhooks/${bot.application.id}/${data.token}/messages/@original`; - - this.packet = data; - - // TODO - this.args = []; - } - - async createMessage(content, file, del) { - await axios.post(this.url, { - type: 4, - data: content, - }); - - if (del) { - setTimeout(() => { - axios.delete(this.followUpUrl); - }, del); - } - - return { - id: this.id, - channel: this.channel, - edit: (content) => { - if (typeof content === 'string') { - content = { content }; - } - if (content.embed) { - content.embeds = [content.embed]; - delete content.embed; - } - return axios.patch(this.followUpUrl, content); - }, - }; - } -} diff --git a/src/interactionHandlers/index.js b/src/interactionHandlers/index.js index 5c43284d0..848f8faac 100644 --- a/src/interactionHandlers/index.js +++ b/src/interactionHandlers/index.js @@ -7,7 +7,6 @@ class InteractionHandler { constructor(main) { this.buttons = new (require('./button'))(main); - this.messages = new (require('./messageCommands'))(main); } } diff --git a/src/interactionHandlers/messageCommands/grabEmoji.js b/src/interactionHandlers/messageCommands/grabEmoji.js deleted file mode 100644 index 5b3cf9b85..000000000 --- a/src/interactionHandlers/messageCommands/grabEmoji.js +++ /dev/null @@ -1,35 +0,0 @@ -/* - * OwO Bot for Discord - * Copyright (C) 2021 Christopher Thai - * This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International - * For more information, see README.md and LICENSE - */ - -exports.name = 'Grab Emojis'; - -exports.handle = async function (interaction) { - let content = ''; - const messages = interaction.packet.data.resolved.messages; - for (let id in messages) { - const msg = messages[id]; - content += msg.content; - content += JSON.stringify(msg.embeds); - content += JSON.stringify(msg.reactions); - if (msg.reactions?.length) { - msg.reactions.forEach((reaction) => { - const emoji = reaction.emoji; - content += `<${emoji.animated ? 'a' : ''}:${emoji.name}:${emoji.id}>`; - }); - } - if (msg.sticker_items?.length) { - msg.sticker_items.forEach((sticker) => { - content += ``; - }); - } - } - - interaction.args = [content]; - interaction.command = 'emoji'; - - this.command.executeInteraction(interaction); -}; diff --git a/src/interactionHandlers/messageCommands/index.js b/src/interactionHandlers/messageCommands/index.js deleted file mode 100644 index 09aaaeaf9..000000000 --- a/src/interactionHandlers/messageCommands/index.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - * OwO Bot for Discord - * Copyright (C) 2021 Christopher Thai - * This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International - * For more information, see README.md and LICENSE - */ -const requireDir = require('require-dir'); -const dir = requireDir('./'); - -class InteractionHandler { - constructor(main) { - this.listeners = {}; - let filename = __filename.slice(__dirname.length + 1, -3); - for (let listener in dir) { - if (listener != filename) { - const interactionName = dir[listener].name; - this.listeners[interactionName] = dir[listener].handle.bind(main); - } - } - } - - emit(interaction) { - if (this.listeners[interaction.command]) { - this.listeners[interaction.command](interaction); - return true; - } - return false; - } -} - -module.exports = InteractionHandler;