diff --git a/commands/Music/play.js b/commands/Music/play.js index 6af49b3..60b53a7 100644 --- a/commands/Music/play.js +++ b/commands/Music/play.js @@ -47,23 +47,8 @@ module.exports = { autoPlay: true }); - if (isYouTubeUrl(query)) { - const canDirect = await YoutubeDirectSchema.findOne({ - userId: interaction.user.id - }); - - if (!(canDirect && canDirect.userId && canDirect.userId == interaction.user.id)) return interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setColor(Colors.Red) - .setTitle(locale.getLocaleString("command.play.youtube.disabled")) - .setDescription(locale.getLocaleString("command.play.youtube.disabled.description")) - ] - }); - } - - if (user_source ? sources[user_source.source].require.includes("YOUTUBE_DIRECT") : false) { - const canDirect = await YoutubeDirectSchema.findOne({ + async function checkYoutubeDirect() { + const ytDirect = await YoutubeDirectSchema.findOne({ userId: interaction.user.id }); @@ -75,17 +60,46 @@ module.exports = { const adsActionRow = new ActionRowBuilder() .addComponents(adsButton); - if (!(canDirect && canDirect.userId && canDirect.userId == interaction.user.id)) return interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setColor(Colors.Red) - .setDescription(locale.getLocaleString("youtube.direct.disable.text")) - .setImage("https://cdn.jsdelivr.net/gh/HStudioDiscordBot/Storage@main/ads/HStudio.ads.youtube_direct_user.png") - ], - components: [ - adsActionRow - ] - }); + if (!ytDirect) { + await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setColor(Colors.Red) + .setDescription(locale.getLocaleString("youtube.direct.disable.text")) + .setImage("https://cdn.jsdelivr.net/gh/HStudioDiscordBot/Storage@main/ads/HStudio.ads.youtube_direct_user.png") + ], + components: [ + adsActionRow + ] + }); + return false; + } else if ((ytDirect.expireAt ? ytDirect.expireAt.getTime() < Date.now() : false) && !ytDirect.infinity) { + await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setColor(Colors.Red) + .setDescription(locale.getLocaleString("youtube.direct.disable.expired")) + ], + components: [ + adsActionRow + ] + }); + return false; + } else { + return true; + } + } + + if (isYouTubeUrl(query)) { + if (!(await checkYoutubeDirect())) { + return; + } + } + + if (user_source ? sources[user_source.source].require.includes("YOUTUBE_DIRECT") : false) { + if (!(await checkYoutubeDirect())) { + return; + } } if (isHStudioPlayUrl(query)) { diff --git a/locales/en-US.json b/locales/en-US.json index a69a4c6..d45cc73 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -121,5 +121,6 @@ "command.setting.search.save.fail": "❌ Fail to save default source with `{0}`", "youtube.direct.disable.text": "# Want to listen to music directly from YouTube?\nYou can easily order through the HStudio website\n\n**[Support Discord](https://discord.gg/GzTbuZHTEx)**", "youtube.direct.disable.button.text": "Buy now", + "youtube.direct.disable.expired": "# Youtube Directly is expired\nYou can't use this feature anymore\nYou can order through the Studio website", "interaction.client.notOnline": "❌ The bot is not online" } \ No newline at end of file diff --git a/schemas/YoutubeDirect.js b/schemas/YoutubeDirect.js index f28c83e..f4af98b 100644 --- a/schemas/YoutubeDirect.js +++ b/schemas/YoutubeDirect.js @@ -2,6 +2,15 @@ const { model, Schema } = require("mongoose"); module.exports = model("youtubeDirect", new Schema({ userId: String, + expireAt: { + type: Date, + required: false + }, + infinity: { + type: Boolean, + required: true, + default: false + }, }, { timestamps: true })); \ No newline at end of file