Delete subscribe.js

This commit is contained in:
Amane Serenetia 2024-11-03 11:52:09 +07:00
parent 942b524cb7
commit fe834dc23d

View File

@ -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: "<platform> <channel/user_id>",
},
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);