From 942b524cb772d81ef0a96caca45ad23c39937476 Mon Sep 17 00:00:00 2001 From: Kiera Affarantia Date: Sat, 5 Oct 2024 11:06:58 +0700 Subject: [PATCH 1/4] idk what is this lols --- src/commands/utility/subscribe.js | 123 ++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/commands/utility/subscribe.js diff --git a/src/commands/utility/subscribe.js b/src/commands/utility/subscribe.js new file mode 100644 index 0000000..308fb13 --- /dev/null +++ b/src/commands/utility/subscribe.js @@ -0,0 +1,123 @@ +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); From fe834dc23d0bb1d9c89236fe11bf5ae2aa0515b9 Mon Sep 17 00:00:00 2001 From: Kiera Affarantia Date: Sun, 3 Nov 2024 11:52:09 +0700 Subject: [PATCH 2/4] 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); From c833b2e211e5874067ee80bedc09860b1309e9a7 Mon Sep 17 00:00:00 2001 From: Kiera Affarantia Date: Sun, 3 Nov 2024 11:53:54 +0700 Subject: [PATCH 3/4] Update nodes.js --- src/commands/utility/nodes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/utility/nodes.js b/src/commands/utility/nodes.js index fac688c..4fbc779 100644 --- a/src/commands/utility/nodes.js +++ b/src/commands/utility/nodes.js @@ -6,7 +6,7 @@ const { byteUnit } = require('@root/src/helpers/Units'); module.exports = { name: "nodes", - description: "Lists lavalink nodes", + description: "Lists Audio nodes", category: "UTILITY", command: { enabled: true, @@ -64,7 +64,7 @@ async function fetchNodesAndTurnItToTable(nodes) { })) return new EmbedBuilder({ - title: 'Lavalink Nodes', + title: 'Audio Nodes', color: 0x0088ff, fields: fields }) From 33e71babcb25c3e056bf479b38ec5c74835f1e6c Mon Sep 17 00:00:00 2001 From: Kiera Affarantia Date: Sun, 3 Nov 2024 11:55:57 +0700 Subject: [PATCH 4/4] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 588dec7..ab26202 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "TinashaBot", - "version": "5.6.0", + "version": "5.6.2", "description": "multipurpose discord bot built using discord-js", "main": "bot.js", "author": "Amane",