Compare commits

...

2 commits

Author SHA1 Message Date
Jonny_Bro (Nikita)
4b89b8f447
quote return 2024-10-04 12:22:35 +05:00
Jonny_Bro (Nikita)
80c93c95e0
fix quote deletion, move some functions 2024-10-04 12:13:41 +05:00
6 changed files with 63 additions and 53 deletions

View file

@ -15,6 +15,8 @@ class CommandHandler extends BaseEvent {
* @param {import("discord.js").CommandInteraction} interaction
*/
async execute(client, interaction) {
if (interaction.isButton() && interaction.customId === "quote_delete" && interaction.message.deletable) return interaction.message.delete();
const command = client.commands.get(interaction.commandName);
if (!command) return interaction.reply({ content: "Command not found!", ephemeral: true });
@ -27,7 +29,6 @@ class CommandHandler extends BaseEvent {
interaction.data = data;
if (interaction.isButton() && interaction.customId === "quote_delete" && interaction.message.deletable) return interaction.message.delete();
if (interaction.isAutocomplete()) return await command.autocompleteRun(client, interaction);
if (interaction.type !== InteractionType.ApplicationCommand || !interaction.isCommand()) return;
@ -47,13 +48,13 @@ class CommandHandler extends BaseEvent {
await interaction.data.user.save();
const achievementMessage = {
const message = {
content: interaction.user.toString(),
files: [{ name: "achievement_unlocked2.png", attachment: "./assets/img/achievements/achievement_unlocked2.png" }],
};
try {
await interaction.user.send(achievementMessage);
await interaction.user.send(message);
} catch (e) {
client.logger.warn("Failed to send achievement message to user:", e);
}

View file

@ -18,40 +18,37 @@ class MessageCreate extends BaseEvent {
*/
async execute(client, message) {
if (message.author.bot) return;
if (message.content.match(new RegExp(`^<@!?${client.user.id}>( |)$`))) return message.replyT("misc:HELLO_SERVER", null, { mention: true });
const data = await this.initializeMessageData(client, message);
message.data = data;
if (message.guild)
await this.handleGuildMessage(client, message);
return;
}
async initializeMessageData(client, message) {
const data = { user: await client.getUserData(message.author.id) };
if (message.guild) {
if (!message.member) await message.guild.members.fetch(message.author.id);
data.guild = await client.getGuildData(message.guildId);
data.member = await client.getMemberData(message.author.id, message.guildId);
}
message.data = data;
return data;
}
async handleGuildMessage(client, message) {
await updateXp(message);
if (message.content.match(/(https|http):\/\/(ptb\.|canary\.)?(discord.com)\/(channels)\/\d+\/\d+\/\d+/g)) await this.handleLinkQuote(client, message);
if (message.data.guild.plugins.automod.enabled && !message.data.guild.plugins.automod.ignored.includes(message.channelId)) await this.checkAutomod(message);
await this.checkAfkStatus(client, message);
await this.checkMentionedUsersAfk(client, message);
if (message.content.match(new RegExp(`^<@!?${client.user.id}>( |)$`))) return message.replyT("misc:HELLO_SERVER", null, { mention: true, locale: message.data.guild.language });
if (message.guild) {
await this.updateXp(message);
if (message.content.match(/(https|http):\/\/(ptb\.|canary\.)?(discord.com)\/(channels)\/\d+\/\d+\/\d+/g)) return await this.handleLinkQuote(client, message);
if (message.data.guild.plugins.automod.enabled && !message.data.guild.plugins.automod.ignored.includes(message.channelId)) await this.checkAutomod(message);
await this.checkAfkStatus(client, message);
await this.checkMentionedUsersAfk(client, message);
}
return;
}
/**
*
* @param {import("../base/Client")} client
* @param {import("discord.js").Message} message
*/
async handleLinkQuote(client, message) {
const link = message.content.match(/(https|http):\/\/(ptb\.|canary\.)?(discord.com)\/(channels)\/\d+\/\d+\/\d+/g)[0];
const ids = link.match(/\d+/g);
@ -94,6 +91,10 @@ class MessageCreate extends BaseEvent {
}
}
/**
*
* @param {import("discord.js").Message} message
*/
async checkAutomod(message) {
const inviteRegex = /(discord\.(gg|io|me|li)\/.+|discordapp\.com\/invite\/.+)/i;
if (inviteRegex.test(message.content) && !message.channel.permissionsFor(message.member).has(PermissionsBitField.Flags.ManageMessages)) {
@ -102,6 +103,11 @@ class MessageCreate extends BaseEvent {
}
}
/**
*
* @param {import("../base/Client")} client
* @param {import("discord.js").Message} message
*/
async checkAfkStatus(client, message) {
if (message.data.user.afk) {
message.data.user.afk = null;
@ -111,6 +117,11 @@ class MessageCreate extends BaseEvent {
}
}
/**
*
* @param {import("../base/Client")} client
* @param {import("discord.js").Message} message
*/
async checkMentionedUsersAfk(client, message) {
for (const user of message.mentions.users.values()) {
const userData = await client.getUserData(user.id);
@ -118,37 +129,35 @@ class MessageCreate extends BaseEvent {
if (userData.afk) message.replyT("general/afk:IS_AFK", { user: user.getUsername(), message: userData.afk }, { ephemeral: true });
}
}
}
/**
*
* @param {import("../base/Client")} client
* @param {import("discord.js").Message} message
* @returns
*/
async function updateXp(message) {
const memberData = message.data.member;
const isInCooldown = xpCooldown[message.author.id];
/**
*
* @param {import("discord.js").Message} message
*/
async updateXp(message) {
const memberData = message.data.member;
const isInCooldown = xpCooldown[message.author.id];
if (isInCooldown && isInCooldown > Date.now()) return;
if (isInCooldown && isInCooldown > Date.now()) return;
const toWait = Date.now() + 60 * 1000; // 1 min
xpCooldown[message.author.id] = toWait;
const toWait = Date.now() + 60 * 1000; // 1 min
xpCooldown[message.author.id] = toWait;
const won = message.client.functions.randomNum(1, 2);
const newXp = memberData.exp + won;
const neededXp = 5 * memberData.level ** 2 + 80 * memberData.level + 100;
const won = message.client.functions.randomNum(1, 2);
const newXp = memberData.exp + won;
const neededXp = 5 * memberData.level ** 2 + 80 * memberData.level + 100;
if (newXp > neededXp) {
memberData.level += 1;
memberData.exp = 0;
if (newXp > neededXp) {
memberData.level += 1;
memberData.exp = 0;
message.replyT("misc:LEVEL_UP", { level: memberData.level }, { mention: false });
} else {
memberData.exp = newXp;
message.replyT("misc:LEVEL_UP", { level: memberData.level }, { mention: false });
} else {
memberData.exp = newXp;
}
await memberData.save();
}
await memberData.save();
}
module.exports = MessageCreate;

View file

@ -41,7 +41,7 @@
"MONITORING": {
"DELETE": {
"TITLE": "{{user}} deleted a message!",
"TITLE": "{{user}}'s message was deleted!",
"DESCRIPTION": "Message content was: ```{{content}}```\nChannel: {{channel}}\nTime created: {{time}}"
},
"UPDATE": {

View file

@ -41,7 +41,7 @@
"MONITORING": {
"DELETE": {
"TITLE": "{{user}} удалил сообщение!",
"TITLE": "Сообщение {{user}} удалено!",
"DESCRIPTION": "Содержимое сообщения было: ```{{content}}```\nКанал: {{channel}}\nВремя создания: {{time}}"
},
"UPDATE": {

View file

@ -41,7 +41,7 @@
"MONITORING": {
"DELETE": {
"TITLE": "{{user}} видалив повідомлення!",
"TITLE": "Повідомлення {{user}} видалено!",
"DESCRIPTION": "Вміст повідомлення було: ```{{content}}```\nКанал: {{channel}}\nЧас створення: {{time}}"
},
"UPDATE": {