-
Notifications
You must be signed in to change notification settings - Fork 1
Fonctions utilitaires en rapport avec les messages Discord #217
Conversation
Steellgold
commented
Jun 7, 2023
- Close Fonction de récupération d'un message #211
feat(message.util.ts): add isDiscordLink function to check if a link is a valid discord link
…k function from message.util module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je me demande si le fichier utilitaire message
n'aurait pas sa place au côté des fichiers utilitaires dans /utils/function
?
…functions test(utils/message): add tests for isDiscordLink, getMessageContentFromLink and msgParams functions
…and remove getMessageContentFromLink function test(utils/message): add tests for containsDiscordLink function feat(utils/message): export containsDiscordLink function instead of isDiscordLink function
… for clarity and consistency with other functions
test(utils): add tests for extractDiscordLink function in extract-discord-link.test.ts
…port it to message.util.ts to avoid code duplication.
…e from a Discord message link test(utils): add test for getMessageFromLink function to check if it returns an instance of Message
…s and non-discord links
it("should return false because is litteraly not a discord link", () => { | ||
expect(containsDiscordLink("Salut check la superbe vidéo: https://www.youtube.com/watch?v=dQw4w9WgXcQ")).toBe(false); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Soit plus sérieux dans les titres
src/utils/message/message.util.ts
Outdated
export const containsDiscordLink = (content: string): boolean => { | ||
return content.match(discordLinkRegex) !== null; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cette fonction est inutile. On peux s'en passer, juste la fonction extractDiscordLink()
est suffisante, si elle retourne une array vide, ça veux dire qu'il n'y a pas de lien.
src/utils/message/message.util.ts
Outdated
export const extractDiscordLink = (content: string): string | string[] | null => { | ||
const discordLinks = content.match(discordLinkRegex); | ||
if (discordLinks) return discordLinks; | ||
return null; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cette fonction devrait avoir cette valeur de retour :
type DiscordMessage = {
guildID: Snowflake;
channelID: Snowflake;
messageID: Snowflake;
}
export function extractDiscordLink = (messageContent: string): DiscordMessage[] => {
// TODO
}
return null; | ||
}; | ||
|
||
export const getMessageFromLink = async(link: string): Promise<Message<true> | null> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suite aux modifications de extractDiscordLink
, cette fonction devrait être bien plus simple car elle n'a plus à gérer la logique d'extraction.
const ids = [...link.match(/(\d+)/g) ?? []]; | ||
|
||
if (ids.length !== 3) return null; | ||
|
||
const guildId = ids[0]; | ||
const channelId = ids[1]; | ||
const messageId = ids[2]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
La manière de parse est pourrait être amélioré :
const content = `
Hello World!
https://canary.discord.com/channels/732251741999071303/786216771723198514/803532192793493544
are you ok ?
https://canary.discord.com/channels/732251741999071303/786216771723198514/803532192793493544
`;
const matchs = [...content.matchAll(/\/\d+\/\d+\/\d+/g)].map(element => {
const [guildID, channelID, messageID] = [...element[0].matchAll(/\d+/g)].map(e => e[0]);
return { guildID, channelID, messageID };
});
console.log(matchs);
containsDiscordLink("Salut check : https://canary.discord.com/channels/732251741999071303/1113731433123565589/1113731587570413588") | ||
).toBe(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En anglais les tests
…k examples chore(contains-discord-link.test.ts): remove unnecessary test case
…st.ts file chore(extract-discord-link.test.ts): update tests for extractDiscordLink function chore(index.ts): remove containsDiscordLink from export chore(message.type.ts): add DiscordMessage type chore(message.util.ts): update extractDiscordLink function to return DiscordMessage or empty array
… extractDiscordLink fix(resolve.cmd.ts): change type of extracted message from array to DiscordMessage | null fix(resolve.cmd.ts): change variable name from message to fetchedMessage
Que manque il a ce pr ? @Bluzzi |
Certainement la résolution des reviews ouvertes, bien que des nouveaux commits ont vu le jour depuis celle-ci. On a pas eu de nouvelle de Gaëtan et il n'a pas actualisé le status des reviews. |
Je n'avais pas répondu / resolve mais j'avais commit les changements. |