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 { getLocale } from '../../utils/locales';
|
||||||
import { isImage, userWithNickname } from '../../utils/misc';
|
import { isImage } from '../../utils/misc';
|
||||||
import { showDate } from '../../utils/time';
|
import { showDate } from '../../utils/time';
|
||||||
|
|
||||||
/** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-messageCreate */
|
/** 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);
|
.catch(() => undefined);
|
||||||
|
|
||||||
// If message doesn't exist or empty
|
// If message doesn't exist or empty
|
||||||
if (!quoted_message || (
|
if (!quoted_message || (!quoted_message.content && quoted_message.attachments.size == 0)) {
|
||||||
!quoted_message.content &&
|
|
||||||
quoted_message.attachments.size == 0)
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,26 +76,29 @@ export default async (message: Message, client: Client) => {
|
||||||
// Remove undefined elements
|
// Remove undefined elements
|
||||||
).filter(Boolean);
|
).filter(Boolean);
|
||||||
|
|
||||||
const loc = getLocale(client, client.config.default_lang);
|
messages.map(quoted_msg => {
|
||||||
messages.map(quoted_post => {
|
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setColor('#2f3136')
|
.setColor('#2f3136')
|
||||||
.setAuthor({
|
.setAuthor({
|
||||||
name: 'Citation',
|
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
|
// Handle attachments
|
||||||
if (quoted_post?.attachments.size) {
|
if (quoted_msg?.attachments.size === 1 && isImage(quoted_msg.attachments.first()?.name as string)) {
|
||||||
if (quoted_post?.attachments.size === 1 && isImage(
|
|
||||||
quoted_post.attachments.first()?.name as string
|
|
||||||
)) {
|
|
||||||
// Only contains one image
|
// Only contains one image
|
||||||
embed.setImage(quoted_post.attachments.first()?.url as string);
|
embed.setImage(quoted_msg.attachments.first()?.url as string);
|
||||||
} else {
|
} else {
|
||||||
// Contains more than one image or other files
|
// Contains more than one image or other files
|
||||||
let files = '';
|
let files = '';
|
||||||
quoted_post?.attachments.forEach(attachment => {
|
quoted_msg?.attachments.forEach(attachment => {
|
||||||
files += `[${attachment.name}](${attachment.url}), `;
|
files += `[${attachment.name}](${attachment.url}), `;
|
||||||
});
|
});
|
||||||
embed.addFields({
|
embed.addFields({
|
||||||
|
@ -106,49 +106,6 @@ export default async (message: Message, client: Client) => {
|
||||||
value: `${files.slice(0, -2)}.`,
|
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] });
|
return message.channel.send({ embeds: [embed] });
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import { GuildMember } from 'discord.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log module status.
|
* Log module status.
|
||||||
* @param {string} name Module name
|
* @param {string} name Module name
|
||||||
|
@ -60,19 +58,3 @@ export const isImage = (filename: string) => {
|
||||||
/jpg|jpeg|png|webp|gif/
|
/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