Compare commits
2 commits
b5016bb39b
...
040ff1cc8c
Author | SHA1 | Date | |
---|---|---|---|
040ff1cc8c | |||
a9c076247b |
2 changed files with 86 additions and 25 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { Client, Message, MessageEmbed, TextBasedChannel } from 'discord.js';
|
import { Client, GuildMember, Message, MessageEmbed, TextBasedChannel } from 'discord.js';
|
||||||
import { getLocale } from '../../utils/locales';
|
import { getLocale } from '../../utils/locales';
|
||||||
import { isImage } from '../../utils/misc';
|
import { isImage, userWithNickname } 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,7 +66,10 @@ 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 || (!quoted_message.content && quoted_message.attachments.size == 0)) {
|
if (!quoted_message || (
|
||||||
|
!quoted_message.content &&
|
||||||
|
quoted_message.attachments.size == 0)
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,37 +79,77 @@ export default async (message: Message, client: Client) => {
|
||||||
// Remove undefined elements
|
// Remove undefined elements
|
||||||
).filter(Boolean);
|
).filter(Boolean);
|
||||||
|
|
||||||
messages.map(quoted_msg => {
|
const loc = getLocale(client, client.config.default_lang);
|
||||||
|
messages.map(quoted_post => {
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setColor('#2f3136')
|
.setColor('#2f3136')
|
||||||
.setAuthor({
|
.setAuthor({
|
||||||
name: 'Citation',
|
name: 'Citation',
|
||||||
iconURL: quoted_msg?.author.displayAvatarURL(),
|
iconURL: quoted_post?.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_msg?.attachments.size === 1 && isImage(quoted_msg.attachments.first()?.name as string)) {
|
if (quoted_post?.attachments.size) {
|
||||||
// Only contains one image
|
if (quoted_post?.attachments.size === 1 && isImage(
|
||||||
embed.setImage(quoted_msg.attachments.first()?.url as string);
|
quoted_post.attachments.first()?.name as string
|
||||||
} else {
|
)) {
|
||||||
// Contains more than one image or other files
|
// Only contains one image
|
||||||
let files = '';
|
embed.setImage(quoted_post.attachments.first()?.url as string);
|
||||||
quoted_msg?.attachments.forEach(attachment => {
|
} else {
|
||||||
files += `[${attachment.name}](${attachment.url}), `;
|
// Contains more than one image or other files
|
||||||
});
|
let files = '';
|
||||||
embed.addFields({
|
quoted_post?.attachments.forEach(attachment => {
|
||||||
name: 'Fichiers joints',
|
files += `[${attachment.name}](${attachment.url}), `;
|
||||||
value: `${files.slice(0, -2)}.`,
|
});
|
||||||
});
|
embed.addFields({
|
||||||
|
name: 'Fichiers joints',
|
||||||
|
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,3 +1,5 @@
|
||||||
|
import { GuildMember } from 'discord.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log module status.
|
* Log module status.
|
||||||
* @param {string} name Module name
|
* @param {string} name Module name
|
||||||
|
@ -58,3 +60,19 @@ 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