From e61a604b7ce4be6e5f01268236d99ee1dfcf35ac Mon Sep 17 00:00:00 2001 From: bignutty <3515180-bignutty@users.noreply.gitlab.com> Date: Tue, 11 Jun 2024 23:16:40 +0200 Subject: [PATCH] adds incognito mode, fixes /emoji --- commands/interaction/context/audio.js | 7 +- commands/interaction/context/ocr.js | 5 +- commands/interaction/context/ocrtr.js | 5 +- commands/interaction/context/reverse-image.js | 7 +- commands/interaction/context/transcribe.js | 66 ++++++++++--------- commands/interaction/slash/fun/otter.js | 18 +++-- commands/interaction/slash/info/avatar.js | 12 +++- commands/interaction/slash/info/user.js | 14 +++- .../interaction/slash/search/google-images.js | 14 +++- commands/interaction/slash/search/google.js | 14 +++- commands/interaction/slash/search/lyrics.js | 14 +++- .../interaction/slash/search/wolfram-alpha.js | 14 +++- commands/interaction/slash/search/xkcd.js | 14 +++- commands/interaction/slash/search/youtube.js | 24 +++++-- .../interaction/slash/utils/dictionary.js | 14 +++- commands/interaction/slash/utils/emoji.js | 14 +++- commands/interaction/slash/utils/emojiinfo.js | 10 ++- .../interaction/slash/utils/screenshot.js | 12 +++- commands/interaction/slash/utils/weather.js | 12 +++- .../subcommands/tts/imtranslator.js | 12 +++- .../interaction/subcommands/tts/microsoft.js | 12 +++- .../interaction/subcommands/tts/moonbase.js | 13 +++- .../interaction/subcommands/tts/playht.js | 12 +++- .../subcommands/tts/tiktok/character.js | 14 +++- .../subcommands/tts/tiktok/french.js | 14 +++- .../subcommands/tts/tiktok/german.js | 14 +++- .../subcommands/tts/tiktok/indonesian.js | 14 +++- .../subcommands/tts/tiktok/italian.js | 14 +++- .../subcommands/tts/tiktok/japanese.js | 14 +++- .../subcommands/tts/tiktok/korean.js | 14 +++- .../subcommands/tts/tiktok/pop-culture.js | 14 +++- .../subcommands/tts/tiktok/portugese.js | 14 +++- .../subcommands/tts/tiktok/song.js | 13 +++- .../subcommands/tts/tiktok/spanish.js | 13 +++- labscore/utils/interactions.js | 23 +++++++ labscore/utils/message.js | 14 +++- 36 files changed, 401 insertions(+), 127 deletions(-) create mode 100644 labscore/utils/interactions.js diff --git a/commands/interaction/context/audio.js b/commands/interaction/context/audio.js index 046a89d..837f253 100644 --- a/commands/interaction/context/audio.js +++ b/commands/interaction/context/audio.js @@ -1,7 +1,8 @@ const { renderMusicButtons } = require('#utils/buttons'); -const { createEmbed } = require('#utils/embed') +const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); -const { InteractionCallbackTypes, ApplicationCommandTypes } = require("detritus-client/lib/constants");; +const { ApplicationCommandTypes } = require("detritus-client/lib/constants");; const superagent = require('superagent') @@ -20,7 +21,7 @@ module.exports = { ], run: async (context, args) => { try{ - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context); const { message } = args; diff --git a/commands/interaction/context/ocr.js b/commands/interaction/context/ocr.js index 7f843cf..6f8b54d 100644 --- a/commands/interaction/context/ocr.js +++ b/commands/interaction/context/ocr.js @@ -2,10 +2,11 @@ const { googleVisionOcr } = require('#api'); const { getMessageAttachment, validateAttachment } = require('#utils/attachment'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { codeblock } = require('#utils/markdown'); const { STATICS } = require('#utils/statics'); -const { InteractionCallbackTypes, ApplicationCommandTypes, MessageFlags } = require("detritus-client/lib/constants"); +const { ApplicationCommandTypes, MessageFlags } = require("detritus-client/lib/constants"); module.exports = { name: 'OCR', @@ -20,7 +21,7 @@ module.exports = { ], run: async (context, args) => { try{ - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context); const { message } = args; diff --git a/commands/interaction/context/ocrtr.js b/commands/interaction/context/ocrtr.js index 4c88055..f2187fb 100644 --- a/commands/interaction/context/ocrtr.js +++ b/commands/interaction/context/ocrtr.js @@ -3,11 +3,12 @@ const { TRANSLATE_LANGUAGE_MAPPINGS, TRANSLATE_LANGUAGES } = require('#constants const { getMessageAttachment, validateAttachment } = require('#utils/attachment'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { editOrReply } = require('#utils/message'); const { codeblock, icon, pill } = require('#utils/markdown'); const { STATICS } = require('#utils/statics'); -const { InteractionCallbackTypes, ApplicationCommandTypes, MessageFlags } = require("detritus-client/lib/constants"); +const { ApplicationCommandTypes, MessageFlags } = require("detritus-client/lib/constants"); module.exports = { name: 'OCR Translate', @@ -21,8 +22,8 @@ module.exports = { 1 ], run: async (context, args) => { + await acknowledge(context); try{ - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) const { message } = args; diff --git a/commands/interaction/context/reverse-image.js b/commands/interaction/context/reverse-image.js index 95042a2..fd4c65e 100644 --- a/commands/interaction/context/reverse-image.js +++ b/commands/interaction/context/reverse-image.js @@ -2,11 +2,12 @@ const { reverseImageSearch } = require('#api'); const { paginator } = require('#client'); const { getMessageAttachment, validateAttachment } = require('#utils/attachment'); -const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed') +const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { editOrReply } = require('#utils/message') const { STATICS } = require('#utils/statics') -const { InteractionCallbackTypes, ApplicationCommandTypes } = require("detritus-client/lib/constants"); +const { ApplicationCommandTypes } = require("detritus-client/lib/constants"); // TODO: create a favicon() util function createReverseImageSearchResultPage(context, result, source) { @@ -45,7 +46,7 @@ module.exports = { ], run: async (context, args) => { try{ - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context); const { message } = args; diff --git a/commands/interaction/context/transcribe.js b/commands/interaction/context/transcribe.js index 30e6e8a..48a6199 100644 --- a/commands/interaction/context/transcribe.js +++ b/commands/interaction/context/transcribe.js @@ -1,11 +1,13 @@ const { AudioTranscribe } = require('#obelisk'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { editOrReply } = require('#utils/message'); const { codeblock } = require('#utils/markdown'); const { STATICS } = require('#utils/statics'); -const { InteractionCallbackTypes, ApplicationCommandTypes, MessageFlags } = require("detritus-client/lib/constants");; +const { ApplicationCommandTypes, MessageFlags } = require("detritus-client/lib/constants"); +; module.exports = { name: 'Transcribe Voice Message', @@ -19,38 +21,38 @@ module.exports = { 1 ], run: async (context, args) => { - await context.respond({data: { flags: MessageFlags.EPHEMERAL }, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context); - try { - const { message } = args; + try { + const { message } = args; - if(!message.attachments.first()) return editOrReply(context, { - embeds: [createEmbed("warning", context, "No voice message found.")], - flags: MessageFlags.EPHEMERAL - }) - if(!message.attachments.first().url.split('?')[0].endsWith('voice-message.ogg')) return editOrReply(context, { - embeds: [createEmbed("warning", context, "No voice message found.")], - flags: MessageFlags.EPHEMERAL - }) - - const recog = await AudioTranscribe(context, message.attachments.first().url) - - return editOrReply(context, { - embeds: [createEmbed("default", context, { - description: codeblock("md", [ recog.response.body.transcript.substr(0,3900) ]), - footer: { - iconUrl: STATICS.google, - text: `Google Speech to Text • ${context.application.name}` - } - })], - flags: MessageFlags.EPHEMERAL - }) - - } catch (e) { - return editOrReply(context, { - embeds: [createEmbed("error", context, "Unable to transcribe message.")], - flags: MessageFlags.EPHEMERAL - }) - } + if (!message.attachments.first()) return editOrReply(context, { + embeds: [createEmbed("warning", context, "No voice message found.")], + flags: MessageFlags.EPHEMERAL + }) + if (!message.attachments.first().url.split('?')[0].endsWith('voice-message.ogg')) return editOrReply(context, { + embeds: [createEmbed("warning", context, "No voice message found.")], + flags: MessageFlags.EPHEMERAL + }) + + const recog = await AudioTranscribe(context, message.attachments.first().url) + + return editOrReply(context, { + embeds: [createEmbed("default", context, { + description: codeblock("md", [recog.response.body.transcript.substr(0, 3900)]), + footer: { + iconUrl: STATICS.google, + text: `Google Speech to Text • ${context.application.name}` + } + })], + flags: MessageFlags.EPHEMERAL + }) + + } catch (e) { + return editOrReply(context, { + embeds: [createEmbed("error", context, "Unable to transcribe message.")], + flags: MessageFlags.EPHEMERAL + }) + } }, }; \ No newline at end of file diff --git a/commands/interaction/slash/fun/otter.js b/commands/interaction/slash/fun/otter.js index 6fec94a..a40ebc6 100644 --- a/commands/interaction/slash/fun/otter.js +++ b/commands/interaction/slash/fun/otter.js @@ -1,9 +1,10 @@ const { otter } = require('#api'); -const { createEmbed } = require('#utils/embed') +const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { editOrReply } = require('#utils/message') -const { InteractionCallbackTypes } = require("detritus-client/lib/constants"); +const { ApplicationCommandOptionTypes } = require("detritus-client/lib/constants"); module.exports = { description: 'Shows a random otter picture.', @@ -16,8 +17,17 @@ module.exports = { integrationTypes: [ 1 ], - run: async (context) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + options: [ + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false + } + ], + run: async (context, args) => { + await acknowledge(context, args.incognito); try{ const ott = (await otter()).response.body diff --git a/commands/interaction/slash/info/avatar.js b/commands/interaction/slash/info/avatar.js index 7c259e4..fc67758 100644 --- a/commands/interaction/slash/info/avatar.js +++ b/commands/interaction/slash/info/avatar.js @@ -1,7 +1,8 @@ const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { editOrReply } = require('#utils/message'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require("detritus-client/lib/constants"); +const { ApplicationCommandOptionTypes } = require("detritus-client/lib/constants"); module.exports = { description: 'Get someones avatar.', @@ -20,10 +21,17 @@ module.exports = { description: 'User to get the avatar from.', type: ApplicationCommandOptionTypes.USER, required: false + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); if(!args.user) return editOrReply(context, createEmbed("default", context, { image: { diff --git a/commands/interaction/slash/info/user.js b/commands/interaction/slash/info/user.js index 058243e..1bf5ee0 100644 --- a/commands/interaction/slash/info/user.js +++ b/commands/interaction/slash/info/user.js @@ -1,11 +1,12 @@ const { BADGE_ICONS } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { smallIconPill, highlight, smallPill, icon, timestamp } = require('#utils/markdown'); const { editOrReply } = require('#utils/message'); const { renderBadges } = require('#utils/users'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes, UserFlags } = require("detritus-client/lib/constants"); +const { ApplicationCommandOptionTypes, UserFlags } = require("detritus-client/lib/constants"); module.exports = { description: 'Displays information about a user', @@ -24,12 +25,19 @@ module.exports = { description: 'The User.', type: ApplicationCommandOptionTypes.USER, required: false + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - try{ - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); + try{ const { user, member } = args; let u = user; diff --git a/commands/interaction/slash/search/google-images.js b/commands/interaction/slash/search/google-images.js index a2ddc3f..29c1518 100644 --- a/commands/interaction/slash/search/google-images.js +++ b/commands/interaction/slash/search/google-images.js @@ -1,11 +1,12 @@ const { googleImages } = require('#api'); const { paginator } = require('#client'); -const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed') +const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { editOrReply } = require('#utils/message') const { STATICS } = require('#utils/statics') -const { ApplicationCommandOptionTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); // TODO: create a favicon() util function createImageResultPage(context, result) { @@ -46,10 +47,17 @@ module.exports = { description: 'Image search query.', type: ApplicationCommandOptionTypes.TEXT, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); try { let search = await googleImages(context, args.query, false) //safesearch is always on diff --git a/commands/interaction/slash/search/google.js b/commands/interaction/slash/search/google.js index 6651066..e5a2d8b 100644 --- a/commands/interaction/slash/search/google.js +++ b/commands/interaction/slash/search/google.js @@ -1,12 +1,13 @@ const { google } = require('#api'); const { paginator } = require('#client'); -const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed') +const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { link, citation } = require('#utils/markdown') const { editOrReply } = require('#utils/message') const { STATICS } = require('#utils/statics') -const { ApplicationCommandOptionTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); // TODO: create a favicon() util function createSearchResultPage(context, result){ @@ -71,10 +72,17 @@ module.exports = { description: 'Google search query.', type: ApplicationCommandOptionTypes.TEXT, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); try{ let search = await google(context, args.query, false) // safe search is always on diff --git a/commands/interaction/slash/search/lyrics.js b/commands/interaction/slash/search/lyrics.js index 16b66cc..92194f6 100644 --- a/commands/interaction/slash/search/lyrics.js +++ b/commands/interaction/slash/search/lyrics.js @@ -1,12 +1,13 @@ const { lyrics } = require('#api'); const { paginator } = require('#client'); -const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed') +const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { smallIconPill } = require('#utils/markdown'); const { editOrReply } = require('#utils/message') const { STATICS } = require('#utils/statics') -const { ApplicationCommandOptionTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); const META_FIELDS = { "Album": "stat_videos", @@ -56,10 +57,17 @@ module.exports = { description: 'Song name or partial lyrics.', type: ApplicationCommandOptionTypes.TEXT, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); try{ let search = await lyrics(context, args.query) diff --git a/commands/interaction/slash/search/wolfram-alpha.js b/commands/interaction/slash/search/wolfram-alpha.js index cf3be95..c5b22c7 100644 --- a/commands/interaction/slash/search/wolfram-alpha.js +++ b/commands/interaction/slash/search/wolfram-alpha.js @@ -1,12 +1,13 @@ const { wolframAlpha } = require('#api'); const { paginator } = require('#client'); -const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed') +const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { citation } = require('#utils/markdown'); const { editOrReply } = require('#utils/message') const { STATICS } = require('#utils/statics') -const { ApplicationCommandOptionTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); function createWolframPage(context, pod, query, sources) { let res = page(createEmbed("default", context, { @@ -56,10 +57,17 @@ module.exports = { description: 'Computational Query.', type: ApplicationCommandOptionTypes.TEXT, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); try { let search = await wolframAlpha(context, args.query) diff --git a/commands/interaction/slash/search/xkcd.js b/commands/interaction/slash/search/xkcd.js index a578610..983ff19 100644 --- a/commands/interaction/slash/search/xkcd.js +++ b/commands/interaction/slash/search/xkcd.js @@ -1,9 +1,10 @@ const { paginator } = require('#client'); -const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed') +const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { editOrReply } = require('#utils/message') -const { ApplicationCommandOptionTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); const superagent = require('superagent') @@ -24,10 +25,17 @@ module.exports = { description: 'Search query, can be a title, words from the comic, etc.', type: ApplicationCommandOptionTypes.TEXT, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); if(!isNaN(parseInt(args.query))){ try{ diff --git a/commands/interaction/slash/search/youtube.js b/commands/interaction/slash/search/youtube.js index 4f43050..1e48d34 100644 --- a/commands/interaction/slash/search/youtube.js +++ b/commands/interaction/slash/search/youtube.js @@ -2,11 +2,14 @@ const { youtube } = require('#api'); const { paginator } = require('#client'); const { YOUTUBE_CATEGORIES } = require('#constants'); -const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed') +const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { link, iconPill } = require('#utils/markdown') const { editOrReply } = require('#utils/message') const { STATICS } = require('#utils/statics') +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); + // TODO: Move this to a numbers utility // https://www.html-code-generator.com/javascript/shorten-long-numbers const intToString = num => { @@ -106,8 +109,6 @@ function createYoutubePage(context, result){ return res; } -const { ApplicationCommandOptionTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants'); - module.exports = { name: 'youtube', description: 'Search for videos on YouTube.', @@ -126,8 +127,12 @@ module.exports = { type: ApplicationCommandOptionTypes.STRING, required: true }, - {name: 'type', default: 'all', type: 'string', help: `Video Category`}, - + { + name: 'type', + default: 'all', + type: 'string', + help: `Video Category` + }, { name: 'type', description: 'Type of videos to search.', @@ -166,10 +171,17 @@ module.exports = { name: "News" }, ] + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); try{ if(!args.type) args.type="all" diff --git a/commands/interaction/slash/utils/dictionary.js b/commands/interaction/slash/utils/dictionary.js index 3f1b849..bf3b217 100644 --- a/commands/interaction/slash/utils/dictionary.js +++ b/commands/interaction/slash/utils/dictionary.js @@ -2,11 +2,12 @@ const { dictionary } = require('#api'); const { paginator } = require('#client'); const { TRANSLATE_LANGUAGE_MAPPINGS, DICTIONARY_LANGUAGES } = require('#constants'); -const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed') +const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { link, iconPill, smallPill, icon, iconLinkPill, pill } = require('#utils/markdown') const { editOrReply } = require('#utils/message') -const { ApplicationCommandOptionTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); const LABELS = { "offensive": `${iconPill("warning", "Offensive")}` @@ -65,10 +66,17 @@ module.exports = { description: 'Term to look up.', type: ApplicationCommandOptionTypes.TEXT, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); try{ let search = await dictionary(context, args.term, "en") diff --git a/commands/interaction/slash/utils/emoji.js b/commands/interaction/slash/utils/emoji.js index 7fd2f93..765d99d 100644 --- a/commands/interaction/slash/utils/emoji.js +++ b/commands/interaction/slash/utils/emoji.js @@ -1,6 +1,7 @@ const { emojipedia, emojiKitchen } = require("#api"); const { createEmbed } = require("#utils/embed"); +const { acknowledge } = require("#utils/interactions"); const { icon, pill, iconPill, highlight, timestamp } = require("#utils/markdown"); const { editOrReply } = require("#utils/message"); const { STATICS } = require("#utils/statics"); @@ -8,7 +9,7 @@ const { STATICS } = require("#utils/statics"); const { ingest } = require("#logging"); const { Utils } = require("detritus-client"); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require("detritus-client/lib/constants"); +const { InteractionCallbackTypes, ApplicationCommandOptionTypes, DiscordRegexNames } = require("detritus-client/lib/constants"); const { Components, Snowflake } = require("detritus-client/lib/utils"); const onlyEmoji = require('emoji-aware').onlyEmoji; @@ -53,13 +54,20 @@ module.exports = { description: 'Emoji to enlarge. Use two built-in emoji to mix them.', type: ApplicationCommandOptionTypes.TEXT, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); const { matches } = Utils.regex( - Constants.DiscordRegexNames.EMOJI, + DiscordRegexNames.EMOJI, args.emoji ); embeds = [] diff --git a/commands/interaction/slash/utils/emojiinfo.js b/commands/interaction/slash/utils/emojiinfo.js index 6594ec1..ba101c1 100644 --- a/commands/interaction/slash/utils/emojiinfo.js +++ b/commands/interaction/slash/utils/emojiinfo.js @@ -7,6 +7,7 @@ const { STATICS } = require("#utils/statics"); const { Components } = require("detritus-client/lib/utils"); const { InteractionCallbackTypes, MessageComponentButtonStyles, ApplicationCommandOptionTypes } = require("detritus-client/lib/constants"); +const { acknowledge } = require("#utils/interactions"); const onlyEmoji = require('emoji-aware').onlyEmoji; @@ -48,10 +49,17 @@ module.exports = { description: 'Emoji to enlarge. Use two built-in emoji to mix them.', type: ApplicationCommandOptionTypes.TEXT, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); const emoji = onlyEmoji(args.emoji) if(!emoji){ diff --git a/commands/interaction/slash/utils/screenshot.js b/commands/interaction/slash/utils/screenshot.js index e9f1363..3d26659 100644 --- a/commands/interaction/slash/utils/screenshot.js +++ b/commands/interaction/slash/utils/screenshot.js @@ -1,9 +1,10 @@ const { WebUtilsWebPageScreenshot} = require("#obelisk"); const { createEmbed } = require("#utils/embed"); +const { acknowledge } = require("#utils/interactions"); const { editOrReply } = require("#utils/message"); -const { ApplicationCommandOptionTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); module.exports = { name: 'screenshot', @@ -22,10 +23,17 @@ module.exports = { description: 'Website URL.', type: ApplicationCommandOptionTypes.TEXT, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); await editOrReply(context, createEmbed("loading", context, `Creating website screenshot...`)) diff --git a/commands/interaction/slash/utils/weather.js b/commands/interaction/slash/utils/weather.js index 0990618..e159db2 100644 --- a/commands/interaction/slash/utils/weather.js +++ b/commands/interaction/slash/utils/weather.js @@ -1,11 +1,12 @@ const { darksky } = require('#api'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { pill, iconPill, smallPill, weatherIcon, timestamp } = require('#utils/markdown'); const { editOrReply } = require('#utils/message'); const { STATICS } = require('#utils/statics'); -const { ApplicationCommandOptionTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); module.exports = { name: 'weather', @@ -24,10 +25,17 @@ module.exports = { description: 'City or place to check.', type: ApplicationCommandOptionTypes.TEXT, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + await acknowledge(context, args.incognito); try{ let data = await darksky(context, args.location) diff --git a/commands/interaction/subcommands/tts/imtranslator.js b/commands/interaction/subcommands/tts/imtranslator.js index 558be22..0546908 100644 --- a/commands/interaction/subcommands/tts/imtranslator.js +++ b/commands/interaction/subcommands/tts/imtranslator.js @@ -2,9 +2,10 @@ const { imtranslator } = require('#api'); const { IMTRANSLATOR_VOICES } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); module.exports = { description: 'Text to Speech with imtranslator voices', @@ -23,12 +24,19 @@ module.exports = { type: ApplicationCommandOptionTypes.STRING, required: true, maxLength: 256 + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); try{ let s = Date.now() - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) let audio = await imtranslator(context, args.text, args.voice) let diff = (Date.now() - s) await context.editOrRespond({ diff --git a/commands/interaction/subcommands/tts/microsoft.js b/commands/interaction/subcommands/tts/microsoft.js index 9fcb4b6..a7e9a6e 100644 --- a/commands/interaction/subcommands/tts/microsoft.js +++ b/commands/interaction/subcommands/tts/microsoft.js @@ -2,9 +2,10 @@ const { sapi4 } = require('#api'); const { MICROSOFT_VOICES, MICROSOFT_VOICE_CONFIG } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); module.exports = { description: 'Text to Speech with microsoft voices', @@ -23,11 +24,18 @@ module.exports = { type: ApplicationCommandOptionTypes.STRING, required: true, maxLength: 256 + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); try{ - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) let audio = await sapi4(context, args.text, args.voice, MICROSOFT_VOICE_CONFIG[args.voice].pitch, MICROSOFT_VOICE_CONFIG[args.voice].speed) await context.editOrRespond({ embeds: [createEmbed("defaultNoFooter", context, { description: `${icon("audio")} Audio Generated in ${highlight(audio.timings + "s")}.` })], diff --git a/commands/interaction/subcommands/tts/moonbase.js b/commands/interaction/subcommands/tts/moonbase.js index d82f9d6..042e241 100644 --- a/commands/interaction/subcommands/tts/moonbase.js +++ b/commands/interaction/subcommands/tts/moonbase.js @@ -1,9 +1,10 @@ const { moonbase } = require('#api'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); module.exports = { description: 'Moonbase Alpha text to speech voices', @@ -16,12 +17,18 @@ module.exports = { type: ApplicationCommandOptionTypes.STRING, required: true, maxLength: 1024 + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - let audio = await moonbase(context, args.text, args.voice) await context.editOrRespond({ diff --git a/commands/interaction/subcommands/tts/playht.js b/commands/interaction/subcommands/tts/playht.js index 0bb856c..b433a82 100644 --- a/commands/interaction/subcommands/tts/playht.js +++ b/commands/interaction/subcommands/tts/playht.js @@ -2,9 +2,10 @@ const { playht } = require('#api'); const { PLAYHT_VOICES } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); module.exports = { description: 'Text to Speech with playht voices', @@ -23,11 +24,18 @@ module.exports = { type: ApplicationCommandOptionTypes.STRING, required: true, maxLength: 256 + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); try{ - await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) let audio = await playht(context, args.text, args.voice) await context.editOrRespond({ diff --git a/commands/interaction/subcommands/tts/tiktok/character.js b/commands/interaction/subcommands/tts/tiktok/character.js index b4de5cf..2306191 100644 --- a/commands/interaction/subcommands/tts/tiktok/character.js +++ b/commands/interaction/subcommands/tts/tiktok/character.js @@ -2,9 +2,10 @@ const { tiktok } = require('#api'); const { TIKTOK_VOICES_CHARACTERS } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); let voices = [] for(const k of Object.keys(TIKTOK_VOICES_CHARACTERS)) voices.unshift({ @@ -28,12 +29,19 @@ module.exports = { description: 'Voice to use', choices: voices, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); + try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - if(args.text.length >= 101) return await context.editOrRespond({ embeds: [createEmbed("warning", context, "Text too long (must be 100 or shorter).")] }) diff --git a/commands/interaction/subcommands/tts/tiktok/french.js b/commands/interaction/subcommands/tts/tiktok/french.js index 96e3bcd..c2da8b4 100644 --- a/commands/interaction/subcommands/tts/tiktok/french.js +++ b/commands/interaction/subcommands/tts/tiktok/french.js @@ -2,9 +2,10 @@ const { tiktok } = require('#api'); const { TIKTOK_VOICES_FRENCH } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); let voices = [] for(const k of Object.keys(TIKTOK_VOICES_FRENCH)) voices.unshift({ @@ -28,12 +29,19 @@ module.exports = { description: 'Voice to use', choices: voices, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); + try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - if(args.text.length >= 101) return await context.editOrRespond({ embeds: [createEmbed("warning", context, "Text too long (must be 100 or shorter).")] }) diff --git a/commands/interaction/subcommands/tts/tiktok/german.js b/commands/interaction/subcommands/tts/tiktok/german.js index 25dc523..105fa6c 100644 --- a/commands/interaction/subcommands/tts/tiktok/german.js +++ b/commands/interaction/subcommands/tts/tiktok/german.js @@ -2,9 +2,10 @@ const { tiktok } = require('#api'); const { TIKTOK_VOICES_GERMAN } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); let voices = [] for(const k of Object.keys(TIKTOK_VOICES_GERMAN)) voices.unshift({ @@ -28,12 +29,19 @@ module.exports = { description: 'Voice to use', choices: voices, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); + try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - if(args.text.length >= 101) return await context.editOrRespond({ embeds: [createEmbed("warning", context, "Text too long (must be 100 or shorter).")] }) diff --git a/commands/interaction/subcommands/tts/tiktok/indonesian.js b/commands/interaction/subcommands/tts/tiktok/indonesian.js index 2617d4b..578392e 100644 --- a/commands/interaction/subcommands/tts/tiktok/indonesian.js +++ b/commands/interaction/subcommands/tts/tiktok/indonesian.js @@ -2,9 +2,10 @@ const { tiktok } = require('#api'); const { TIKTOK_VOICES_INDONESIAN } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); let voices = [] for(const k of Object.keys(TIKTOK_VOICES_INDONESIAN)) voices.unshift({ @@ -28,12 +29,19 @@ module.exports = { description: 'Voice to use', choices: voices, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); + try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - if(args.text.length >= 101) return await context.editOrRespond({ embeds: [createEmbed("warning", context, "Text too long (must be 100 or shorter).")] }) diff --git a/commands/interaction/subcommands/tts/tiktok/italian.js b/commands/interaction/subcommands/tts/tiktok/italian.js index 1cd9b98..bfcc30c 100644 --- a/commands/interaction/subcommands/tts/tiktok/italian.js +++ b/commands/interaction/subcommands/tts/tiktok/italian.js @@ -2,9 +2,10 @@ const { tiktok } = require('#api'); const { TIKTOK_VOICES_ITALIAN } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); let voices = [] for(const k of Object.keys(TIKTOK_VOICES_ITALIAN)) voices.unshift({ @@ -28,12 +29,19 @@ module.exports = { description: 'Voice to use', choices: voices, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); + try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - if(args.text.length >= 101) return await context.editOrRespond({ embeds: [createEmbed("warning", context, "Text too long (must be 100 or shorter).")] }) diff --git a/commands/interaction/subcommands/tts/tiktok/japanese.js b/commands/interaction/subcommands/tts/tiktok/japanese.js index 9f1b07a..0fbac8e 100644 --- a/commands/interaction/subcommands/tts/tiktok/japanese.js +++ b/commands/interaction/subcommands/tts/tiktok/japanese.js @@ -2,9 +2,10 @@ const { tiktok } = require('#api'); const { TIKTOK_VOICES_JAPANESE } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); let voices = [] for(const k of Object.keys(TIKTOK_VOICES_JAPANESE)) voices.unshift({ @@ -28,12 +29,19 @@ module.exports = { description: 'Voice to use', choices: voices, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); + try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - if(args.text.length >= 101) return await context.editOrRespond({ embeds: [createEmbed("warning", context, "Text too long (must be 100 or shorter).")] }) diff --git a/commands/interaction/subcommands/tts/tiktok/korean.js b/commands/interaction/subcommands/tts/tiktok/korean.js index 04def2d..f5a36d7 100644 --- a/commands/interaction/subcommands/tts/tiktok/korean.js +++ b/commands/interaction/subcommands/tts/tiktok/korean.js @@ -2,9 +2,10 @@ const { tiktok } = require('#api'); const { TIKTOK_VOICES_KOREAN } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); let voices = [] for(const k of Object.keys(TIKTOK_VOICES_KOREAN)) voices.unshift({ @@ -28,12 +29,19 @@ module.exports = { description: 'Voice to use', choices: voices, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); + try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - if(args.text.length >= 101) return await context.editOrRespond({ embeds: [createEmbed("warning", context, "Text too long (must be 100 or shorter).")] }) diff --git a/commands/interaction/subcommands/tts/tiktok/pop-culture.js b/commands/interaction/subcommands/tts/tiktok/pop-culture.js index 90d04c6..5778746 100644 --- a/commands/interaction/subcommands/tts/tiktok/pop-culture.js +++ b/commands/interaction/subcommands/tts/tiktok/pop-culture.js @@ -2,9 +2,10 @@ const { tiktok } = require('#api'); const { TIKTOK_VOICES_POP_CULTURE } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); let voices = [] for(const k of Object.keys(TIKTOK_VOICES_POP_CULTURE)) voices.unshift({ @@ -28,12 +29,19 @@ module.exports = { description: 'Voice to use', choices: voices, required: true, + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); + try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - if(args.text.length >= 101) return await context.editOrRespond({ embeds: [createEmbed("warning", context, "Text too long (must be 100 or shorter).")] }) diff --git a/commands/interaction/subcommands/tts/tiktok/portugese.js b/commands/interaction/subcommands/tts/tiktok/portugese.js index 39503bd..c59b93c 100644 --- a/commands/interaction/subcommands/tts/tiktok/portugese.js +++ b/commands/interaction/subcommands/tts/tiktok/portugese.js @@ -2,9 +2,10 @@ const { tiktok } = require('#api'); const { TIKTOK_VOICES_PORTUGESE } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); let voices = [] for(const k of Object.keys(TIKTOK_VOICES_PORTUGESE)) voices.unshift({ @@ -28,12 +29,19 @@ module.exports = { description: 'Voice to use', choices: voices, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); + try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - if(args.text.length >= 101) return await context.editOrRespond({ embeds: [createEmbed("warning", context, "Text too long (must be 100 or shorter).")] }) diff --git a/commands/interaction/subcommands/tts/tiktok/song.js b/commands/interaction/subcommands/tts/tiktok/song.js index ce642e4..1202a32 100644 --- a/commands/interaction/subcommands/tts/tiktok/song.js +++ b/commands/interaction/subcommands/tts/tiktok/song.js @@ -2,9 +2,10 @@ const { tiktok } = require('#api'); const { TIKTOK_VOICES_SONG } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); let voices = [] for(const k of Object.keys(TIKTOK_VOICES_SONG)) voices.unshift({ @@ -28,12 +29,18 @@ module.exports = { description: 'Voice to use', choices: voices, required: true, + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - if(args.text.length >= 101) return await context.editOrRespond({ embeds: [createEmbed("warning", context, "Text too long (must be 100 or shorter).")] }) diff --git a/commands/interaction/subcommands/tts/tiktok/spanish.js b/commands/interaction/subcommands/tts/tiktok/spanish.js index 10bc511..6d60553 100644 --- a/commands/interaction/subcommands/tts/tiktok/spanish.js +++ b/commands/interaction/subcommands/tts/tiktok/spanish.js @@ -2,9 +2,10 @@ const { tiktok } = require('#api'); const { TIKTOK_VOICES_SPANISH } = require('#constants'); const { createEmbed } = require('#utils/embed'); +const { acknowledge } = require('#utils/interactions'); const { icon, highlight } = require('#utils/markdown'); -const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); +const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants'); let voices = [] for(const k of Object.keys(TIKTOK_VOICES_SPANISH)) voices.unshift({ @@ -28,12 +29,18 @@ module.exports = { description: 'Voice to use', choices: voices, required: true + }, + { + name: 'incognito', + description: 'Makes the response only visible to you.', + type: ApplicationCommandOptionTypes.BOOLEAN, + required: false, + default: false } ], run: async (context, args) => { + await acknowledge(context, args.incognito); try { - await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) - if(args.text.length >= 101) return await context.editOrRespond({ embeds: [createEmbed("warning", context, "Text too long (must be 100 or shorter).")] }) diff --git a/labscore/utils/interactions.js b/labscore/utils/interactions.js new file mode 100644 index 0000000..d42bcfc --- /dev/null +++ b/labscore/utils/interactions.js @@ -0,0 +1,23 @@ +const { MessageFlags, InteractionCallbackTypes } = require("detritus-client/lib/constants") + +const { Context } = require("detritus-client/lib/command") +const { InteractionContext } = require("detritus-client/lib/interaction") + +/** + * Acknowledges a command or interaction. + * @param { InteractionContext|Context } context Command/interaction context + * @param { boolean } incognito Specifies if the interaction should run privately (only applicable for interactions) + */ +module.exports.acknowledge = async function(context, incognito = false){ + // Interaction flow + if(context.editOrRespond){ + if(incognito){ + if(!context._meta) context._meta = {}; + context._meta.isIncognito = true; + return await context.respond({data: { flags: MessageFlags.EPHEMERAL }, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}); + } + return await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + } + // Command Flow + return await context.triggerTyping() +} \ No newline at end of file diff --git a/labscore/utils/message.js b/labscore/utils/message.js index 8f5d1a6..e10a5c9 100644 --- a/labscore/utils/message.js +++ b/labscore/utils/message.js @@ -1,4 +1,4 @@ -const { Permissions } = require("detritus-client/lib/constants") +const { Permissions, MessageFlags } = require("detritus-client/lib/constants") const { basecamp } = require("../logging") const { createEmbed } = require("./embed") @@ -10,6 +10,15 @@ module.exports.editOrReply = function(context, message, disableReference = false // Disable mentions if(!message.allowedMentions) message.allowedMentions = {parse: [], repliedUser: false} + let flags = 0; + + // Special labsCore context clues for the command. + // Currently only used to identify incognito requests + // on user slash commands. + if(context._meta){ + if(context._meta.isIncognito) flags = MessageFlags.EPHEMERAL + } + // you can figure out what this does on your own time message.nonce = Math.floor(Math.random() * 9999 + 1000) @@ -32,7 +41,8 @@ module.exports.editOrReply = function(context, message, disableReference = false allowedMentions: { parse: [], repliedUser: false }, embeds: [ embedResponse - ] + ], + flags }) }catch(e){ /*