creesch / discordIRCd

A node.js script that allows you to connect to discord with your irc client.
Apache License 2.0
115 stars 21 forks source link

VIM based replace/edit #24

Open Scrxtchy opened 7 years ago

Scrxtchy commented 7 years ago

As seen by many IRC bots and the discord webapp itself, using an input such as s/foo/bar will, depending on the platform, will edit, or resend the last message with the replacement string. Discord also have a replacement of no content to delete the message from the buffer This could be useful for editing the last sent message from the deamon

Here's discord's implementation, a bit minified though

searchReplace: {
                    regex: /^s\/((?:.+?)[^\\]|.)\/(.*)/,
                    REMOVE_ESCAPE_CHARS: /\\([*?+\/])/g,
                    action: function(e, t) {
                        if (!t.isEdit) {
                            var n = e.content;
                            e.content = "";
                            var a = x["default"].getChannelId();
                            if (a) {
                                var i = V["default"].getLastEditableMessage(a);
                                if (i && i.id) {
                                    var r = Array.from(n.match(this.regex) || []),
                                        o = r[1],
                                        s = r[2];
                                    o = o.replace(this.REMOVE_ESCAPE_CHARS, function(e, t) {
                                        return t
                                    }), s = s.replace(this.REMOVE_ESCAPE_CHARS, function(e, t) {
                                        return t
                                    });
                                    var E = i.content.replace(o, s);
                                    E ? E !== i.content && z["default"].editMessage(a, i.id, {
                                        content: E
                                    }) : z["default"].deleteMessage(a, i.id)
                                }
                            }
                        }
                    }
                }
creesch commented 7 years ago

Oh pretty awesome discord has this actually.Too bad it doesn't work server side though. That would have been much easier.

I'll look into implementing this at some point,