Compare commits
No commits in common. "040ff1cc8cc81072140f4d0145e4147b8e8de32b" and "b5016bb39b5aad08abab0bbe6abebdd3fe900836" have entirely different histories.
040ff1cc8c
...
b5016bb39b
2 changed files with 24 additions and 85 deletions
|
@ -1,6 +1,6 @@
|
|||
import { Client, GuildMember, Message, MessageEmbed, TextBasedChannel } from 'discord.js';
|
||||
import { Client, Message, MessageEmbed, TextBasedChannel } from 'discord.js';
|
||||
import { getLocale } from '../../utils/locales';
|
||||
import { isImage, userWithNickname } from '../../utils/misc';
|
||||
import { isImage } from '../../utils/misc';
|
||||
import { showDate } from '../../utils/time';
|
||||
|
||||
/** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-messageCreate */
|
||||
|
@ -66,10 +66,7 @@ export default async (message: Message, client: Client) => {
|
|||
.catch(() => undefined);
|
||||
|
||||
// If message doesn't exist or empty
|
||||
if (!quoted_message || (
|
||||
!quoted_message.content &&
|
||||
quoted_message.attachments.size == 0)
|
||||
) {
|
||||
if (!quoted_message || (!quoted_message.content && quoted_message.attachments.size == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -79,26 +76,29 @@ export default async (message: Message, client: Client) => {
|
|||
// Remove undefined elements
|
||||
).filter(Boolean);
|
||||
|
||||
const loc = getLocale(client, client.config.default_lang);
|
||||
messages.map(quoted_post => {
|
||||
messages.map(quoted_msg => {
|
||||
const embed = new MessageEmbed()
|
||||
.setColor('#2f3136')
|
||||
.setAuthor({
|
||||
name: 'Citation',
|
||||
iconURL: quoted_post?.author.displayAvatarURL(),
|
||||
iconURL: quoted_msg?.author.displayAvatarURL(),
|
||||
})
|
||||
.setFooter({
|
||||
text: `Posté le ${showDate(
|
||||
client.config.default_lang,
|
||||
getLocale(client, client.config.default_lang),
|
||||
quoted_msg?.createdAt as Date)
|
||||
}`,
|
||||
});
|
||||
|
||||
// Handle attachments
|
||||
if (quoted_post?.attachments.size) {
|
||||
if (quoted_post?.attachments.size === 1 && isImage(
|
||||
quoted_post.attachments.first()?.name as string
|
||||
)) {
|
||||
if (quoted_msg?.attachments.size === 1 && isImage(quoted_msg.attachments.first()?.name as string)) {
|
||||
// Only contains one image
|
||||
embed.setImage(quoted_post.attachments.first()?.url as string);
|
||||
embed.setImage(quoted_msg.attachments.first()?.url as string);
|
||||
} else {
|
||||
// Contains more than one image or other files
|
||||
let files = '';
|
||||
quoted_post?.attachments.forEach(attachment => {
|
||||
quoted_msg?.attachments.forEach(attachment => {
|
||||
files += `[${attachment.name}](${attachment.url}), `;
|
||||
});
|
||||
embed.addFields({
|
||||
|
@ -106,49 +106,6 @@ export default async (message: Message, client: Client) => {
|
|||
value: `${files.slice(0, -2)}.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Description
|
||||
embed.setDescription(quoted_post?.content ?? '');
|
||||
|
||||
// Footer
|
||||
let footer = `Posté le ${showDate(
|
||||
client.config.default_lang,
|
||||
loc,
|
||||
quoted_post?.createdAt as Date
|
||||
)}`;
|
||||
if (quoted_post?.editedAt) {
|
||||
footer += ` et modifié le ${showDate(
|
||||
client.config.default_lang,
|
||||
loc,
|
||||
quoted_post.editedAt
|
||||
)}`;
|
||||
}
|
||||
|
||||
let author = 'Auteur';
|
||||
if (message.author == quoted_post?.author) {
|
||||
author += ' & Citateur';
|
||||
} else {
|
||||
footer += `\nCité par ${userWithNickname(
|
||||
message.guild?.members.cache.get(message.author.id) as GuildMember
|
||||
) ?? '?'} le ${showDate(
|
||||
client.config.default_lang,
|
||||
loc,
|
||||
message.createdAt
|
||||
)}`;
|
||||
}
|
||||
|
||||
embed.setFooter({
|
||||
text: footer,
|
||||
iconURL: message.author.avatarURL() ?? undefined,
|
||||
});
|
||||
|
||||
// Info about the post
|
||||
embed.addField(author, `${quoted_post?.author}`, true);
|
||||
embed.addField(
|
||||
'Message', `${quoted_post?.channel} - [Lien Message](${quoted_post?.url})`,
|
||||
true
|
||||
);
|
||||
|
||||
return message.channel.send({ embeds: [embed] });
|
||||
});
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { GuildMember } from 'discord.js';
|
||||
|
||||
/**
|
||||
* Log module status.
|
||||
* @param {string} name Module name
|
||||
|
@ -60,19 +58,3 @@ export const isImage = (filename: string) => {
|
|||
/jpg|jpeg|png|webp|gif/
|
||||
));
|
||||
};
|
||||
|
||||
/**
|
||||
* String with pseudo and nickname if available.
|
||||
* @param member Member
|
||||
* @returns string
|
||||
*/
|
||||
export const userWithNickname = (member: GuildMember) => {
|
||||
if (!member) {
|
||||
return undefined;
|
||||
}
|
||||
if (member.nickname) {
|
||||
return `${member.nickname} (${member.user.tag})`;
|
||||
} else {
|
||||
return member.user.tag;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue