From f1366cc9ec447e571a113d76e79391a76cf97ac5 Mon Sep 17 00:00:00 2001 From: "Jonny_Bro (Nikita)" Date: Sat, 21 Oct 2023 21:15:25 +0500 Subject: [PATCH] change domain + rewrite quotes --- commands/General/shorturl.js | 2 +- events/MessageHandler.js | 40 +++++++++++++++++++++--------------- helpers/cleanup.js | 16 +++++++++++++++ languages/en-US/misc.json | 3 ++- languages/ru-RU/misc.json | 3 ++- languages/uk-UA/misc.json | 3 ++- 6 files changed, 46 insertions(+), 21 deletions(-) diff --git a/commands/General/shorturl.js b/commands/General/shorturl.js index e7ef2e94..068ff844 100644 --- a/commands/General/shorturl.js +++ b/commands/General/shorturl.js @@ -47,7 +47,7 @@ class Shorturl extends BaseCommand { */ async execute(client, interaction) { const url = interaction.options.getString("url"); - const res = await fetch(`http://jababot.ru/yourls/yourls-api.php?signature=${client.config.apiKeys.jababot_yourls}&action=shorturl&url=${encodeURIComponent(url)}&format=json`).then(res => res.json()); + const res = await fetch(`http://plsgo.ru/yourls-api.php?signature=${client.config.apiKeys.jababot_yourls}&action=shorturl&url=${encodeURIComponent(url)}&format=json`).then(res => res.json()); interaction.reply({ content: `<${res.shorturl}>`, diff --git a/events/MessageHandler.js b/events/MessageHandler.js index 90b7dac5..cc533745 100644 --- a/events/MessageHandler.js +++ b/events/MessageHandler.js @@ -39,7 +39,7 @@ class MessageCreate extends BaseEvent { if (message.guild) { await updateXp(client, message, data.memberData); - if (message.content.includes("discord.com/channels/")) { + if (message.content.match(/(https|http):\/\/(ptb\.|canary\.)?(discord.com)\/(channels)\/\d+\/\d+\/\d+/g)) { const link = message.content.match(/(https|http):\/\/(ptb\.|canary\.)?(discord.com)\/(channels)\/\d+\/\d+\/\d+/g)[0], ids = link.match(/\d+/g), channelId = ids[1], @@ -54,32 +54,34 @@ class MessageCreate extends BaseEvent { iconURL: "https://wynem.com/assets/images/icons/quote.webp", }) .setThumbnail(msg.author.displayAvatarURL()) - .setDescription(msg.content !== "" ? msg.content : `*${message.translate("common:MISSING")}*`) - .addFields([ - { - name: message.translate("misc:QUOTE_ATTACHED"), - value: - msg.attachments.size > 0 - ? msg.attachments - .map(a => { - return `[${a.name}](${a.url})`; - }) - .join("\n") - : `*${message.translate("common:MISSING")}*`, - }, - ]) .setFooter({ text: message.translate("misc:QUOTE_FOOTER", { user: message.author.getUsername() }), }) .setColor(client.config.embed.color) .setTimestamp(msg.createdTimestamp); + if (msg.content !== "") embed.addFields([ + { + name: message.translate("misc:QUOTE_CONTENT"), + value: msg.content, + }, + ]); + + if (msg.attachments.size > 0) { + embed.addFields([ + { + name: message.translate("misc:QUOTE_ATTACHED"), + value: msg.attachments.map(a => { return `[${a.name}](${a.url})`; }).join(", "), + }, + ]); + } + const row = new ActionRowBuilder().addComponents( new ButtonBuilder().setLabel(message.translate("misc:QUOTE_JUMP")).setStyle(ButtonStyle.Link).setURL(msg.url), new ButtonBuilder().setCustomId("quote_delete").setEmoji("1102200816582000750").setStyle(ButtonStyle.Danger), ); - const reply = await message.reply({ + await message.reply({ embeds: [embed], components: [row], }); @@ -88,7 +90,11 @@ class MessageCreate extends BaseEvent { const collector = message.channel.createMessageComponentCollector({ filter, time: 60 * 1000 }); collector.on("collect", async i => { - if (i.isButton() && i.customId === "quote_delete") if (reply.deletable) reply.delete(); + if (i.isButton() && i.customId === "quote_delete") { + console.log(i.message); + + if (i.message.deletable) i.message.delete(); + } }); } diff --git a/helpers/cleanup.js b/helpers/cleanup.js index 0c547df6..3c9521a8 100644 --- a/helpers/cleanup.js +++ b/helpers/cleanup.js @@ -44,6 +44,22 @@ module.exports.init = async function (client) { client.databaseCache.users.delete(u.id); client.usersData.deleteOne({ id: u.id }); client.logger.log(`Removed from database deleted user - ID: ${u.id} Username: ${u.username}`); + + client.usersData.save(); + } + }); + } + }); + + client.membersData.find({}, function (err, res) { + for (const user of res) { + client.users.fetch(user.id).then(u => { + if (u.username.match(/.*Deleted User.* [A-z0-9]+/g)) { + client.databaseCache.members.delete(u.id); + client.membersData.deleteOne({ id: u.id }); + client.logger.log(`Removed from database deleted user - ID: ${u.id} Username: ${u.username}`); + + client.membersData.save(); } }); } diff --git a/languages/en-US/misc.json b/languages/en-US/misc.json index 7e2cbb6a..35d476b5 100644 --- a/languages/en-US/misc.json +++ b/languages/en-US/misc.json @@ -16,8 +16,9 @@ "TIMED_OUT": "Time out.", "JUMP_TO_PAGE": "Specify the page you want to jump to (maximum **{{length}}**):", "QUOTE_TITLE": "Message from {{user}}", + "QUOTE_CONTENT": "Content", "QUOTE_ATTACHED": "Attached files", - "QUOTE_JUMP": "Jump", + "QUOTE_JUMP": "Jump to", "QUOTE_FOOTER": "Quoted by {{user}}", "PERMISSIONS": { diff --git a/languages/ru-RU/misc.json b/languages/ru-RU/misc.json index 7a9d84e3..2b79f536 100644 --- a/languages/ru-RU/misc.json +++ b/languages/ru-RU/misc.json @@ -16,8 +16,9 @@ "TIMED_OUT": "Время вышло", "JUMP_TO_PAGE": "Укажите страницу к которой хотите перейти (максимум **{{length}}**):", "QUOTE_TITLE": "Сообщение от {{user}}", + "QUOTE_CONTENT": "Содержимое", "QUOTE_ATTACHED": "Прикреплённые файлы", - "QUOTE_JUMP": "Перейти", + "QUOTE_JUMP": "Перейти к", "QUOTE_FOOTER": "Цитировал {{user}}", "PERMISSIONS": { diff --git a/languages/uk-UA/misc.json b/languages/uk-UA/misc.json index 6cb6a532..e222cff5 100644 --- a/languages/uk-UA/misc.json +++ b/languages/uk-UA/misc.json @@ -16,8 +16,9 @@ "TIMED_OUT": "Час вийшов", "JUMP_TO_PAGE": "Вкажіть сторінку, до якої хочете перейти (максимум **{{length}}**):", "QUOTE_TITLE": "Повідомлення від {{user}}", + "QUOTE_CONTENT": "Вміст", "QUOTE_ATTACHED": "Прикріплені файли", - "QUOTE_JUMP": "Перейти", + "QUOTE_JUMP": "Перейти до", "QUOTE_FOOTER": "Цитував {{user}}", "PERMISSIONS": {