Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Fonctions utilitaires en rapport avec les messages Discord #217

Closed
wants to merge 14 commits into from

Conversation

Steellgold
Copy link
Member

feat(message.util.ts): add isDiscordLink function to check if a link is a valid discord link
@Steellgold Steellgold added the refactor Improvement of an existing code label Jun 7, 2023
@Steellgold Steellgold added this to the V3.2.0 milestone Jun 7, 2023
@Steellgold Steellgold self-assigned this Jun 7, 2023
@Steellgold Steellgold linked an issue Jun 7, 2023 that may be closed by this pull request
@Bluzzi Bluzzi requested review from Unarray and Bluzzi June 7, 2023 20:00
Copy link
Member

@Bluzzi Bluzzi left a 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 ?

src/utils/message/message.test.ts Outdated Show resolved Hide resolved
src/commands/forum/[sub-commands]/resolve.cmd.ts Outdated Show resolved Hide resolved
@Bluzzi Bluzzi changed the title Fonction de récupération d'un message Création d'une fonction utilitaire pour récupérer un lien de message Discord dans un texte Jun 7, 2023
…functions

test(utils/message): add tests for isDiscordLink, getMessageContentFromLink and msgParams functions
@Steellgold
Copy link
Member Author

image

Bluzzi and others added 8 commits June 14, 2023 01:45
…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
@Steellgold Steellgold changed the title Création d'une fonction utilitaire pour récupérer un lien de message Discord dans un texte Fonctions utilitaires en rapport avec les messages Discord Jun 20, 2023
Comment on lines 25 to 27
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);
});
Copy link
Member

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

Comment on lines 15 to 17
export const containsDiscordLink = (content: string): boolean => {
return content.match(discordLinkRegex) !== null;
};
Copy link
Member

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.

Comment on lines 19 to 23
export const extractDiscordLink = (content: string): string | string[] | null => {
const discordLinks = content.match(discordLinkRegex);
if (discordLinks) return discordLinks;
return null;
};
Copy link
Member

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> => {
Copy link
Member

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.

Comment on lines +26 to +32
const ids = [...link.match(/(\d+)/g) ?? []];

if (ids.length !== 3) return null;

const guildId = ids[0];
const channelId = ids[1];
const messageId = ids[2];
Copy link
Member

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);

Comment on lines 7 to 8
containsDiscordLink("Salut check : https://canary.discord.com/channels/732251741999071303/1113731433123565589/1113731587570413588")
).toBe(true);
Copy link
Member

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
@Arcoz0308
Copy link
Member

Que manque il a ce pr ? @Bluzzi

@Bluzzi
Copy link
Member

Bluzzi commented Feb 17, 2024

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.

@Steellgold
Copy link
Member Author

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.

@Steellgold Steellgold closed this Jul 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
refactor Improvement of an existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fonction de récupération d'un message
4 participants