Add files via upload

This commit is contained in:
Sophia Atkinson 2021-04-13 11:49:09 -07:00 committed by GitHub
parent cb6790de6a
commit 529b646d31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 960 additions and 0 deletions

29
commands/about.js Normal file
View File

@ -0,0 +1,29 @@
const { MessageEmbed } = require("discord.js");
module.exports = {
name: "about",
aliases: ["ab"],
description: "Info About Codsworth",
execute(message) {
let commands = message.client.commands.array();
let aboutEmbed = new MessageEmbed()
.setTitle("About Codsworth")
.setDescription(`Codsworth is a Mister Handy robotic butler for the Sole Survivor's family before the Great War. He was bought by the family not long before October 23, 2077, as evidenced by the Mr. Handy box in the laundry room of the Sole Survivor's home. He was not granted entry to Vault 111, as claimed by the Vault-Tec rep, and was left behind when the war was announced on television. Codsworth is reunited with the Survivor after 210 years of roaming around Sanctuary Hills, still loyal to his owner. At first, Codsworth seems cheerful and oblivious to what has happened. During the first ten years after the war, Codsworth tried to keep himself busy by doing futile housekeeping work, such as keeping the nuclear fallout-tainted floors waxed, dusting a collapsed house, and polishing a rusted car. However, talking to him further reveals that he is actually very depressed about the state of the world, and was deeply affected by his two-centuries-long isolation. To cope, he pretended that nothing happened. At some point after the bombs fell, Codsworth visited the town of Concord - mentioning that the locals only "pummeled him with sticks a few times" and "shot at him on a few occasions" before he retreated back to Sanctuary.`)
.setColor("#8C52FF")
.setImage("https://cdn.discordapp.com/attachments/766155499368087563/767873872186966076/Codsworth_model.png")
aboutEmbed.setFooter(`Info Taken From fallout.fandom.com`);
return message.channel.send(aboutEmbed).catch(console.error);
}
};
//Codsworth is a Mister Handy robotic butler for the Sole Survivor's family before the Great War. He was bought by the family not long before October 23, 2077, as evidenced by the Mr. Handy box in the laundry room of the Sole Survivor's home. He was not granted entry to Vault 111, as claimed by the Vault-Tec rep, and was left behind when the war was announced on television. Codsworth is reunited with the Survivor after 210 years of roaming around Sanctuary Hills, still loyal to his owner. At first, Codsworth seems cheerful and oblivious to what has happened. During the first ten years after the war, Codsworth tried to keep himself busy by doing futile housekeeping work, such as keeping the nuclear fallout-tainted floors waxed, dusting a collapsed house, and polishing a rusted car. However, talking to him further reveals that he is actually very depressed about the state of the world, and was deeply affected by his two-centuries-long isolation. To cope, he pretended that nothing happened. At some point after the bombs fell, Codsworth visited the town of Concord - mentioning that the locals only "pummeled him with sticks a few times" and "shot at him on a few occasions" before he retreated back to Sanctuary.

18
commands/disconnect.js Normal file
View File

@ -0,0 +1,18 @@
const { MessageEmbed } = require("discord.js");
const { Client, Collection } = require("discord.js");
module.exports = {
name: "disconnect",
aliases: ["leave"],
description: "disconnects from channel",
async execute(message, args) {
const { channel } = message.member.voice;
const serverQueue = message.client.queue.get(message.guild.id);
if (!channel) return message.reply("You need to join the voice channel before you can disconnect me!").catch(console.error);
await channel.leave();
return message.reply(`Codsworth Has Left Your Channel.`);
}
};

31
commands/help.js Normal file
View File

@ -0,0 +1,31 @@
const { MessageEmbed } = require("discord.js");
const { LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "help",
aliases: ["h"],
description: i18n.__("help.description"),
execute(message) {
let commands = message.client.commands.array();
let helpEmbed = new MessageEmbed()
.setTitle(i18n.__mf("help.embedTitle", { botname: message.client.user.username }))
.setDescription(i18n.__("help.embedDescription"))
.setColor("#8C52FF");
commands.forEach((cmd) => {
helpEmbed.addField(
`**${message.client.prefix}${cmd.name} ${cmd.aliases ? `(${cmd.aliases})` : ""}**`,
`${cmd.description}`,
true
);
});
helpEmbed.setFooter(`Made By Jim Sim#3076`);
return message.channel.send(helpEmbed).catch(console.error);
}
};

17
commands/invite.js Normal file
View File

@ -0,0 +1,17 @@
const { LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "invite",
description: i18n.__('invite.description'),
execute(message) {
return message.member
.send(
`https://discord.com/oauth2/authorize?client_id=${message.client.user.id}&permissions=70282305&scope=bot
`
)
.catch(console.error);
}
};

16
commands/join.js Normal file
View File

@ -0,0 +1,16 @@
const { MessageEmbed } = require("discord.js");
const { Client, Collection } = require("discord.js");
module.exports = {
name: "join",
description: "Joins channel",
async execute(message, args) {
const { channel } = message.member.voice;
const serverQueue = message.client.queue.get(message.guild.id);
if (!channel) return message.reply("You need to join a voice channel first!").catch(console.error);
await channel.join();
return message.reply(`Codsworth Has Joined Your Channel`)
}
};

21
commands/loop.js Normal file
View File

@ -0,0 +1,21 @@
const { canModifyQueue, LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "loop",
aliases: ["l"],
description: i18n.__("loop.description"),
execute(message) {
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.reply(i18n.__("loop.errorNotQueue")).catch(console.error);
if (!canModifyQueue(message.member)) return i18n.__("common.errorNotChannel");
// toggle from false to true and reverse
queue.loop = !queue.loop;
return queue.textChannel
.send(i18n.__mf("loop.result", { loop: queue.loop ? i18n.__("common.on") : i18n.__("common.off") }))
.catch(console.error);
}
};

35
commands/lyrics.js Normal file
View File

@ -0,0 +1,35 @@
const { MessageEmbed } = require("discord.js");
const lyricsFinder = require("lyrics-finder");
const { LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "lyrics",
aliases: ["ly"],
description: i18n.__("lyrics.description"),
async execute(message) {
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.channel.send(i18n.__("lyrics.errorNotQueue")).catch(console.error);
let lyrics = null;
const title = queue.songs[0].title;
try {
lyrics = await lyricsFinder(queue.songs[0].title, "");
if (!lyrics) lyrics = i18n.__mf("lyrics.lyricsNotFound", { title: title });
} catch (error) {
lyrics = i18n.__mf("lyrics.lyricsNotFound", { title: title });
}
let lyricsEmbed = new MessageEmbed()
.setTitle(i18n.__mf("lyrics.embedTitle", { title: title }))
.setDescription(lyrics)
.setColor("#8C52FF")
.setTimestamp();
if (lyricsEmbed.description.length >= 2048)
lyricsEmbed.description = `${lyricsEmbed.description.substr(0, 2045)}...`;
return message.channel.send(lyricsEmbed).catch(console.error);
}
};

31
commands/move.js Normal file
View File

@ -0,0 +1,31 @@
const move = require("array-move");
const { canModifyQueue, LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "move",
aliases: ["mv"],
description: i18n.__("move.description"),
execute(message, args) {
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.channel.send(i18n.__("move.errorNotQueue")).catch(console.error);
if (!canModifyQueue(message.member)) return;
if (!args.length) return message.reply(i18n.__mf("move.usagesReply", { prefix: message.client.prefix }));
if (isNaN(args[0]) || args[0] <= 1)
return message.reply(i18n.__mf("move.usagesReply", { prefix: message.client.prefix }));
let song = queue.songs[args[0] - 1];
queue.songs = move(queue.songs, args[0] - 1, args[1] == 1 ? 1 : args[1] - 1);
queue.textChannel.send(
i18n.__mf("move.result", {
author: message.author,
title: song.title,
index: args[1] == 1 ? 1 : args[1]
})
);
}
};

43
commands/nowplaying.js Normal file
View File

@ -0,0 +1,43 @@
const createBar = require("string-progressbar");
const { MessageEmbed } = require("discord.js");
const { LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "np",
description: i18n.__("nowplaying.description"),
execute(message) {
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.reply(i18n.__("nowplaying.errorNotQueue")).catch(console.error);
const song = queue.songs[0];
const seek = (queue.connection.dispatcher.streamTime - queue.connection.dispatcher.pausedTime) / 1000;
const left = song.duration - seek;
let nowPlaying = new MessageEmbed()
.setTitle(i18n.__("nowplaying.embedTitle"))
.setDescription(`${song.title}\n${song.url}`)
.setColor("#8C52FF")
.setAuthor(message.client.user.username);
if (song.duration > 0) {
nowPlaying.addField(
"\u200b",
new Date(seek * 1000).toISOString().substr(11, 8) +
"[" +
createBar(song.duration == 0 ? seek : song.duration, seek, 20)[0] +
"]" +
(song.duration == 0 ? " ◉ LIVE" : new Date(song.duration * 1000).toISOString().substr(11, 8)),
false
);
nowPlaying.setFooter(
i18n.__mf("nowplaying.timeRemaining", { time: new Date(left * 1000).toISOString().substr(11, 8) })
);
}
return message.channel.send(nowPlaying);
}
};

22
commands/pause.js Normal file
View File

@ -0,0 +1,22 @@
const { canModifyQueue, LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "pause",
description: i18n.__("pause.description"),
execute(message) {
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.reply(i18n.__("pause.errorNotQueue")).catch(console.error);
if (!canModifyQueue(message.member)) return i18n.__("common.errorNotChannel");
if (queue.playing) {
queue.playing = false;
queue.connection.dispatcher.pause(true);
return queue.textChannel
.send(i18n.__mf("pause.result", { author: message.author }))
.catch(console.error);
}
}
};

15
commands/ping.js Normal file
View File

@ -0,0 +1,15 @@
const { LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "ping",
cooldown: 10,
description: i18n.__("ping.description"),
execute(message) {
message
.reply(i18n.__mf("ping.result", { ping: Math.round(message.client.ws.ping) }))
.catch(console.error);
}
};

140
commands/play.js Normal file
View File

@ -0,0 +1,140 @@
const { play } = require("../include/play");
const ytdl = require("ytdl-core");
const YouTubeAPI = require("simple-youtube-api");
const scdl = require("soundcloud-downloader").default
const https = require("https");
const { YOUTUBE_API_KEY, SOUNDCLOUD_CLIENT_ID, LOCALE, DEFAULT_VOLUME } = require("../util/Util");
const youtube = new YouTubeAPI(YOUTUBE_API_KEY);
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "play",
cooldown: 3,
aliases: ["p"],
description: i18n.__("play.description"),
async execute(message, args) {
const { channel } = message.member.voice;
const serverQueue = message.client.queue.get(message.guild.id);
if (!channel) return message.reply(i18n.__("play.errorNotChannel")).catch(console.error);
if (serverQueue && channel !== message.guild.me.voice.channel)
return message
.reply(i18n.__mf("play.errorNotInSameChannel", { user: message.client.user }))
.catch(console.error);
if (!args.length)
return message
.reply(i18n.__mf("play.usageReply", { prefix: message.client.prefix }))
.catch(console.error);
const permissions = channel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT")) return message.reply(i18n.__("play.missingPermissionConnect"));
if (!permissions.has("SPEAK")) return message.reply(i18n.__("play.missingPermissionSpeak"));
const search = args.join(" ");
const videoPattern = /^(https?:\/\/)?(www\.)?(m\.)?(youtube\.com|youtu\.?be)\/.+$/gi;
const playlistPattern = /^.*(list=)([^#\&\?]*).*/gi;
const scRegex = /^https?:\/\/(soundcloud\.com)\/(.*)$/;
const mobileScRegex = /^https?:\/\/(soundcloud\.app\.goo\.gl)\/(.*)$/;
const url = args[0];
const urlValid = videoPattern.test(args[0]);
// Start the playlist if playlist url was provided
if (!videoPattern.test(args[0]) && playlistPattern.test(args[0])) {
return message.client.commands.get("playlist").execute(message, args);
} else if (scdl.isValidUrl(url) && url.includes("/sets/")) {
return message.client.commands.get("playlist").execute(message, args);
}
if (mobileScRegex.test(url)) {
try {
https.get(url, function (res) {
if (res.statusCode == "302") {
return message.client.commands.get("play").execute(message, [res.headers.location]);
} else {
return message.reply("No content could be found at that url.").catch(console.error);
}
});
} catch (error) {
console.error(error);
return message.reply(error.message).catch(console.error);
}
return message.reply("Following url redirection...").catch(console.error);
}
const queueConstruct = {
textChannel: message.channel,
channel,
connection: null,
songs: [],
loop: false,
volume: DEFAULT_VOLUME || 100,
playing: true
};
let songInfo = null;
let song = null;
if (urlValid) {
try {
songInfo = await ytdl.getInfo(url);
song = {
title: songInfo.videoDetails.title,
url: songInfo.videoDetails.video_url,
duration: songInfo.videoDetails.lengthSeconds
};
} catch (error) {
console.error(error);
return message.reply(error.message).catch(console.error);
}
} else if (scRegex.test(url)) {
try {
const trackInfo = await scdl.getInfo(url, SOUNDCLOUD_CLIENT_ID);
song = {
title: trackInfo.title,
url: trackInfo.permalink_url,
duration: Math.ceil(trackInfo.duration / 1000)
};
} catch (error) {
console.error(error);
return message.reply(error.message).catch(console.error);
}
} else {
try {
const results = await youtube.searchVideos(search, 1, { part: "snippet" });
songInfo = await ytdl.getInfo(results[0].url);
song = {
title: songInfo.videoDetails.title,
url: songInfo.videoDetails.video_url,
duration: songInfo.videoDetails.lengthSeconds
};
} catch (error) {
console.error(error);
return message.reply(error.message).catch(console.error);
}
}
if (serverQueue) {
serverQueue.songs.push(song);
return serverQueue.textChannel
.send(i18n.__mf("play.queueAdded", { title: song.title, author: message.author }))
.catch(console.error);
}
queueConstruct.songs.push(song);
message.client.queue.set(message.guild.id, queueConstruct);
try {
queueConstruct.connection = await channel.join();
await queueConstruct.connection.voice.setSelfDeaf(false);
play(queueConstruct.songs[0], message);
} catch (error) {
console.error(error);
message.client.queue.delete(message.guild.id);
await channel.leave();
return message.channel.send(i18n.__('play.cantJoinChannel', {error: error})).catch(console.error);
}
}
};

129
commands/playlist.js Normal file
View File

@ -0,0 +1,129 @@
const { MessageEmbed } = require("discord.js");
const { play } = require("../include/play");
const YouTubeAPI = require("simple-youtube-api");
const scdl = require("soundcloud-downloader").default;
const {
YOUTUBE_API_KEY,
SOUNDCLOUD_CLIENT_ID,
MAX_PLAYLIST_SIZE,
DEFAULT_VOLUME,
LOCALE
} = require("../util/Util");
const youtube = new YouTubeAPI(YOUTUBE_API_KEY);
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "playlist",
cooldown: 5,
aliases: ["pl"],
description: i18n.__("playlist.description"),
async execute(message, args) {
const { channel } = message.member.voice;
const serverQueue = message.client.queue.get(message.guild.id);
if (!args.length)
return message
.reply(i18n.__mf("playlist.usageReply", { prefix: message.client.prefix }))
.catch(console.error);
if (!channel) return message.reply(i18n.__("playlist.errorNotChannel")).catch(console.error);
const permissions = channel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT")) return message.reply(i18n.__("playlist.missingPermissionConnect"));
if (!permissions.has("SPEAK")) return message.reply(i18n.__("missingPermissionSpeak"));
if (serverQueue && channel !== message.guild.me.voice.channel)
return message
.reply(i18n.__mf("play.errorNotInSameChannel", { user: message.client.user }))
.catch(console.error);
const search = args.join(" ");
const pattern = /^.*(youtu.be\/|list=)([^#\&\?]*).*/gi;
const url = args[0];
const urlValid = pattern.test(args[0]);
const queueConstruct = {
textChannel: message.channel,
channel,
connection: null,
songs: [],
loop: false,
volume: DEFAULT_VOLUME || 100,
playing: true
};
let playlist = null;
let videos = [];
if (urlValid) {
try {
playlist = await youtube.getPlaylist(url, { part: "snippet" });
videos = await playlist.getVideos(MAX_PLAYLIST_SIZE || 10, { part: "snippet" });
} catch (error) {
console.error(error);
return message.reply(i18n.__("playlist.errorNotFoundPlaylist")).catch(console.error);
}
} else if (scdl.isValidUrl(args[0])) {
if (args[0].includes("/sets/")) {
message.channel.send(i18n.__("playlist.fetchingPlaylist"));
playlist = await scdl.getSetInfo(args[0], SOUNDCLOUD_CLIENT_ID);
videos = playlist.tracks.map((track) => ({
title: track.title,
url: track.permalink_url,
duration: track.duration / 1000
}));
}
} else {
try {
const results = await youtube.searchPlaylists(search, 1, { part: "snippet" });
playlist = results[0];
videos = await playlist.getVideos(MAX_PLAYLIST_SIZE || 10, { part: "snippet" });
} catch (error) {
console.error(error);
return message.reply(error.message).catch(console.error);
}
}
const newSongs = videos
.filter((video) => video.title != "Private video" && video.title != "Deleted video")
.map((video) => {
return (song = {
title: video.title,
url: video.url,
duration: video.durationSeconds
});
});
serverQueue ? serverQueue.songs.push(...newSongs) : queueConstruct.songs.push(...newSongs);
let playlistEmbed = new MessageEmbed()
.setTitle(`${playlist.title}`)
.setDescription(newSongs.map((song, index) => `${index + 1}. ${song.title}`))
.setURL(playlist.url)
.setColor("#8C52FF")
.setTimestamp();
if (playlistEmbed.description.length >= 2048)
playlistEmbed.description =
playlistEmbed.description.substr(0, 2007) + i18n.__("playlist.playlistCharLimit");
message.channel.send(i18n.__mf("playlist.startedPlaylist", { author: message.author }), playlistEmbed);
if (!serverQueue) {
message.client.queue.set(message.guild.id, queueConstruct);
try {
queueConstruct.connection = await channel.join();
await queueConstruct.connection.voice.setSelfDeaf(true);
play(queueConstruct.songs[0], message);
} catch (error) {
console.error(error);
message.client.queue.delete(message.guild.id);
await channel.leave();
return message.channel.send(i18n.__("play.cantJoinChannel", { error: error })).catch(console.error);
}
}
}
};

37
commands/pruning.js Normal file
View File

@ -0,0 +1,37 @@
const fs = require("fs");
const { LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
let config;
try {
config = require("../config.json");
} catch (error) {
config = null;
}
module.exports = {
name: "pruning",
description: i18n.__('pruning.description'),
execute(message) {
if (!config) return;
config.PRUNING = !config.PRUNING;
fs.writeFile("./config.json", JSON.stringify(config, null, 2), (err) => {
if (err) {
console.log(err);
return message.channel.send(i18n.__("pruning.errorWritingFile")).catch(console.error);
}
return message.channel
.send(
i18n.__("pruning.result", {
loop: config.PRUNING ? i18n.__("common.enabled") : i18n.__("common.disabled")
})
)
.catch(console.error);
});
}
};

95
commands/queue.js Normal file
View File

@ -0,0 +1,95 @@
const { MessageEmbed } = require("discord.js");
const { LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "queue",
cooldown: 5,
aliases: ["q"],
description: i18n.__("queue.description"),
async execute(message) {
const permissions = message.channel.permissionsFor(message.client.user);
if (!permissions.has(["MANAGE_MESSAGES", "ADD_REACTIONS"]))
return message.reply(i18n.__("queue.missingPermissionMessage"));
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.channel.send(i18n.__("queue.errorNotQueue"));
let currentPage = 0;
const embeds = generateQueueEmbed(message, queue.songs);
const queueEmbed = await message.channel.send(
`**${i18n.__mf("queue.currentPage")} ${currentPage + 1}/${embeds.length}**`,
embeds[currentPage]
);
try {
await queueEmbed.react("⬅️");
await queueEmbed.react("⏹");
await queueEmbed.react("➡️");
} catch (error) {
console.error(error);
message.channel.send(error.message).catch(console.error);
}
const filter = (reaction, user) =>
["⬅️", "⏹", "➡️"].includes(reaction.emoji.name) && message.author.id === user.id;
const collector = queueEmbed.createReactionCollector(filter, { time: 60000 });
collector.on("collect", async (reaction, user) => {
try {
if (reaction.emoji.name === "➡️") {
if (currentPage < embeds.length - 1) {
currentPage++;
queueEmbed.edit(
i18n.__mf("queue.currentPage", { page: currentPage + 1, length: embeds.length }),
embeds[currentPage]
);
}
} else if (reaction.emoji.name === "⬅️") {
if (currentPage !== 0) {
--currentPage;
queueEmbed.edit(
i18n.__mf("queue.currentPage", { page: currentPage + 1, length: embeds.length }),
embeds[currentPage]
);
}
} else {
collector.stop();
reaction.message.reactions.removeAll();
}
await reaction.users.remove(message.author.id);
} catch (error) {
console.error(error);
return message.channel.send(error.message).catch(console.error);
}
});
}
};
function generateQueueEmbed(message, queue) {
let embeds = [];
let k = 10;
for (let i = 0; i < queue.length; i += 10) {
const current = queue.slice(i, k);
let j = i;
k += 10;
const info = current.map((track) => `${++j} - [${track.title}](${track.url})`).join("\n");
const embed = new MessageEmbed()
.setTitle(i18n.__("queue.embedTitle"))
.setThumbnail(message.guild.iconURL())
.setColor("#8C52FF")
.setDescription(
i18n.__mf("queue.embedCurrentSong", { title: queue[0].title, url: queue[0].url, info: info })
)
.setTimestamp();
embeds.push(embed);
}
return embeds;
}

41
commands/remove.js Normal file
View File

@ -0,0 +1,41 @@
const { canModifyQueue, LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
const pattern = /^[0-9]{1,2}(\s*,\s*[0-9]{1,2})*$/;
module.exports = {
name: "remove",
aliases: ["rm"],
description: i18n.__("remove.description"),
execute(message, args) {
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.channel.send(i18n.__("remove.errorNotQueue")).catch(console.error);
if (!canModifyQueue(message.member)) return i18n.__("common.errorNotChannel");
if (!args.length) return message.reply(i18n.__mf("remove.usageReply", { prefix: message.client.prefix }));
const arguments = args.join("");
const songs = arguments.split(",").map((arg) => parseInt(arg));
let removed = [];
if (pattern.test(arguments)) {
queue.songs = queue.songs.filter((item, index) => {
if (songs.find((songIndex) => songIndex - 1 === index)) removed.push(item);
else return true;
});
queue.textChannel.send(
`${message.author} ❌ removed **${removed.map((song) => song.title).join("\n")}** from the queue.`
);
} else if (!isNaN(args[0]) && args[0] >= 1 && args[0] <= queue.songs.length) {
console.log("we got elsed!");
return queue.textChannel.send(
`${message.author} ❌ removed **${queue.songs.splice(args[0] - 1, 1)[0].title}** from the queue.`
);
} else {
console.log("we got the last one");
return message.reply(i18n.__mf("remove.usageReply", { prefix: message.client.prefix }));
}
}
};

25
commands/resume.js Normal file
View File

@ -0,0 +1,25 @@
const { canModifyQueue, LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "resume",
aliases: ["r"],
description: i18n.__('resume.description'),
execute(message) {
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.reply(i18n.__("resume.errorNotQueue")).catch(console.error);
if (!canModifyQueue(message.member)) return i18n.__("common.errorNotChannel");
if (!queue.playing) {
queue.playing = true;
queue.connection.dispatcher.resume();
return queue.textChannel
.send(i18n.__mf("resume.resultNotPlaying", { author: message.author }))
.catch(console.error);
}
return message.reply(i18n.__("resume.errorPlaying")).catch(console.error);
}
};

65
commands/search.js Normal file
View File

@ -0,0 +1,65 @@
const { MessageEmbed } = require("discord.js");
const YouTubeAPI = require("simple-youtube-api");
const { YOUTUBE_API_KEY, LOCALE } = require("../util/Util");
const youtube = new YouTubeAPI(YOUTUBE_API_KEY);
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "search",
description: i18n.__("search.description"),
async execute(message, args) {
if (!args.length)
return message
.reply(i18n.__mf("search.usageReply", { prefix: message.client.prefix, name: module.exports.name }))
.catch(console.error);
if (message.channel.activeCollector) return message.reply(i18n.__("search.errorAlreadyCollector"));
if (!message.member.voice.channel)
return message.reply(i18n.__("search.errorNotChannel")).catch(console.error);
const search = args.join(" ");
let resultsEmbed = new MessageEmbed()
.setTitle(i18n.__("search.resultEmbedTtile"))
.setDescription(i18n.__mf("search.resultEmbedDesc", { search: search }))
.setColor("#8C52FF");
try {
const results = await youtube.searchVideos(search, 10);
results.map((video, index) => resultsEmbed.addField(video.shortURL, `${index + 1}. ${video.title}`));
let resultsMessage = await message.channel.send(resultsEmbed);
function filter(msg) {
const pattern = /^[0-9]{1,2}(\s*,\s*[0-9]{1,2})*$/;
return pattern.test(msg.content);
}
message.channel.activeCollector = true;
const response = await message.channel.awaitMessages(filter, { max: 1, time: 30000, errors: ["time"] });
const reply = response.first().content;
if (reply.includes(",")) {
let songs = reply.split(",").map((str) => str.trim());
for (let song of songs) {
await message.client.commands
.get("play")
.execute(message, [resultsEmbed.fields[parseInt(song) - 1].name]);
}
} else {
const choice = resultsEmbed.fields[parseInt(response.first()) - 1].name;
message.client.commands.get("play").execute(message, [choice]);
}
message.channel.activeCollector = false;
resultsMessage.delete().catch(console.error);
response.first().delete().catch(console.error);
} catch (error) {
console.error(error);
message.channel.activeCollector = false;
message.reply(error.message).catch(console.error);
}
}
};

23
commands/shuffle.js Normal file
View File

@ -0,0 +1,23 @@
const { canModifyQueue, LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "shuffle",
description: i18n.__('shuffle.description'),
execute(message) {
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.channel.send(i18n.__("shuffle.errorNotQueue")).catch(console.error);
if (!canModifyQueue(message.member)) return i18n.__("common.errorNotChannel");
let songs = queue.songs;
for (let i = songs.length - 1; i > 1; i--) {
let j = 1 + Math.floor(Math.random() * i);
[songs[i], songs[j]] = [songs[j], songs[i]];
}
queue.songs = songs;
message.client.queue.set(message.guild.id, queue);
queue.textChannel.send(i18n.__mf('shuffle.result', {author: message.author})).catch(console.error);
}
};

19
commands/skip.js Normal file
View File

@ -0,0 +1,19 @@
const { canModifyQueue, LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "skip",
aliases: ["s"],
description: i18n.__("skip.description"),
execute(message) {
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.reply(i18n.__("skip.errorNotQueue")).catch(console.error);
if (!canModifyQueue(message.member)) return i18n.__("common.errorNotChannel");
queue.playing = true;
queue.connection.dispatcher.end();
queue.textChannel.send(i18n.__mf("skip.result", { author: message.author })).catch(console.error);
}
};

39
commands/skipto.js Normal file
View File

@ -0,0 +1,39 @@
const { canModifyQueue, LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "skipto",
aliases: ["st"],
description: i18n.__("skipto.description"),
execute(message, args) {
if (!args.length || isNaN(args[0]))
return message
.reply(i18n.__mf("skipto.usageReply", { prefix: message.client.prefix, name: module.exports.name }))
.catch(console.error);
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.channel.send(i18n.__("skipto.errorNotQueue")).catch(console.error);
if (!canModifyQueue(message.member)) return i18n.__("common.errorNotChannel");
if (args[0] > queue.songs.length)
return message
.reply(i18n.__mf("skipto.errorNotValid", { length: queue.songs.length }))
.catch(console.error);
queue.playing = true;
if (queue.loop) {
for (let i = 0; i < args[0] - 2; i++) {
queue.songs.push(queue.songs.shift());
}
} else {
queue.songs = queue.songs.slice(args[0] - 2);
}
queue.connection.dispatcher.end();
queue.textChannel
.send(i18n.__mf("skipto.result", { author: message.author, arg: args[0] - 1 }))
.catch(console.error);
}
};

19
commands/stop.js Normal file
View File

@ -0,0 +1,19 @@
const { canModifyQueue, LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "stop",
description: i18n.__('stop.description'),
execute(message) {
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.reply(i18n.__("stop.errorNotQueue")).catch(console.error);
if (!canModifyQueue(message.member)) return i18n.__("common.errorNotChannel");
queue.songs = [];
queue.connection.dispatcher.end();
queue.textChannel.send(i18n.__mf("stop.result", { author: message.author })).catch(console.error);
}
};

24
commands/uptime.js Normal file
View File

@ -0,0 +1,24 @@
const { LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "uptime",
aliases: ["u"],
description: i18n.__('uptime.description'),
execute(message) {
let seconds = Math.floor(message.client.uptime / 1000);
let minutes = Math.floor(seconds / 60);
let hours = Math.floor(minutes / 60);
let days = Math.floor(hours / 24);
seconds %= 60;
minutes %= 60;
hours %= 24;
return message
.reply(i18n.__mf('uptime.result', {days: days, hours: hours, minutes: minutes, seconds: seconds}))
.catch(console.error);
}
};

26
commands/volume.js Normal file
View File

@ -0,0 +1,26 @@
const { canModifyQueue, LOCALE } = require("../util/Util");
const i18n = require("i18n");
i18n.setLocale(LOCALE);
module.exports = {
name: "volume",
aliases: ["v"],
description: i18n.__("volume.description"),
execute(message, args) {
const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.reply(i18n.__("volume.errorNotQueue")).catch(console.error);
if (!canModifyQueue(message.member))
return message.reply(i18n.__("volume.errorNotChannel")).catch(console.error);
if (!args[0]) return message.reply(i18n.__mf("volume.currentVolume", { volume: queue.volume })).catch(console.error);
if (isNaN(args[0])) return message.reply(i18n.__("volume.errorNotNumber")).catch(console.error);
if (Number(args[0]) > 100 || Number(args[0]) < 0)
return message.reply(i18n.__("volume.errorNotValid")).catch(console.error);
queue.volume = args[0];
queue.connection.dispatcher.setVolumeLogarithmic(args[0] / 100);
return queue.textChannel.send(i18n.__mf("volume.result", { arg: args[0] })).catch(console.error);
}
};