Wee-slack: Feature Request: Render Emojis

Created on 2 Nov 2017  路  7Comments  路  Source: wee-slack/wee-slack

We already have support for emoji tab completion using the weemoji.json file and appending |%(emoji) to weechat.completion.default_template. I've written a fairly simple shell script for extending the weemoji.json file by scraping the Slack API and appending the list of custom emojis for a particular team. The only thing missing from this setup is the ability to actually see the visual representation of the emoji in the message. Using the native image rendering support in iTerm2, we could capture elements of conversation that look like :my_emoji: and cross reference them with the weemoji.json file. We could add a configuration option for a cache directory on disk that Wee-slack could look in to see if an image file with the same name as emoji and display that in place of the :my_emoji: text. If the image does not exist, the API could be used to fetch it and add it to the cache for later. It would probably also be good to add some meta data to indicate the date when the image was last cached to re-fetch images in case they have changed over time.

I understand python and the Slack API well but unfortunately do not have a firm grasp on the plugin framework used in WeeChat. I'd be interested in discussing and incubating this idea further with other developers more familiar with WeeChat plugins to figure out if this would actually be feasible before I begin work on it (or to see if it's even something I'd be able to tackle on my own).

All 7 comments

I've written a fairly simple shell script for extending the weemoji.json file by scraping the Slack API and appending the list of custom emojis for a particular team.

There is an open PR which adds completion of custom emojis: #437.

The only thing missing from this setup is the ability to actually see the visual representation of the emoji in the message.

I think this might be out of scope for wee-slack, and should rather be done by another plugin. There is already a plugin for converting the emoji texts to unicode emojis, here https://weechat.org/scripts/source/emoji_aliases.py.html/. Something similar could be made for converting to images.

Only thing that might make it impractical to do this in a separate plugin is the custom emojis in Slack. Not sure how to solve that.

There is this PR that tries to use emoji_aliases.py for this feature:
https://github.com/wee-slack/wee-slack/pull/621

@tedwardd I will love to install a separate plugin that extends wee-slack to print the emoji and the workflow you discussed sounds the best one. I agree with @trygveaa wee-slack sounds already too big and this applies very well as separate plugin.

The part that updates the list of supported emoji sounds like something great to have as part of wee-slack

@trygveaa I tried to use the plugin you shared to convert emoji in unicode, but I them the unicode printed in wee-chat, any pointer about what I am doing wrong?

2020-01-09-15-32-05_349x23

UPDATE: Looking around I installed this plugin https://weechat.org/scripts/source/emoji.lua.html/
it works great for me. I am wondering if there is something I can do to render images as well

I agree with @trygveaa wee-slack sounds already too big and this applies very well as separate plugin.

I forgot to write it here, but after I wrote that comment I have realized that it's probably not possible to do properly in a separate script. Wee-slack changes lines all the time (not just for messages that are edited, but also when they get reactions or thread messages), and I don't think other scripts can hook into that.

The part that updates the list of supported emoji sounds like something great to have as part of wee-slack

Custom emojis are updated automatically. Standard emoji are hard coded, but they change pretty seldom, so you don't gain that much by having it as part of the script. The main reason it's not is that the list of standard emojis is just scraped from the web client because there is no api to get them.

@trygveaa I tried to use the plugin you shared to convert emoji in unicode, but I them the unicode printed in wee-chat, any pointer about what I am doing wrong?

I'm guessing that is because the script was written in python 2 and not updated for python 3.

UPDATE: Looking around I installed this plugin https://weechat.org/scripts/source/emoji.lua.html/
it works great for me. I am wondering if there is something I can do to render images as well

Iiirc, there are some issues with using that script (or any of the emoji scripts) with wee-slack. I don't remember which issues each script has, but the one I mentioned above about changed lines is a problem for all of them. I think there was some other issues with some of the scripts as well.

As for rendering images, that's harder to do. I think the biggest problem is that you have to write some escape codes to render images in the terminal, and weechat strips away those codes. Additionally, I'm guessing you might run into issues with getting the image to scroll when the lines in the buffer scroll, and also with getting the image to expand over multiple lines without covering the text.

There is an issue in the weechat repo about it here: https://github.com/weechat/weechat/issues/1430

I experimented with adding emoji support in wee-slack a year ago, but it was hard to get emojis with multiple code points and emojis with skin codes correct. I should probably revisit it and just start with support for the simple emojis though. It's available here if anyone wants to look at it. Though, that branch doesn't have the latest changes from the last year.

If it helps, the https://github.com/wee-slack/wee-slack/pull/621 PR could be useful (I use it for years without any issue), but it requires a small change in the emoji_aliases plugin. My version is heavily customized, but the only required part is wrapping a if __name__ == "__main__": before each weechat.foo function/bloc at the top level of the script to let it be imported as a module

Emojis are now rendered by default, as long as you have the weemoji.json file in your .weechat directory. Note that the weemoji.json file has been updated, so you will need to download the new file (wee-slack will print an error if you have the old version).

Emoji rendering can be disabled by setting plugins.var.python.slack.render_emoji_as_string to true, then the emoji names will be printed like before.

To be clear, only standard emojis are rendered. Custom emojis are still displayed using the name. This is because custom emojis are images, and weechat doesn't support displaying images as far as I know. https://github.com/weechat/weechat/issues/1430 or something similar would have to be solved before wee-slack can render custom emojis.

Was this page helpful?
0 / 5 - 0 ratings