mobile update

This commit is contained in:
2026-08-11 12:30:43 +02:00
parent 878e8fcdaa
commit c99a96c201
6 changed files with 373 additions and 256 deletions
+111 -57
View File
@@ -1,76 +1,130 @@
const { EmbedBuilder, MessageFlags } = require("discord.js")
const { client, mClient } = require("../../../index")
const { EmbedBuilder, MessageFlags } = require("discord.js");
const { client, mClient } = require("../../../index");
module.exports = {
name: 'quotesadd',
description: 'adds a quote to the database by replying to the message',
category: 'Quotes',
aliases: ['qadd', 'qa'],
async execute(message, args) {
const refMessage = message.reference // message to be quoted has been replied to
const refMessageId = refMessage.messageId
const refChannelId = refMessage.channelId
const refGuildId = refMessage.guildId
var msgData = {}
var refData = {}
const quoteGuild = await client.guilds.fetch(refGuildId)
const quoteChannel = await quoteGuild.channels.fetch(refChannelId)
const quoteMessage = await quoteChannel.messages.fetch(refMessageId)
name: "quotesadd",
description: "Adds a quote to the database by replying to a message.",
aliases: ["qadd", "qa"],
async execute(message) {
// Ensure the command is used as a reply.
if (!message.reference?.messageId) {
return message.reply({
content: "Please reply to the message you want to quote.",
flags: MessageFlags.Ephemeral
});
}
msgData = {
const { messageId, channelId, guildId } = message.reference;
let quoteMessage;
let quoteChannel;
let quoteGuild;
try {
quoteGuild = await client.guilds.fetch(guildId);
quoteChannel = await quoteGuild.channels.fetch(channelId);
quoteMessage = await quoteChannel.messages.fetch(messageId);
} catch (err) {
console.error(err);
return message.reply({
content: "Unable to fetch the quoted message.",
flags: MessageFlags.Ephemeral
});
}
const msgData = {
content: quoteMessage.content,
author: await quoteMessage.author,
reference: await quoteMessage.reference,
embed: await quoteMessage.embeds ? 'embed' : null
} // debug
if (msgData.reference) {
const quoteRefGuild = await client.guilds.fetch(msgData.reference.guildId)
const quoteRefChannel = await quoteRefGuild.channels.fetch(msgData.reference.channelId)
const quoteRefMessage = await quoteRefChannel.messages.fetch(msgData.reference.messageId)
author: quoteMessage.author,
hasEmbed: quoteMessage.embeds.length > 0,
reference: quoteMessage.reference
};
// Only populated if the quoted message is itself a reply.
let refData = null;
refData = {
content: quoteRefMessage.content,
author: await quoteRefMessage.author,
embed: await quoteRefMessage.embeds.length > 0 ? 'embed' : null
if (msgData.reference?.messageId) {
try {
const refGuild = await client.guilds.fetch(msgData.reference.guildId);
const refChannel = await refGuild.channels.fetch(msgData.reference.channelId);
const refMessage = await refChannel.messages.fetch(msgData.reference.messageId);
refData = {
content: refMessage.content,
author: refMessage.author,
hasEmbed: refMessage.embeds.length > 0
};
} catch (err) {
// Referenced message couldn't be fetched (deleted, inaccessible, etc.)
refData = null;
}
}
const db = mClient.db(process.env.M_DB)
const quotesColl = db.collection('items_quotes')
const found = await quotesColl.findOne({ messageID: quoteMessage.id })
if (found) { return await message.reply({ content: 'Quote Already in Database', flags: MessageFlags.Ephemeral }) }
await quotesColl.findOneAndUpdate({ messageID: quoteMessage.id }, {
$set: {
messageID: quoteMessage.id,
channelID: quoteChannel.id,
guildID: quoteGuild.id,
userID: msgData.author.id,
count: 0
}
}, { upsert: true })
const db = mClient.db(process.env.M_DB);
const quotesColl = db.collection("items_quotes");
var description = ''
const existing = await quotesColl.findOne({
messageID: quoteMessage.id
});
if (existing) {
return message.reply({
content: "Quote already exists in the database.",
flags: MessageFlags.Ephemeral
});
}
await quotesColl.findOneAndUpdate(
{ messageID: quoteMessage.id },
{
$set: {
messageID: quoteMessage.id,
channelID: quoteChannel.id,
guildID: quoteGuild.id,
userID: msgData.author.id,
count: 0
}
},
{ upsert: true }
);
const messageLink = `https://discord.com/channels/${quoteGuild.id}/${quoteChannel.id}/${quoteMessage.id}`;
let description = "";
// Only show the replied-to message if one actually exists.
if (refData) {
description += `> ${refData.author}`
if (refData.embed) {
description += '*an embed / a command* '
description += `> ${refData.author} `;
if (refData.hasEmbed) {
description += "*an embed / a command*";
} else if (refData.content) {
description += refData.content;
} else {
description += refData.content
description += "*no text*";
}
description += `\r\n↳`
description += "\n↳ ";
}
const messageLink = `https://discord.com/channels/${quoteGuild.id}/${quoteChannel.id}/${quoteMessage.id}/`
description += `${msgData.author} ${msgData.content}\r\n\r\n${messageLink}`
let timestamp = new Date(message.createdTimestamp)
let footer = timestamp.toDateString().toString()
description += `${msgData.author} `;
if (msgData.hasEmbed && !msgData.content) {
description += "*an embed / a command*";
} else {
description += msgData.content || "*no text*";
}
description += `\n\n${messageLink}`;
const footer = `${new Date(quoteMessage.createdTimestamp).toDateString()} #${quoteMessage.id}`;
const embed = new EmbedBuilder()
.setThumbnail(msgData.author.displayAvatarURL())
.setTitle("- Quote Added! -")
.setURL(messageLink)
.setTitle(`- Quote Added! -`)
.setThumbnail(msgData.author.displayAvatarURL())
.setDescription(description)
.setFooter({ text: (footer + ' #' + quoteMessage.id) })
await message.reply({ embeds: [embed] })
.setFooter({ text: footer });
return message.reply({ embeds: [embed] });
}
}
};