From fe834dc23d0bb1d9c89236fe11bf5ae2aa0515b9 Mon Sep 17 00:00:00 2001 From: Kiera Affarantia Date: Sun, 3 Nov 2024 11:52:09 +0700 Subject: [PATCH] Delete subscribe.js --- src/commands/utility/subscribe.js | 123 ------------------------------ 1 file changed, 123 deletions(-) delete mode 100644 src/commands/utility/subscribe.js diff --git a/src/commands/utility/subscribe.js b/src/commands/utility/subscribe.js deleted file mode 100644 index 308fb13..0000000 --- a/src/commands/utility/subscribe.js +++ /dev/null @@ -1,123 +0,0 @@ -const { EmbedBuilder, ApplicationCommandOptionType } = require("discord.js"); -const { MESSAGES, EMBED_COLORS } = require("@root/config"); -const fetch = require('node-fetch'); - -const subscriptions = new Map(); // Store subscriptions in memory (consider using the mongodb or maybe gonna use redis) - -/** - * @type {import("@structures/Command")} - */ -module.exports = { - name: "subscribe", - description: "Subscribe to YouTube or TikTok notifications.", - category: "UTILITY", - botPermissions: ["SendMessages"], - command: { - enabled: true, - usage: " ", - }, - slashCommand: { - enabled: true, - options: [ - { - name: "platform", - description: "The platform to subscribe to (youtube/tiktok)", - type: ApplicationCommandOptionType.String, - required: true, - choices: [ - { name: "YouTube", value: "youtube" }, - { name: "TikTok", value: "tiktok" }, - ], - }, - { - name: "channel_or_user_id", - description: "The YouTube channel ID or TikTok user ID", - type: ApplicationCommandOptionType.String, - required: true, - }, - ], - }, - - async messageRun(message, args) { - const platform = args[0].toLowerCase(); - const channelOrUserId = args[1]; - const response = await subscribe(message.channel, platform, channelOrUserId); - await message.safeReply(response); - }, - - async interactionRun(interaction) { - const platform = interaction.options.getString("platform"); - const channelOrUserId = interaction.options.getString("channel_or_user_id"); - const response = await subscribe(interaction.channel, platform, channelOrUserId); - await interaction.followUp(response); - }, -}; - -/** - * Subscribe to notifications for a specific platform and channel/user. - * @param {import("discord.js").TextChannel} channel - * @param {string} platform - * @param {string} channelOrUserId - */ -async function subscribe(channel, platform, channelOrUserId) { - const key = `${platform}:${channelOrUserId}`; - - if (subscriptions.has(key)) { - return "🚫 You are already subscribed to this channel/user."; - } - - subscriptions.set(key, channel.id); - return `✅ Successfully subscribed to ${platform} updates for ${channelOrUserId}.`; -} - -/** - * Function to check for updates (YouTube and TikTok) - * This function should be called periodically (e.g., using setInterval) - */ -async function checkForUpdates() { - for (const [key, channelId] of subscriptions.entries()) { - const [platform, id] = key.split(":"); - - let updateMessage = ""; - - if (platform === "youtube") { - const updates = await fetchYouTubeUpdates(id); - if (updates) { - updateMessage = `New YouTube update for ${id}: ${updates}`; - } - } else if (platform === "tiktok") { - const updates = await fetchTikTokUpdates(id); - if (updates) { - updateMessage = `New TikTok update for ${id}: ${updates}`; - } - } - - if (updateMessage) { - const channel = await channelId.fetch(); - channel.send(updateMessage); - } - } -} - -/** - * Fetch updates from YouTube (placeholder function) - * @param {string} channelId - */ -async function fetchYouTubeUpdates(channelId) { - // Implement your logic to fetch updates from YouTube - // Return the update message or null if no updates - return null; // Placeholder -} - -/** - * Fetch updates from TikTok (placeholder function) - * @param {string} userId - */ -async function fetchTikTokUpdates(userId) { - // Implement your logic to fetch updates from TikTok - // Return the update message or null if no updates - return null; // Placeholder -} - -// Set an interval to check for updates every 10 minutes (600000 ms) -setInterval(checkForUpdates, 600000);