Skip to content

Implementation of DiscordMessage.Content humanization.

Mateusz Brawański requested to merge github/fork/Evengard/humanize-message into master

Created by: Evengard

Summary

This is the implementation of the convertation to a human-readable format of DiscordMessage snowflake tags (such as mentions and emojis). Fixes #935 (closed).

Details

For some cases, a human-readable version of the message received by a bot may be useful - for example, to relay it somewhere else, eg on a website. This pull request implements the convertation to a human-readable format the most cryptic part of a bot-received message - the mentions and emojis.

Changes proposed

  • Added an Emojis list which gets populated by DiscordEmoji objects of all emojis present in DiscordMessage.Content at the time of populating the mentions
  • Added an IsUnicode bool to DiscordEmoji object to distinguish between emojis which can be converted to Unicode and the ones which doesn't
  • Added the Utilities.HumanizeContentAsync method for converting the snowflake tags into human-readable representation
  • Because the method of converting emojis may depend on circumstances, HumanizeContentAsync accepts a second parameter of Func<DiscordEmoji, Task<string>> to allow specifying a method of formatting theese
  • The default is to skip all non-unicode emojis, and output the unicode emojis in unicode format.

Notes

The HumanizeContentAsync method is async only because of the message.Channel.Guild.GetMemberAsync call, which is in turn a fallback for the case if if (user is DiscordMember member) fails. Now, if for guild messages this cast is always true, I can rework it to make it non-async.

Merge request reports

Loading