mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-21 20:54:58 +05:00
fix quote deletion, move some functions
This commit is contained in:
parent
6967581788
commit
80c93c95e0
3 changed files with 60 additions and 50 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -18,18 +18,7 @@ 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) {
|
||||
|
@ -38,20 +27,28 @@ class MessageCreate extends BaseEvent {
|
|||
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)) 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;
|
||||
|
|
Loading…
Reference in a new issue