Skip to content

Commit

Permalink
Refactored code and removed the require lines of the old files
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Dec 8, 2021
1 parent 31aa8e9 commit 4286abf
Show file tree
Hide file tree
Showing 15 changed files with 337 additions and 128 deletions.
9 changes: 6 additions & 3 deletions commands/Anime/highfive.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { requestAPI } = require("../../modules/requestAPI");
const { getUserFromMention } = require("../../modules/getUserFromMention");

module.exports = {
Expand All @@ -11,7 +10,9 @@ module.exports = {
async run(message, args, client) {
try {
const user = getUserFromMention(args[0], client);
const highFive = await requestAPI("https://api.waifu.pics/sfw/highfive");
const highFive = await client.apis.request(
"https://api.waifu.pics/sfw/highfive"
);
const highFiveEmbed = {
color: "#9dcc37",
image: {
Expand Down Expand Up @@ -42,7 +43,9 @@ module.exports = {
async execute(interaction, client) {
await interaction.deferReply();
try {
const highFive = await requestAPI("https://api.waifu.pics/sfw/highfive");
const highFive = await client.apis.request(
"https://api.waifu.pics/sfw/highfive"
);
const highFiveEmbed = {
color: "#9dcc37",
image: {
Expand Down
7 changes: 4 additions & 3 deletions commands/Anime/hug.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { requestAPI } = require("../../modules/requestAPI");

module.exports = {
name: "hug",
args: false,
description: "Sends a hug gif",
usage: "hug",
async run(message, args, client) {
console.log("hi");
try {
const hug = await requestAPI("https://api.waifu.pics/sfw/hug");
const hug = await client.apis.request("https://api.waifu.pics/sfw/hug");
const hugEmbed = {
color: "#9dcc37",
image: {
Expand All @@ -24,6 +24,7 @@ module.exports = {
};
return await message.channel.send({ embeds: [hugEmbed] });
} catch (error) {
console.log(error);
client.logger(error.message, "error");
return await message.channel.send(
`❌ | Couldn't retrieve a hug gif, Sorry!`
Expand All @@ -36,7 +37,7 @@ module.exports = {
async execute(interaction, client) {
await interaction.deferReply();
try {
const hug = await requestAPI("https://api.waifu.pics/sfw/hug");
const hug = await client.apis.request("https://api.waifu.pics/sfw/hug");
const hugEmbed = {
color: "#9dcc37",
image: {
Expand Down
12 changes: 5 additions & 7 deletions commands/Anime/searchAnime.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const { embedMessage } = require("../../modules/embedSimple");
const { getAnimeInfo } = require("../../modules/get-anime-details");
const { SlashCommandBuilder } = require("@discordjs/builders");
const { logger } = require("../../modules/logger");

module.exports = {
name: "searchanime",
Expand All @@ -16,7 +14,7 @@ module.exports = {
embeds: [embedMessage("RED", "❌ You have to provide an anime name!")],
});
try {
const Anime = await getAnimeInfo(searchString);
const Anime = await client.apis.getAnimeInfo(searchString);
const animeEmbed = {
color: "#9dcc37",
title: `${Anime.titlerom} AKA ${Anime.titleeng ?? `${Anime.titlerom}`}`,
Expand Down Expand Up @@ -72,11 +70,11 @@ module.exports = {

return await message.channel.send({ embeds: [animeEmbed] });
} catch (err) {
client.logger(err.message, "error");
console.error(err);
return await message.channel.send({
embeds: [embedMessage("RED", `❌ Could not find this Anime, Sry!`)],
});
logger(err.message, "error");
console.error(err);
}
},
data: new SlashCommandBuilder()
Expand All @@ -93,7 +91,7 @@ module.exports = {
const animeName = interaction.options.getString("anime");

try {
const Anime = await getAnimeInfo(animeName);
const Anime = await client.apis.getAnimeInfo(animeName);
const animeEmbed = {
color: "#9dcc37",
title: `${Anime.titlerom} AKA ${Anime.titleeng ?? `${Anime.titlerom}`}`,
Expand Down Expand Up @@ -152,7 +150,7 @@ module.exports = {
await interaction.followUp({
embeds: [embedMessage("RED", `❌ Could not find this Anime, Sry!`)],
});
logger(err.message, "error");
client.logger(err.message, "error");
console.error(err);
}
},
Expand Down
17 changes: 12 additions & 5 deletions commands/Anime/waifu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { requestAPI } = require("../../modules/requestAPI");

module.exports = {
name: "waifu",
Expand All @@ -8,7 +7,9 @@ module.exports = {
usage: "waifu",
async run(message, args, client) {
try {
const waifu = await requestAPI("https://api.waifu.pics/sfw/waifu");
const waifu = await client.apis.request(
"https://api.waifu.pics/sfw/waifu"
);
const waifuEmbed = {
color: "#9dcc37",
image: {
Expand All @@ -25,7 +26,9 @@ module.exports = {
return await message.channel.send({ embeds: [waifuEmbed] });
} catch (error) {
client.logger(error.message, "error");
return await message.channel.send(`❌ | Couldn't retrieve a waifu pic, Sorry!`);
return await message.channel.send(
`❌ | Couldn't retrieve a waifu pic, Sorry!`
);
}
},
data: new SlashCommandBuilder()
Expand All @@ -34,7 +37,9 @@ module.exports = {
async execute(interaction, client) {
await interaction.deferReply();
try {
const waifu = await requestAPI("https://api.waifu.pics/sfw/waifu");
const waifu = await client.apis.request(
"https://api.waifu.pics/sfw/waifu"
);
const waifuEmbed = {
color: "#9dcc37",
image: {
Expand All @@ -51,7 +56,9 @@ module.exports = {
return await interaction.followUp({ embeds: [waifuEmbed] });
} catch (error) {
client.logger(error.message, "error");
return await interaction.followUp(`❌ | Couldn't retrieve a waifu pic, Sorry!`);
return await interaction.followUp(
`❌ | Couldn't retrieve a waifu pic, Sorry!`
);
}
},
};
7 changes: 3 additions & 4 deletions commands/Fun/gif.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { embedMessage } = require("../../modules/embedSimple");
const { requestAPI } = require("../../modules/requestAPI");
const { GiphyKey } = require("../../config.json");

module.exports = {
Expand All @@ -22,7 +21,7 @@ module.exports = {
});

if (!query) {
const random = await requestAPI(
const random = await client.apis.request(
`https://api.giphy.com/v1/gifs/random?api_key=${GiphyKey}`,
{
method: "GET",
Expand Down Expand Up @@ -118,7 +117,7 @@ module.exports = {
],
});
if (!query) {
const random = await requestAPI(
const random = await client.apis.request(
`https://api.giphy.com/v1/gifs/random?api_key=${GiphyKey}`,
{
method: "GET",
Expand All @@ -145,7 +144,7 @@ module.exports = {
return await interaction.followUp({ embeds: [randomEmbed] });
}

const request = await requestAPI(
const request = await client.api.request(
`https://api.giphy.com/v1/gifs/search?q=${query}&api_key=${GiphyKey}&limit=25`,
{
method: "GET",
Expand Down
5 changes: 2 additions & 3 deletions commands/Fun/insult.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { embedMessage } = require("../../modules/embedSimple");
const { getUserFromMention } = require("../../modules/getUserFromMention");
const { requestAPI } = require("../../modules/requestAPI");

module.exports = {
name: "insult",
Expand Down Expand Up @@ -29,7 +28,7 @@ module.exports = {
});

try {
const insult = await requestAPI(
const insult = await client.apis.request(
"https://evilinsult.com/generate_insult.php?lang=en&type=json"
);

Expand All @@ -54,7 +53,7 @@ module.exports = {
const user = interaction.options.getUser("user");

try {
const insult = await requestAPI(
const insult = await client.apis.request(
"https://evilinsult.com/generate_insult.php?lang=en&type=json"
);

Expand Down
5 changes: 2 additions & 3 deletions commands/Fun/jokes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { requestAPI } = require("../../modules/requestAPI");

module.exports = {
name: "joke",
Expand All @@ -8,7 +7,7 @@ module.exports = {
description: "Gets a random joke!",
async run(message, args, client) {
try {
const joke = await requestAPI(
const joke = await client.apis.request(
"https://v2.jokeapi.dev/joke/Miscellaneous,Dark,Pun,Spooky,Christmas"
);

Expand Down Expand Up @@ -53,7 +52,7 @@ module.exports = {
await interaction.deferReply();

try {
const joke = await requestAPI(
const joke = await client.apis.request(
"https://v2.jokeapi.dev/joke/Miscellaneous,Dark,Pun,Spooky,Christmas"
);

Expand Down
29 changes: 13 additions & 16 deletions commands/Misc/searchMovie.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { TMDb } = require("../../config.json");
const { embedMessage } = require("../../modules/embedSimple");
const { getMovieID, getDetails } = require("../../modules/getMovieInfo");
const { logger } = require("../../modules/logger");

module.exports = {
name: "searchmovie",
Expand Down Expand Up @@ -45,17 +43,17 @@ module.exports = {
embeds: [embedMessage("#9dcc37", `You have to provide a Movie name!`)],
});
try {
let movie;
if (searchString[1]) {
const movieWithYear = await getMovieID(
searchString[0],
searchString[1]
);
movie = await getDetails(movieWithYear);
} else {
const withoutYear = await getMovieID(searchString[0]);
movie = await getDetails(withoutYear);
}
let movie = await client.api.getMovieDetails(searchString[0], TMDb);
// if (searchString[1]) {
// const movieWithYear = await getMovieID(
// searchString[0],
// searchString[1]
// );
// movie = await getDetails(movieWithYear);
// } else {
// const withoutYear = await getMovieID(searchString[0]);
// movie = await getDetails(withoutYear);
// }

const movieEmbed = {
color: "#9dcc37",
Expand Down Expand Up @@ -121,7 +119,7 @@ module.exports = {

return await message.channel.send({ embeds: [movieEmbed] });
} catch (error) {
logger(error.message, "error");
client.logger(error.message, "error");
console.error(error);
}
},
Expand All @@ -146,8 +144,7 @@ module.exports = {
});

try {
const movieID = await getMovieID(movieName);
const movie = await getDetails(movieID);
const movie = await client.apis.getMovieDetails(movieName, TMDb);

const movieEmbed = {
color: "#9dcc37",
Expand Down
5 changes: 2 additions & 3 deletions commands/Music/lyrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { SlashCommandBuilder } = require("@discordjs/builders");
const { embedMessage } = require("../../modules/embedSimple");
const { getSong } = require("genius-lyrics-api");
const { geniusApiKey } = require("../../config.json");
const { chunkSubstr } = require("../../modules/chunkString");

module.exports = {
name: "lyrics",
Expand Down Expand Up @@ -85,7 +84,7 @@ module.exports = {
};

if (lyrics.lyrics.length > 4096) {
const chunkLyrics = chunkSubstr(lyrics.lyrics, 4096);
const chunkLyrics = client.tools.chunkSubstr(lyrics.lyrics, 4096);
chunkLyrics.forEach(async (str) => {
lyricsEmbed.description = str;
return await message.channel.send({ embeds: [lyricsEmbed] });
Expand Down Expand Up @@ -189,7 +188,7 @@ module.exports = {
};

if (lyrics.lyrics.length > 4096) {
const chunkLyrics = chunkSubstr(lyrics.lyrics, 4096);
const chunkLyrics = client.tools.chunkSubstr(lyrics.lyrics, 4096);
chunkLyrics.forEach(async (str) => {
lyricsEmbed.description = str;
return await interaction.followUp({ embeds: [lyricsEmbed] });
Expand Down
5 changes: 2 additions & 3 deletions commands/Music/queue.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { chunkSubstr } = require("../../modules/chunkString");
const { embedMessage } = require("../../modules/embedSimple");

module.exports = {
Expand Down Expand Up @@ -40,7 +39,7 @@ module.exports = {
};

if (tracks.join("\n").length > 4096) {
const chunked = chunkSubstr(tracks.join("\n"), 4096);
const chunked = client.tools.chunkSubstr(tracks.join("\n"), 4096);
chunked.forEach(async (str) => {
queueEmbed.description = str;
return await message.channel.send({ embeds: [queueEmbed] });
Expand Down Expand Up @@ -81,7 +80,7 @@ module.exports = {
};

if (tracks.join("\n").length > 4096) {
const chunked = chunkSubstr(tracks.join("\n"), 4096);
const chunked = client.tools.chunkSubstr(tracks.join("\n"), 4096);
chunked.forEach(async (str) => {
queueEmbed.description = str;
return await interaction.followUp({ embeds: [queueEmbed] });
Expand Down
4 changes: 2 additions & 2 deletions events/error.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { logger } = require(".././modules/logger");
const { Utils } = require("devtools-ts");

module.exports = {
name: "error",
async execute(error) {
logger(error, "error");
new Utils().logger(error, "error");
},
};
3 changes: 1 addition & 2 deletions modules/Music.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { embedMessage } = require("./embedSimple.js");
const playdl = require("play-dl");
const { QueryType } = require("discord-player");
const { logger } = require("./logger.js");

class Music {
/**
Expand Down Expand Up @@ -147,7 +146,7 @@ class Music {
});
return;
} catch (err) {
logger(err.message, "error");
client.logger(err.message, "error");
console.log(err);
await command.reply({
embeds: [
Expand Down
Loading

0 comments on commit 4286abf

Please sign in to comment.