Skip to content

[FEATURE] 希望支持Mirai的消息链序列化方法 #71

Description

@Natsukage

希望支持Mirai中的消息序列化方法,serializeToMiraiCode()

目前Mirai.Net只有GetPlainMessage()。没有办法直接对比2条消息内容是否相同。
由于消息链中包含有消息的源数据,因此即使是2条复读的消息,其中的Source部分也有差异。当使用==直接对比两条消息链时总是会得到False的结果。

除了消息链外,Image等单个元素也会有类似的问题,即使是同一张图片连续发送,ImageID相同,但是因为每一次的图片地址url都有变化,所以导致即使是同一个消息里的3张ID相同的表情包,判断是否相等时候结果也是False。

目前我能想到的实现方法是逐个元素对比两个消息链并直接跳过Source类型,但是对于图片等类型的元素,依然需要每个元素单独判断两者是否相等(通过imageId),非常不美观。
类似于长这样

        private static bool Equals(MessageChain a,MessageChain b)
        {
            if (a.Count!=b.Count) return false;
            for (int i = 0; i < a.Count; i++)
            {
                if (a[i].Type==Messages.Source || b[i].Type == Messages.Source)
                    continue;
                if (a[i].Type == Messages.Image && b[i].Type == Messages.Image && ((ImageMessage)a[i]).ImageId == ((ImageMessage)b[i]).ImageId) continue;
                if (a[i] != b[i]) return false;
            }
            return true;
        }

如果对比两条消息的Mirai码或者酷Q码是可以简单地判断两条消息的内容是否相同的。并且一整条字符串也方便对消息本身进行整体处理(比如说,我想把消息的简体文字替换成繁体)的同时不影响消息中的表情图片、at等元素。希望能实现此特性。

非常感谢!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions