Skip to content

Commit

Permalink
Fixed the issue of client receiving incorrect information.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maseshi committed May 16, 2022
1 parent 0381c77 commit 59defea
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 66 deletions.
4 changes: 1 addition & 3 deletions source/events/channel/channelCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { getDatabase, ref, child, get, set } = require("firebase/database");
const settingsData = require("../../extras/settingsData");
const catchError = require("../../extras/catchError");

module.exports = (channel) => {
const client = channel.client;

module.exports = (client, channel) => {
if (client.mode === "start") {
settingsData(client, channel.guild, module.exports, channel);
if (client.config.worker !== 1) return;
Expand Down
4 changes: 1 addition & 3 deletions source/events/channel/channelDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { getDatabase, ref, child, get, set } = require("firebase/database");
const settingsData = require("../../extras/settingsData");
const catchError = require("../../extras/catchError");

module.exports = (channel) => {
const client = channel.client;

module.exports = (client, channel) => {
if (client.mode === "start") {
settingsData(client, channel.guild, module.exports, channel);
if (client.config.worker !== 1) return;
Expand Down
4 changes: 1 addition & 3 deletions source/events/channel/channelPinsUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { getDatabase, ref, child, get, set } = require("firebase/database");
const settingsData = require("../../extras/settingsData");
const catchError = require("../../extras/catchError");

module.exports = (channel, time) => {
const client = channel.client;

module.exports = (client, channel, time) => {
if (client.mode === "start") {
settingsData(client, channel.guild, module.exports, (channel, time));
if (client.config.worker !== 1) return;
Expand Down
4 changes: 1 addition & 3 deletions source/events/channel/channelUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { getDatabase, ref, child, get, set } = require("firebase/database");
const settingsData = require("../../extras/settingsData");
const catchError = require("../../extras/catchError");

module.exports = (oldChannel, newChannel) => {
const client = newChannel.client;

module.exports = (client, oldChannel, newChannel) => {
if (client.mode === "start") {
settingsData(client, newChannel.guild, module.exports, (oldChannel, newChannel));
if (client.config.worker !== 1) return;
Expand Down
2 changes: 1 addition & 1 deletion source/events/client/debug.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const logGenerator = require("../../extras/logGenerator");

module.exports = (info) => {
module.exports = (client, info) => {
logGenerator("debug", info);
};
2 changes: 1 addition & 1 deletion source/events/client/error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const logGenerator = require("../../extras/logGenerator");

module.exports = (error) => {
module.exports = (client, error) => {
logGenerator("error", error);
};
2 changes: 1 addition & 1 deletion source/events/client/warn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const logGenerator = require("../../extras/logGenerator");

module.exports = (info) => {
module.exports = (client, info) => {
logGenerator("warn", info);
};
4 changes: 1 addition & 3 deletions source/events/emoji/emojiCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { getDatabase, ref, child, get, set } = require("firebase/database");
const settingsData = require("../../extras/settingsData");
const catchError = require("../../extras/catchError");

module.exports = (emoji) => {
const client = emoji.client;

module.exports = (client, emoji) => {
if (client.mode === "start") {
settingsData(client, emoji.guild, module.exports, emoji);
if (client.config.worker !== 1) return;
Expand Down
4 changes: 1 addition & 3 deletions source/events/emoji/emojiDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { getDatabase, ref, child, get, set } = require("firebase/database");
const settingsData = require("../../extras/settingsData");
const catchError = require("../../extras/catchError");

module.exports = (emoji) => {
const client = emoji.client;

module.exports = (client, emoji) => {
if (client.mode === "start") {
settingsData(client, emoji.guild, module.exports, emoji);
if (client.config.worker !== 1) return;
Expand Down
4 changes: 1 addition & 3 deletions source/events/emoji/emojiUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { getDatabase, ref, child, get, set } = require("firebase/database");
const settingsData = require("../../extras/settingsData");
const catchError = require("../../extras/catchError");

module.exports = (oldEmoji, newEmoji) => {
const client = newEmoji.client;

module.exports = (client, oldEmoji, newEmoji) => {
if (client.mode === "start") {
settingsData(client, newEmoji.guild, module.exports, (oldEmoji, newEmoji));
if (client.config.worker !== 1) return;
Expand Down
4 changes: 1 addition & 3 deletions source/events/guild/guildCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { MessageAttachment } = require("discord.js");
const settingsData = require("../../extras/settingsData");
const catchError = require("../../extras/catchError");

module.exports = async (guild) => {
const client = guild.client;

module.exports = (client, guild) => {
if (client.mode === "start") {
settingsData(client, guild, module.exports, guild);
if (client.config.worker !== 1) return;
Expand Down
4 changes: 1 addition & 3 deletions source/events/guild/guildMemberAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { getDatabase, ref, child, get, set } = require("firebase/database");
const settingsData = require("../../extras/settingsData");
const catchError = require("../../extras/catchError");

module.exports = (member) => {
const client = member.client;

module.exports = (client, member) => {
if (member.user.bot) return;
if (client.mode === "start") {
settingsData(client, member.guild, module.exports, member);
Expand Down
4 changes: 1 addition & 3 deletions source/events/guild/guildMemberRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { getDatabase, ref, child, get, set } = require("firebase/database");
const settingsData = require("../../extras/settingsData");
const catchError = require("../../extras/catchError");

module.exports = (member) => {
const client = member.client;

module.exports = (client, member) => {
if (member.user.bot) return;
if (client.mode === "start") {
settingsData(client, member.guild, module.exports, member);
Expand Down
21 changes: 11 additions & 10 deletions source/events/interaction/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
const { getDatabase, ref, update, get } = require("firebase/database");
const catchError = require("../../extras/catchError");

module.exports = async (interaction) => {
module.exports = async (client, interaction) => {
if (!interaction.isCommand()) return;

const command = interaction.client.interaction.get(interaction.commandName);
const command = client.interaction.get(interaction.commandName);

if (!command) return;

// Check that members have the permissions to use the application or not.
if (!interaction.member.permissions.has("USE_APPLICATION_COMMANDS")) {
return await interaction.reply(interaction.client.translate.events.interactionCreate.no_permission);
return await interaction.reply(client.translate.events.interactionCreate.no_permission);
}

// Check the permissions of the command for the user.
if (command.help.userPermissions) {
if (!interaction.member.permissions.has(command.help.userPermissions)) {
return await interaction.reply(interaction.client.translate.events.interactionCreate.user_is_not_allowed).replace("%s", command.help.userPermissions.join());
return await interaction.reply(client.translate.events.interactionCreate.user_is_not_allowed).replace("%s", command.help.userPermissions.join());
}
}

// Check the permissions of the command for the bot.
if (command.help.clientPermissions) {
if (!interaction.guild.me.permissions.has(command.help.clientPermissions)) {
return await interaction.reply(interaction.client.translate.events.interactionCreate.client_is_not_allowed).replace("%s", command.help.clientPermissions.join());
return await interaction.reply(client.translate.events.interactionCreate.client_is_not_allowed).replace("%s", command.help.clientPermissions.join());
}
}

Expand All @@ -33,9 +34,9 @@ module.exports = async (interaction) => {

// Stores information when the bot is working properly.
if (client.mode === "start") {
get(ref(getDatabase(), 'Shioru/data/survey/working'), (snapshot) => {
if (snapshot.exists()) {
let working = snapshot.val();
get(ref(getDatabase(), 'Shioru/data/survey')).then((snapshot) => {
if (snapshot.exists()) {
let working = snapshot.val().working;

update(ref(getDatabase(), 'Shioru/data/survey'), {
"working": (working + 1)
Expand All @@ -45,9 +46,9 @@ module.exports = async (interaction) => {
"working": 1
});
}
});
});
}
} catch (error) {
catchError(interaction.client, interaction, interaction.commandName, error);
catchError(client, interaction, interaction.commandName, error);
}
}
39 changes: 18 additions & 21 deletions source/events/message/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ const settingsData = require("../../extras/settingsData");
const catchError = require("../../extras/catchError");
const ansiColor = require("../../extras/ansiColor")

module.exports = async (message) => {
const client = message.client;

module.exports = (client, message) => {
let command = "";
const round = 3;
const defaultPrefix = "S";

let command = "";
const prefix = client.config.prefix;
const mentioned = message.content.startsWith("<@!" + client.user.id + ">") || message.content.startsWith("<@" + client.user.id + ">");
const args = message.content.slice(prefix.length).trim().split(/ +/g);
Expand Down Expand Up @@ -60,7 +57,7 @@ module.exports = async (message) => {

// If the members remember the prefix, then start counting again.
client.temp.round = 0;

message.channel.sendTyping();

// Check the permissions of the command for the user.
Expand All @@ -81,22 +78,22 @@ module.exports = async (message) => {
command.run(client, message, args);

// Stores information when the bot is working properly.
if (client.mode === "start") {
get(ref(getDatabase(), 'Shioru/data/survey/working'), (snapshot) => {
if (snapshot.exists()) {
let working = snapshot.val();
if (client.mode === "start") {
get(ref(getDatabase(), 'Shioru/data/survey')).then((snapshot) => {
if (snapshot.exists()) {
let working = snapshot.val().working;

update(ref(getDatabase(), 'Shioru/data/survey'), {
"working": (working + 1)
});
} else {
update(ref(getDatabase(), 'Shioru/data/survey'), {
"working": 1
});
}
});
}
} catch(error) {
update(ref(getDatabase(), 'Shioru/data/survey'), {
"working": (working + 1)
});
} else {
update(ref(getDatabase(), 'Shioru/data/survey'), {
"working": 1
});
}
});
}
} catch (error) {
catchError(client, message, command.help.name, error);
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/extras/settingsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = (client, guild, exports, callback) => {
client.translate = require("../languages/" + lang + ".json");
if (!client.temp.set) {
client.temp.set = 1;
return exports(callback);
return exports(client, callback);
}
} else {
set(child(childRef, "config"), {
Expand Down
2 changes: 1 addition & 1 deletion source/handlers/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = (client) => {
"text": "Loading event " + eventName + " in category " + dirs
});

client.on(eventName, pull.bind())
client.on(eventName, pull.bind(null, client))
delete require.cache[require.resolve("../events/" + dirs + "/" + file)];
} catch (error) {
spinnies.fail("events-loading", {
Expand Down

0 comments on commit 59defea

Please sign in to comment.