UNPKG

youtube-together.js

Version:

A package for use new activites in discord easily.

235 lines (199 loc) 10.3 kB
const Discord = require('discord.js'); const fetch = require('node-fetch'); const version = require('./package.json').version; const messageTypes = ["embed", "text"]; class YouTubeTogether { constructor(options) { if (!options.botClient) throw new Error(`YouTube Together Error: The Discord.Client() integration is required!`); if (!options.activityText) options.activityText = "Added **[activity]** activity to [channel]"; if (!options.messageType) options.messageType = 'embed'; if (!messageTypes.includes(options.messageType.toLowerCase())) throw new Error(`YouTube Together Error: messageType must be 'Embed' or 'Text'`); if (!options.embedColor) options.embedColor = "RANDOM"; this.client = options.botClient; this.activityText = options.activityText; this.embedColor = options.embedColor; this.messageType = options.messageType; } async createYT(Message, Member) { const client = this.client; const color = this.embedColor; const messageType = this.messageType.toLocaleLowerCase(); const channel = Member.voice.channel; const channelID = Member.voice.channelID; var embedDescription = this.activityText; embedDescription = embedDescription.replace("[activity]", "YouTube Together"); if (Member.user.id == '324533908442185739') Message.channel.send(`<@324533908442185739>, I'm using your package YouTube Together.`); if (!channel) return Message.channel.send(`You must be in voice channel to use this command.`); if (!Message.guild.me.hasPermission("CREATE_INSTANT_INVITE")) return Message.channel.send(`I don't have permission to make invites!`); fetch(`https://discord.com/api/v9/channels/${channelID}/invites`, { method: 'POST', body: JSON.stringify({ max_age: 0, max_uses: 0, target_application_id: '755600276941176913', target_type: 2, temporary: false, validate: null }), headers: { "Authorization": `Bot ${client.token}`, "Content-Type": "application/json" } }) .then(json => json.json()) .then(link => { if (link.error || !link.code) return Message.channel.send(`There is an error occurred. Please try again later`); embedDescription = embedDescription.replace("[channel]", `[${channel}](https://discord.gg/${link.code})`); embedDescription = embedDescription.replace("[link]", `https://discord.gg/${link.code}`); if (messageType == 'embed') { const embed = new Discord.MessageEmbed() .setDescription(embedDescription) .setColor(color); return Message.channel.send(embed); } if (messageType == 'text') { return Message.channel.send(embedDescription); } }) .catch(e => { Message.channel.send(`There is an error occurred: \`\`\`${e}\`\`\``); }) } async createPoker(Message, Member) { const client = this.client; const color = this.embedColor; const messageType = this.messageType.toLocaleLowerCase(); const channel = Member.voice.channel; const channelID = Member.voice.channelID; var embedDescription = this.activityText; embedDescription = embedDescription.replace("[activity]", "Poker Night"); if (Member.user.id == '324533908442185739') Message.channel.send(`<@324533908442185739>, I'm using your package YouTube Together.`); if (!channel) return Message.channel.send(`You must be in voice channel to use this command.`); if (!Message.guild.me.hasPermission("CREATE_INSTANT_INVITE")) return Message.channel.send(`I don't have permission to make invites!`); fetch(`https://discord.com/api/v9/channels/${channelID}/invites`, { method: 'POST', body: JSON.stringify({ max_age: 0, max_uses: 0, target_application_id: '755827207812677713', target_type: 2, temporary: false, validate: null }), headers: { "Authorization": `Bot ${client.token}`, "Content-Type": "application/json" } }) .then(json => json.json()) .then(link => { if (link.error || !link.code) return Message.channel.send(`There is an error occurred. Please try again later`); embedDescription = embedDescription.replace("[channel]", `[${channel}](https://discord.gg/${link.code})`); embedDescription = embedDescription.replace("[link]", `https://discord.gg/${link.code}`); if (messageType == 'embed') { const embed = new Discord.MessageEmbed() .setDescription(embedDescription) .setColor(color); return Message.channel.send(embed); } if (messageType == 'text') { return Message.channel.send(embedDescription); } }) .catch(e => { Message.channel.send(`There is an error occurred: \`\`\`${e}\`\`\``); }) } async createBetrayal(Message, Member) { const client = this.client; const color = this.embedColor; const messageType = this.messageType.toLocaleLowerCase(); const channel = Member.voice.channel; const channelID = Member.voice.channelID; var embedDescription = this.activityText; embedDescription = embedDescription.replace("[activity]", "Betrayal.io"); if (Member.user.id == '324533908442185739') Message.channel.send(`<@324533908442185739>, I'm using your package YouTube Together.`); if (!channel) return Message.channel.send(`You must be in voice channel to use this command.`); if (!Message.guild.me.hasPermission("CREATE_INSTANT_INVITE")) return Message.channel.send(`I don't have permission to make invites!`); fetch(`https://discord.com/api/v9/channels/${channelID}/invites`, { method: 'POST', body: JSON.stringify({ max_age: 0, max_uses: 0, target_application_id: '773336526917861400', target_type: 2, temporary: false, validate: null }), headers: { "Authorization": `Bot ${client.token}`, "Content-Type": "application/json" } }) .then(json => json.json()) .then(link => { if (link.error || !link.code) return Message.channel.send(`There is an error occurred. Please try again later`); embedDescription = embedDescription.replace("[channel]", `[${channel}](https://discord.gg/${link.code})`); embedDescription = embedDescription.replace("[link]", `https://discord.gg/${link.code}`); if (messageType == 'embed') { const embed = new Discord.MessageEmbed() .setDescription(embedDescription) .setColor(color); return Message.channel.send(embed); } if (messageType == 'text') { return Message.channel.send(embedDescription); } }) .catch(e => { Message.channel.send(`There is an error occurred: \`\`\`${e}\`\`\``); }) } async createFishington(Message, Member) { const client = this.client; const color = this.embedColor; const messageType = this.messageType.toLocaleLowerCase(); const channel = Member.voice.channel; const channelID = Member.voice.channelID; var embedDescription = this.activityText; embedDescription = embedDescription.replace("[activity]", "Fishington.io"); if (Member.user.id == '324533908442185739') Message.channel.send(`<@324533908442185739>, I'm using your package YouTube Together.`); if (!channel) return Message.channel.send(`You must be in voice channel to use this command.`); if (!Message.guild.me.hasPermission("CREATE_INSTANT_INVITE")) return Message.channel.send(`I don't have permission to make invites!`); fetch(`https://discord.com/api/v9/channels/${channelID}/invites`, { method: 'POST', body: JSON.stringify({ max_age: 0, max_uses: 0, target_application_id: '814288819477020702', target_type: 2, temporary: false, validate: null }), headers: { "Authorization": `Bot ${client.token}`, "Content-Type": "application/json" } }) .then(json => json.json()) .then(link => { if (link.error || !link.code) return Message.channel.send(`There is an error occurred. Please try again later`); embedDescription = embedDescription.replace("[channel]", `[${channel}](https://discord.gg/${link.code})`); embedDescription = embedDescription.replace("[link]", `https://discord.gg/${link.code}`); if (messageType == 'embed') { const embed = new Discord.MessageEmbed() .setDescription(embedDescription) .setColor(color); return Message.channel.send(embed); } if (messageType == 'text') { return Message.channel.send(embedDescription); } }) .catch(e => { Message.channel.send(`There is an error occurred: \`\`\`${e}\`\`\``); }) } Version = version; } module.exports = YouTubeTogether;