Skip to content

Commit

Permalink
🪛 Bugs fix and improve functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Maseshi committed May 25, 2023
1 parent 9781b10 commit f8ba390
Show file tree
Hide file tree
Showing 75 changed files with 795 additions and 705 deletions.
28 changes: 13 additions & 15 deletions source/commands/developer/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,36 +120,36 @@ module.exports.function.command = {
},
async execute(interaction) {
const subCommand = interaction.options.getSubcommand();
const inputType = interaction.options.getString("type") ?? "";
const inputFilename = interaction.options.getString("filename") ?? "";

const folderPath = "./source/logs/";
const teamOwner = parseInt(interaction.client.config.team.owner);
const teamDev = interaction.client.config.team.developer.map(Number);

switch (subCommand) {
case "get":
const inputGetType = interaction.options.getString("type");

try {
const logs = readdirSync(folderPath).filter(files => files.endsWith(".log"));
const listFilename = logs.filter(log => log.includes(inputGetType));
const listFilename = logs.filter(log => log.includes(inputType));

if (listFilename) {
await interaction.reply(interaction.client.translate.commands.logs.found_file.replace("%s1", listFilename.length).replace("%s2", listFilename.join(" \n")));
} else {
await interaction.reply(interaction.client.translate.commands.logs.file_not_found.replace("%s", inputGetType));
await interaction.reply(interaction.client.translate.commands.logs.file_not_found.replace("%s", inputType));
}
} catch (error) {
await interaction.reply(interaction.client.translate.commands.logs.folder_empty);
}
break;
case "read":
const inputReadFilename = interaction.options.getString("filename");

try {
const fileString = readFileSync(folderPath + inputReadFilename, "utf8");
const fileString = readFileSync(folderPath + inputFilename, "utf8");

await interaction.reply("```JavaScript\n%s\n```".replace("%s", fileString));
} catch {
try {
const fileString = readFileSync(folderPath + inputReadFilename + ".log", "utf8");
const fileString = readFileSync(folderPath + inputFilename + ".log", "utf8");

await interaction.reply("```JavaScript\n%s\n```".replace("%s", fileString));
} catch (error) {
Expand All @@ -158,21 +158,19 @@ module.exports.function.command = {
}
break;
case "delete":
const inputDeleteFilename = interaction.options.getString("filename");

if ((interaction.user.id !== interaction.client.config.team.owner) || (!interaction.client.config.team.developer.includes(interaction.user.id))) {
if ((interaction.user.id !== teamOwner) || (!teamDev.includes(interaction.user.id))) {
return interaction.reply(interaction.client.translate.commands.logs.owner_only);
}

try {
unlinkSync(folderPath + inputDeleteFilename);
unlinkSync(folderPath + inputFilename);

await interaction.reply(interaction.client.translate.commands.logs.file_has_been_deleted.replace("%s", inputDeleteFilename));
await interaction.reply(interaction.client.translate.commands.logs.file_has_been_deleted.replace("%s", inputFilename));
} catch {
try {
unlinkSync(folderPath + inputDeleteFilename + ".log");
unlinkSync(folderPath + inputFilename + ".log");

await interaction.reply(interaction.client.translate.commands.logs.file_has_been_deleted.replace("%s", inputDeleteFilename));
await interaction.reply(interaction.client.translate.commands.logs.file_has_been_deleted.replace("%s", inputFilename));
} catch (error) {
await interaction.reply(interaction.client.translate.commands.logs.can_not_delete_file.replace("%s", error));
}
Expand Down
2 changes: 0 additions & 2 deletions source/commands/developer/reload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const { PermissionsBitField } = require("discord.js");
const { readdirSync } = require("node:fs");
const path = require("path");

module.exports = {
"enable": true,
Expand Down
3 changes: 2 additions & 1 deletion source/commands/fun/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports.function.command = {
const subCommand = interaction.options.getSubcommand();

switch (subCommand) {
case "level":
case "level": {
const map = [];
const max = 10;
const snapshot = await levelSystem(interaction.client, interaction, "GET/ALL");
Expand Down Expand Up @@ -102,6 +102,7 @@ module.exports.function.command = {

await interaction.reply({ "embeds": [embed] });
break;
}
}
}
}
8 changes: 4 additions & 4 deletions source/commands/games/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ module.exports.function.command = {
await interaction.followUp(interaction.client.translate.commands.rpc.user_winner.replace("%s", inputOpponent.id));

gameCollector.stop();
return delete winner, playerOne, playerTwo;
return winner = "", playerOne, playerTwo;
}
if (winner === authorUser.id) {
await interaction.followUp(interaction.client.translate.commands.rpc.user_winner.replace("%s", authorUser.id));

gameCollector.stop();
return delete winner, playerOne, playerTwo;
return winner = "", playerOne, playerTwo;
}
if (!winner) {
await interaction.followUp(interaction.client.translate.commands.rpc.tie);

gameCollector.stop();
return delete winner, playerOne, playerTwo;
return winner = "", playerOne, playerTwo;
}
}
});
gameCollector.on("end", async collected => {
gameCollector.on("end", async () => {
rpcEmbed.setDescription(authorUser.username + " `" + gameObjects[playerOne] + "` VS `" + gameObjects[playerTwo] + "` " + inputOpponent.username);

await interaction.editReply({
Expand Down
17 changes: 11 additions & 6 deletions source/commands/games/snake.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports.function.command = {
const gameOver = () => {
inGame = false;
endTime = new Date();

const playTime = endTime - startTime;
const authorAvatar = interaction.user.displayAvatarURL();
const authorUsername = interaction.user.username;
Expand Down Expand Up @@ -134,29 +134,34 @@ module.exports.function.command = {
const nextPos = { "x": snakeHead.x, "y": snakeHead.y };

switch (reaction.emoji.name) {
case "⬅️":
case "⬅️": {
let nextLeftX = snakeHead.x - 1;
if (nextLeftX < 0) nextLeftX = WIDTH - 1;
nextPos.x = nextLeftX;
break;
case "⬆️":
}
case "⬆️": {
let nextTopY = snakeHead.y - 1;
if (nextTopY < 0) nextTopY = HEIGHT - 1;
nextPos.y = nextTopY;
break;
case "⬇️":
}
case "⬇️": {
let nextBottomY = snakeHead.y + 1;
if (nextBottomY >= HEIGHT) nextBottomY = 0;
nextPos.y = nextBottomY;
break;
case "➡️":
}
case "➡️": {
let nextRightX = snakeHead.x + 1;
if (nextRightX >= WIDTH) nextRightX = 0;
nextPos.x = nextRightX;
break;
case "⏹️":
}
case "⏹️": {
gameOver();
break;
}
}

reaction.users.remove(reaction.users.cache.filter(user => user.id !== gameEmbedMessage.author.id).first().id).then(() => {
Expand Down
2 changes: 1 addition & 1 deletion source/commands/games/tictactoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ module.exports.function.command = {
});
}
});
gameCollector.on("end", async collected => {
gameCollector.on("end", async () => {
ButtonTopLeft.setDisabled();
ButtonTopCenter.setDisabled();
ButtonTopRight.setDisabled();
Expand Down
8 changes: 4 additions & 4 deletions source/commands/information/guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ module.exports.function.command = {
const approximatePresenceCount = interaction.guild.approximatePresenceCount || interaction.client.translate.commands.guild.unknown;
const available = interaction.guild.available ? interaction.client.translate.commands.guild.available : interaction.client.translate.commands.guild.unavailable;
const banner = interaction.guild.bannerURL() || interaction.client.translate.commands.guild.do_not_have;
const createdAt = dateFormat(interaction.guild.createAt) || interaction.client.translate.commands.guild.unknown;
const createdTimestamp = dateFormat(interaction.guild.createdTimestamp) || interaction.client.translate.commands.guild.unknown;
const createdAt = dateFormat(interaction.client, interaction.guild.createAt) || interaction.client.translate.commands.guild.unknown;
const createdTimestamp = dateFormat(interaction.client, interaction.guild.createdTimestamp) || interaction.client.translate.commands.guild.unknown;
const defaultMessageNotification = interaction.guild.defaultMessageNotification || interaction.client.translate.commands.guild.unknown;
const description = interaction.guild.description || interaction.client.translate.commands.guild.do_not_have;
const discoverySplash = interaction.guild.discoverySplashURL() || interaction.client.translate.commands.guild.do_not_have;
const explicitContentFilter = interaction.guild.explicitContentFilter.toString() || interaction.client.translate.commands.guild.unknown;
const features = interaction.guild.features.join() || interaction.client.translate.commands.guild.do_not_have;
const icon = interaction.guild.iconURL() || interaction.client.translate.commands.guild.unknown;
const id = interaction.guild.id || interaction.client.translate.commands.guild.unknown;
const joinedAt = dateFormat(interaction.guild.joinedAt) || interaction.client.translate.commands.guild.unknown;
const joinTimestamp = dateFormat(interaction.guild.joinTimestamp) || interaction.client.translate.commands.guild.unknown;
const joinedAt = dateFormat(interaction.client, interaction.guild.joinedAt) || interaction.client.translate.commands.guild.unknown;
const joinTimestamp = dateFormat(interaction.client, interaction.guild.joinTimestamp) || interaction.client.translate.commands.guild.unknown;
const large = interaction.guild.large ? interaction.client.translate.commands.guild.yes : interaction.client.translate.commands.guild.no;
const maximumMembers = interaction.guild.maximumMembers.toString() || interaction.client.translate.commands.guild.unknown;
const maximumPresences = interaction.guild.maximumPresences || interaction.client.translate.commands.guild.unknown;
Expand Down
2 changes: 1 addition & 1 deletion source/commands/information/leveling.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports.function.command = {
let memberBot = false;

if (inputMember) {
author = member.user;
author = inputMember;
authorAvatar = author.avatarURL();
authorFetch = await author.fetch();
memberBot = author.bot;
Expand Down
29 changes: 19 additions & 10 deletions source/commands/information/minecraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ module.exports.function.command = {
},
async execute(interaction) {
const subCommand = interaction.options.getSubcommand();
const inputIP = interaction.options.getString("ip") ?? "";
const inputName = interaction.options.getString("name") ?? "";

const clientUsername = interaction.client.user.username;
const clientAvatar = interaction.client.user.displayAvatarURL();

switch (subCommand) {
case "status":
const inputIP = interaction.options.getString("ip");

case "status": {
const statusEmbed = new EmbedBuilder()
.setColor("Green")
.setAuthor({ "name": clientUsername, "iconURL": clientAvatar })
Expand Down Expand Up @@ -120,25 +120,34 @@ module.exports.function.command = {
{ "name": interaction.client.translate.commands.minecraft.motd, "value": "```" + motd + "```", "inline": false },
);

await interaction.reply({ "embeds": [statusEmbed], "files": [response.data.icon ? icon : null] });
await interaction.reply({
"embeds": [statusEmbed],
"files": [response.data.icon ? icon : null]
});
} catch (error) {
await interaction.reply({ "embeds": [statusErrorEmbed] });
}
break;
case "skin":
const inputName = interaction.options.getString("name");

const skin = new AttachmentBuilder("https://minotar.net/armor/body/" + inputName + "/700.png", { "name": "skin.png" });

}
case "skin": {
const skinEmbed = new EmbedBuilder()
.setColor("Green")
.setAuthor({ "name": clientUsername, "iconURL": clientAvatar })
.setTitle(interaction.client.translate.commands.minecraft.skin_of)
.setImage("attachment://skin.png")
.setTimestamp();

await interaction.reply({ "embeds": [skinEmbed], "files": [skin] });
await interaction.reply({
"embeds": [skinEmbed],
"files": [
new AttachmentBuilder(
"https://minotar.net/armor/body/" + inputName + "/700.png",
{ "name": "skin.png" }
)
]
});
break;
}
}
}
}
12 changes: 8 additions & 4 deletions source/commands/information/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,34 +78,38 @@ module.exports.function.command = {
.setFooter({ "text": interaction.client.translate.commands.status.data_by_server, "iconURL": guildIcon });

switch (inputType) {
case "online":
case "online": {
const onlineCount = interaction.guild.members.cache.filter(members => members.presence ? members.presence.status === "online" : null).size;

statusEmbed.setDescription(interaction.client.translate.commands.status.online_status.replace("%s", onlineCount))
.setColor("Green");
await interaction.reply({ "embeds": [statusEmbed] });
break;
case "offline":
}
case "offline": {
const offlineCount = interaction.guild.members.cache.filter(members => members.presence ? members.presence.status === "offline" : "offline").size;

statusEmbed.setDescription(interaction.client.translate.commands.status.offline_status.replace("%s", offlineCount))
.setColor("Grey");
await interaction.reply({ "embeds": [statusEmbed] });
break;
case "idle":
}
case "idle": {
const idleCount = interaction.guild.members.cache.filter(members => members.presence ? members.presence.status === "idle" : null).size;

statusEmbed.setDescription(interaction.client.translate.commands.status.idle_status.replace("%s", idleCount))
.setColor("Yellow");
await interaction.reply({ "embeds": [statusEmbed] });
break;
case "dnd":
}
case "dnd": {
const dndCount = interaction.guild.members.cache.filter(members => members.presence ? members.presence.status === "dnd" : null).size;

statusEmbed.setDescription(interaction.client.translate.commands.status.dnd_status.replace("%s", dndCount))
.setColor("Red");
await interaction.reply({ "embeds": [statusEmbed] });
break;
}
}
}
}
10 changes: 5 additions & 5 deletions source/commands/information/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { EmbedBuilder, PermissionsBitField } = require("discord.js");
const { getDatabase, ref, child, set } = require("firebase/database");
const { dateFormat } = require("../../utils/miscUtils");
const { dateFormat, IDConvertor } = require("../../utils/miscUtils");

module.exports = {
"enable": true,
Expand Down Expand Up @@ -139,7 +139,7 @@ module.exports.function.command = {
let avatar = interaction.user.avatarURL() || interaction.client.translate.commands.user.unknown;
let bot = interaction.user.bot ? interaction.client.translate.commands.user.yes : interaction.client.translate.commands.user.none;
let createdAt = interaction.user.createdAt.toString() || interaction.client.translate.commands.user.unknown;
let createdTimestamp = dateFormat(interaction.user.createdTimestamp) || interaction.client.translate.commands.user.unknown;
let createdTimestamp = dateFormat(interaction.client, interaction.user.createdTimestamp) || interaction.client.translate.commands.user.unknown;
let defaultAvatarURL = interaction.user.defaultAvatarURL || interaction.client.translate.commands.user.unknown;
let discriminator = interaction.user.discriminator || interaction.client.translate.commands.user.unknown;
let id = interaction.user.id || interaction.client.translate.commands.user.unknown;
Expand All @@ -148,8 +148,8 @@ module.exports.function.command = {
let tag = interaction.user.tag || interaction.client.translate.commands.user.unknown;
let username = interaction.user.username || interaction.client.translate.commands.user.unknown;

const usersSnapshot = interaction.client.api.users
const usersRef = child(child(ref(getDatabase(), "Shioru/apps/discord/guilds"), interaction.guild.id), "data/users");
const usersSnapshot = interaction.client.api.users;
const usersRef = child(child(child(child(ref(getDatabase(), "projects"), IDConvertor(interaction.client.user.username)), "guilds"), interaction.guild.id), "data/users");
const clientUsername = interaction.client.user.username;
const clientAvatarURL = interaction.client.user.avatarURL();
const embed = new EmbedBuilder()
Expand All @@ -165,7 +165,7 @@ module.exports.function.command = {
avatar = inputMember.user.avatarURL() || interaction.client.translate.commands.user.unknown;
bot = inputMember.user.bot ? interaction.client.translate.commands.user.yes : interaction.client.translate.commands.user.none;
createdAt = inputMember.user.createdAt.toString() || interaction.client.translate.commands.user.unknown;
createdTimestamp = dateFormat(inputMember.user.createdTimestamp) || interaction.client.translate.commands.user.unknown;
createdTimestamp = dateFormat(interaction.client, inputMember.user.createdTimestamp) || interaction.client.translate.commands.user.unknown;
defaultAvatarURL = inputMember.user.defaultAvatarURL || interaction.client.translate.commands.user.unknown;
discriminator = inputMember.user.discriminator || interaction.client.translate.commands.user.unknown;
id = inputMember.user.id || interaction.client.translate.commands.user.unknown;
Expand Down
Loading

0 comments on commit f8ba390

Please sign in to comment.