fix: time related issues (#179)
All checks were successful
Publish latest version / build (push) Successful in 1m44s

- cleanup some code
- fix #100 (finally!)
- update some dependencie
   There is an issue with thoses one:
    @typescript-eslint/eslint-plugin": "~8.7.0"
    @typescript-eslint/parser": "~8.7.0"

Reviewed-on: #179
Co-authored-by: Mylloon <kennel.anri@tutanota.com>
Co-committed-by: Mylloon <kennel.anri@tutanota.com>
This commit is contained in:
Mylloon 2024-09-24 18:07:27 +02:00 committed by Mylloon
parent facf0cd88e
commit b1abeefad2
Signed by: Forgejo
GPG key ID: E72245C752A07631
5 changed files with 235 additions and 1049 deletions

1105
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -25,7 +25,6 @@
"discord-player": "^6.7.1", "discord-player": "^6.7.1",
"discord.js": "^14.16.2", "discord.js": "^14.16.2",
"mediaplex": "^0.0.9", "mediaplex": "^0.0.9",
"puppeteer": "^23.4.0",
"sqlite3": "^5.1.7", "sqlite3": "^5.1.7",
"typescript": "^5.6.2", "typescript": "^5.6.2",
"uuid": "^10.0.0" "uuid": "^10.0.0"

View file

@ -98,89 +98,100 @@ export default async (message: Message, client: Client) => {
const loc = getLocale(client, client.config.default_lang); const loc = getLocale(client, client.config.default_lang);
// Remove duplicates then map the quoted posts // Remove duplicates then map the quoted posts
[...new Set(messages)].map((quoted_post) => { [...new Set(messages)]
const embed = new EmbedBuilder().setColor("#2f3136").setAuthor({ .filter((p) => p !== undefined)
name: "Citation", .map((quoted_post) => {
iconURL: quoted_post?.author.displayAvatarURL(), const embed = new EmbedBuilder().setColor("#2f3136").setAuthor({
}); name: "Citation",
iconURL: quoted_post.author.displayAvatarURL(),
});
// Handle attachments // Handle attachments
if (quoted_post?.attachments.size !== 0) { if (quoted_post.attachments.size !== 0) {
if (quoted_post?.attachments.size === 1 && isImage(quoted_post.attachments.first()!.name)) { if (quoted_post.attachments.size === 1 && isImage(quoted_post.attachments.first()!.name)) {
// Only contains one image // Only contains one image
embed.setImage(quoted_post.attachments.first()!.url); embed.setImage(quoted_post.attachments.first()!.url);
} else {
// Contains more than one image and/or other files
let files = "";
quoted_post.attachments.forEach((file) => (files += `[${file.name}](${file.url}), `));
embed.addFields({
// TODO: Don't pluralize when there is only one file.
// TODO: Locales
name: "Fichiers joints",
// TODO: Check if don't exceed char limit, if yes, split
// files into multiples field.
value: `${files.slice(0, -2)}.`,
});
}
}
// Description as post content
if (quoted_post.content) {
// Only if content exists and length > 0
embed.setDescription(quoted_post.content);
}
// Footer
let footer = `Posté le ${showDate(
message.guild?.preferredLocale ?? client.config.default_lang,
loc,
quoted_post.createdAt,
)}`;
if (quoted_post.editedAt) {
footer += ` et modifié le ${showDate(
message.guild?.preferredLocale ?? client.config.default_lang,
loc,
quoted_post.editedAt,
)}`;
}
let author = "Auteur";
if (message.author === quoted_post.author) {
author += " & Citateur";
} else { } else {
// Contains more than one image and/or other files footer += `\nCité par ${userWithNickname(message.member!) ?? "?"} le ${showDate(
let files = ""; message.guild?.preferredLocale ?? client.config.default_lang,
quoted_post?.attachments.forEach((file) => (files += `[${file.name}](${file.url}), `)); loc,
embed.addFields({ message.createdAt,
// TODO: Don't pluralize when there is only one file. )}`;
// TODO: Locales }
name: "Fichiers joints",
// TODO: Check if don't exceed char limit, if yes, split embed.setFooter({
// files into multiples field. text: footer,
value: `${files.slice(0, -2)}.`, iconURL: message.author.avatarURL() ?? undefined,
});
// Location/author of the quoted post
embed.addFields(
{
name: author,
value: `${quoted_post.author}`,
inline: true,
},
{
name: "Message",
value: `${quoted_post.channel} - [Lien Message](${quoted_post.url})`,
inline: true,
},
);
// Delete source message if no content when removing links
if (
!message.content.replace(new RegExp(regex, "g"), "").trim() &&
messages.length === urls.length &&
!message.mentions.repliedUser &&
message.channel.isSendable()
) {
message.delete();
return message.channel.send({ embeds: [embed] });
} else {
return message.reply({
embeds: [embed],
allowedMentions: {
repliedUser: false,
},
}); });
} }
}
// Description as post content
if (quoted_post?.content) {
// Only if content exists and length > 0
embed.setDescription(quoted_post?.content);
}
// Footer
let footer = `Posté le ${showDate(loc, quoted_post!.createdAt)}`;
if (quoted_post?.editedAt) {
footer += ` et modifié le ${showDate(loc, quoted_post.editedAt)}`;
}
let author = "Auteur";
if (message.author === quoted_post?.author) {
author += " & Citateur";
} else {
footer += `\nCité par ${userWithNickname(message.member!) ?? "?"} le ${showDate(
loc,
message.createdAt,
)}`;
}
embed.setFooter({
text: footer,
iconURL: message.author.avatarURL() ?? undefined,
}); });
// Location/author of the quoted post
embed.addFields(
{
name: author,
value: `${quoted_post?.author}`,
inline: true,
},
{
name: "Message",
value: `${quoted_post?.channel} - [Lien Message](${quoted_post?.url})`,
inline: true,
},
);
// Delete source message if no content when removing links
if (
!message.content.replace(new RegExp(regex, "g"), "").trim() &&
messages.length === urls.length &&
!message.mentions.repliedUser &&
message.channel.isSendable()
) {
message.delete();
return message.channel.send({ embeds: [embed] });
} else {
return message.reply({
embeds: [embed],
allowedMentions: {
repliedUser: false,
},
});
}
});
}; };

View file

@ -414,6 +414,7 @@ export const embedListReminders = async (
const expiration = `${loc.get("c_reminder8")} ${timeDeltaToString(remind.expiration_date)}`; const expiration = `${loc.get("c_reminder8")} ${timeDeltaToString(remind.expiration_date)}`;
embed.addFields({ embed.addFields({
name: `#${remind.id}${loc.get("c_reminder9")} ${showDate( name: `#${remind.id}${loc.get("c_reminder9")} ${showDate(
local,
loc, loc,
new Date(Number(remind.creation_date)), new Date(Number(remind.creation_date)),
)}\n${expiration}`, )}\n${expiration}`,

View file

@ -5,10 +5,8 @@
* @param date Date * @param date Date
* @returns String * @returns String
*/ */
export const showDate = (locale: Map<string, unknown>, date: Date) => { export const showDate = (tz: string, locale: Map<string, unknown>, date: Date) =>
const timezoned = new Date(date.getTime()); date.toLocaleString(tz).replace(" ", ` ${locale.get("u_time_at")} `);
return `${timezoned.toDateString()} ${locale.get("u_time_at")} ${timezoned.toTimeString().split(" ")[0]}`;
};
enum TimeSecond { enum TimeSecond {
Year = 31536000, Year = 31536000,