Compare commits
No commits in common. "b5016bb39b5aad08abab0bbe6abebdd3fe900836" and "a5b6924ddc3ba4d46b80d8a0f8288b7a71359f24" have entirely different histories.
b5016bb39b
...
a5b6924ddc
2 changed files with 4 additions and 43 deletions
|
@ -1,6 +1,5 @@
|
||||||
import { Client, 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 } 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 */
|
||||||
|
@ -76,37 +75,21 @@ export default async (message: Message, client: Client) => {
|
||||||
// Remove undefined elements
|
// Remove undefined elements
|
||||||
).filter(Boolean);
|
).filter(Boolean);
|
||||||
|
|
||||||
messages.map(quoted_msg => {
|
messages.map(valid_message => {
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setColor('#2f3136')
|
.setColor('#2f3136')
|
||||||
.setAuthor({
|
.setAuthor({
|
||||||
name: 'Citation',
|
name: 'Citation',
|
||||||
iconURL: quoted_msg?.author.displayAvatarURL(),
|
iconURL: valid_message?.author.displayAvatarURL(),
|
||||||
})
|
})
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: `Posté le ${showDate(
|
text: `Message posté le ${showDate(
|
||||||
client.config.default_lang,
|
client.config.default_lang,
|
||||||
getLocale(client, client.config.default_lang),
|
getLocale(client, client.config.default_lang),
|
||||||
quoted_msg?.createdAt as Date)
|
valid_message?.createdAt as Date)
|
||||||
}`,
|
}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle attachments
|
|
||||||
if (quoted_msg?.attachments.size === 1 && isImage(quoted_msg.attachments.first()?.name as string)) {
|
|
||||||
// Only contains one image
|
|
||||||
embed.setImage(quoted_msg.attachments.first()?.url as string);
|
|
||||||
} else {
|
|
||||||
// Contains more than one image or other files
|
|
||||||
let files = '';
|
|
||||||
quoted_msg?.attachments.forEach(attachment => {
|
|
||||||
files += `[${attachment.name}](${attachment.url}), `;
|
|
||||||
});
|
|
||||||
embed.addFields({
|
|
||||||
name: 'Fichiers joints',
|
|
||||||
value: `${files.slice(0, -2)}.`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return message.channel.send({ embeds: [embed] });
|
return message.channel.send({ embeds: [embed] });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,25 +36,3 @@ export const removeExtension = (filename: string) => {
|
||||||
|
|
||||||
return array.join('.');
|
return array.join('.');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Get extension from a filename.
|
|
||||||
* @param filename string of the filename
|
|
||||||
* @returns string of the extension if it exists
|
|
||||||
*/
|
|
||||||
export const getExtension = (filename: string) => {
|
|
||||||
const array = filename.split('.');
|
|
||||||
|
|
||||||
return array.pop();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define if a media is a media based on file extension.
|
|
||||||
* @param filename string of the filename
|
|
||||||
* @returns true is file is a media
|
|
||||||
*/
|
|
||||||
export const isImage = (filename: string) => {
|
|
||||||
return Boolean(getExtension(filename)?.match(
|
|
||||||
/jpg|jpeg|png|webp|gif/
|
|
||||||
));
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in a new issue