Xujiayao / Discord-MC-Chat

Discord-MC-Chat (DMCC), formerly known as MC-Discord-Chat and MCDiscordChat (MCDC), is a practical and powerful Fabric and Quilt Minecraft <> Discord chat bridge inspired by BRForgers/DisFabric
https://blog.xujiayao.com/posts/4ba0a17a/
MIT License
62 stars 34 forks source link

[Bug] MCDC is incompatible with StyledChat #24

Open ImUrX opened 2 years ago

ImUrX commented 2 years ago

Simplest Environment Tested

Minecraft Version

1.18.2

MCDiscordChat Version

2.0.0-alpha.1

Description

When trying to do a Styled Chat emoji you just get the text you inputted, so if you do :table: it just says :table: instead of (╯°□°)╯︵ ┻━┻ because it tries to check if the emoji exists on Discord. There should be a way to disable this

To Reproduce

Try using Styled Chat emojis while having this mod on

Log

None

Config

None

Xujiayao commented 2 years ago

I don't understand your issue. Please use images to elaborate further, thx.

ImUrX commented 2 years ago

Intended Styled Chat behaviour: javaw_GUnj89ngZk javaw_EOiaRByAZP

Styled Chat behaviour with this mod: javaw_wgTCsPAPEB

Xujiayao commented 2 years ago

Ok, I will add a exclude list in the next version.

Xujiayao commented 2 years ago

Hello!

Did you add a custom emoji called table to your Discord server? I'm confused about the :table: being highlighted in your screenshot.

Also, by "Styled Chat emoji" do you mean the Fabric mod Patbox/StyledChat?

ImUrX commented 2 years ago

Did you add a custom emoji called table to your Discord server? I'm confused about the :table: being highlighted in your screenshot.

So what happens is that all :text: is ignored discord emoji or not by StyledChat when this mod is on. Example, there is a :pos: emoji which gets replaced by your coordinates (so 100 64 -200) by StyledChat. But when this mod is on, the message just says :pos: with white color like it's normal text

Also, by "Styled Chat emoji" do you mean the Fabric mod Patbox/StyledChat? Yes

Yes, I made the issue here because I thought chat text wasn't reaching the StyledChat mod so I deduced the problem was here.

Xujiayao commented 2 years ago

May I take a look at your StyledChat config? I installed StyledChat but it didn't work.

Normally :table: should not be highlighted by MCDC because it is not an emoji name. So your Discord server has added a custom emote called :table:?

ImUrX commented 2 years ago

what happens when you say :table:

ImUrX commented 2 years ago

Alright, I understand it's because you cancel the function and it never reaches StyledChat's @Redirect

Xujiayao commented 2 years ago

I just used the example config given by the author and it works fine. The situation is the same as your screenshot, except that :table: is not highlighted.

Alright, I understand it's because you cancel the function and it never reaches StyledChat's @Redirect

In this case, I guess there does not seem to have a solution to this problem?

ImUrX commented 2 years ago

Yes there is, why cancel it to make mods incompatible where you can conditionally cancel it.

You could also use StyledChat's API

Xujiayao commented 2 years ago
private void handleMessage(TextStream.Message message) {
    if (this.player.getClientChatVisibility() == ChatVisibility.HIDDEN) {
        this.sendPacket(new GameMessageS2CPacket((new TranslatableText("chat.disabled.options")).formatted(Formatting.RED), MessageType.SYSTEM, Util.NIL_UUID));
    } else {
        this.player.updateLastActionTime();
        String string = message.getRaw();
        if (string.startsWith("/")) {
            this.executeCommand(string);
        } else {
            String string2 = message.getFiltered();
            Text text = string2.isEmpty() ? null : new TranslatableText("chat.type.text", new Object[]{this.player.getDisplayName(), string2});
            Text text2 = new TranslatableText("chat.type.text", new Object[]{this.player.getDisplayName(), string});
            this.server.getPlayerManager().broadcast(text2, (player) -> {
                return this.player.shouldFilterMessagesSentTo(player) ? text : text2;
            }, MessageType.CHAT, this.player.getUuid());
        }

        this.messageCooldown += 20;
        if (this.messageCooldown > 200 && !this.server.getPlayerManager().isOperator(this.player.getGameProfile())) {
            this.disconnect(new TranslatableText("disconnect.spam"));
        }
    }
}

This is the target method void handleMessage(Message message) of both mods.

this.server.getPlayerManager().broadcast(text2, (player) -> {
    return this.player.shouldFilterMessagesSentTo(player) ? text : text2;
}, MessageType.CHAT, this.player.getUuid());

You can see that this method sends a message to all players. Both mods have modified the message, which is why we either redirect or inject and cancel the callback, and both have the same effect that makes the original method not send the original message to all players. If this is not done, the message will be sent twice.

As for the API, I don't think it's taken into consideration as not everyone uses this mod.

If I make a message modification switch, there will be no @ mention and emoji highlighting when it is off. That has to be decided which one to choose I think.

Xujiayao commented 2 years ago

I made a message modification switch in the latest commit. There will be no @mentions and emoji highlighting when it is off, but this gives you the opportunity to keep incompatible mods (like FTB Ranks and StyledChat). You have to decide which one to choose for the time being.