Repository navigation
feat(chat): show chat messages from Discord as such (C4) #708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sven-n
wants to merge
5
commits into
claude/discord-presence-mumain-597-l2q09d
Choose a base branch
from
claude/discord-presence-mumain-597-l2q09d-c4-chat
base: claude/discord-presence-mumain-597-l2q09d
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d0a14e0
feat(chat): show chat messages from Discord as such
claude d753ce7
feat(chat): recognise Discord messages of OpenMU's chat bridge
claude 73a1183
Merge branch 'claude/discord-presence-mumain-597-l2q09d' into claude/…
claude 0f6e1b2
docs(chat): the '@' sender check is only a fallback
claude d36772b
Merge branch 'claude/discord-presence-mumain-597-l2q09d' into claude/…
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #include "stdafx.h" | ||
| #include "UI/Chat/ExternalChat.h" | ||
|
|
||
| #include "App/Control/ControlTaps.h" | ||
| #include "Network/Server/WSclient.h" | ||
| #include "UI/Core/WindowSystem.h" | ||
|
|
||
| namespace | ||
| { | ||
| constexpr const wchar_t* DiscordBadge = L"[Discord] "; | ||
| constexpr const char* DiscordChatKind = "discord"; | ||
| } // namespace | ||
|
|
||
| namespace UI::Chat::External | ||
| { | ||
| std::wstring SenderLabel(Source source, std::wstring_view displayName) | ||
| { | ||
| switch (source) | ||
| { | ||
| case Source::Discord: | ||
| default: | ||
| return DiscordBadge + std::wstring(displayName.substr(0, MaxDisplayNameLength)); | ||
| } | ||
| } | ||
|
|
||
| mu::ui::window::MESSAGE_TYPE ScopeMessageType(Scope scope) | ||
| { | ||
| switch (scope) | ||
| { | ||
| case Scope::Guild: | ||
| return mu::ui::window::TYPE_GUILD_MESSAGE; | ||
| case Scope::Alliance: | ||
| return mu::ui::window::TYPE_UNION_MESSAGE; | ||
| case Scope::World: | ||
| default: | ||
| return mu::ui::window::TYPE_CHAT_MESSAGE; | ||
| } | ||
| } | ||
|
|
||
| std::wstring ShownText(std::wstring_view text) | ||
| { | ||
| return std::wstring(text.substr(0, MAX_CHAT_SIZE)); | ||
| } | ||
|
|
||
| // Unlike an in-game message, no speech balloon (nobody stands there) and no | ||
| // entry in the whisper allow-list (nobody to whisper). | ||
| void Show(const Message& message) | ||
| { | ||
| const std::wstring sender = SenderLabel(message.source, message.displayName); | ||
| const std::wstring text = ShownText(message.text); | ||
| if (text.empty()) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| g_pChatListBox->AddExternalText(sender, text, ScopeMessageType(message.scope)); | ||
| App::Control::Events::RecordChatLine(sender.c_str(), text.c_str(), DiscordChatKind); | ||
| } | ||
|
|
||
| bool IsBridgedSender(std::wstring_view sender) | ||
| { | ||
| return sender.size() > 1 && sender.front() == BridgedSenderPrefix; | ||
| } | ||
|
|
||
| void ShowBridged(Scope scope, std::wstring_view sender, std::wstring_view text) | ||
| { | ||
| Message message; | ||
| message.source = Source::Discord; | ||
| message.scope = scope; | ||
| message.displayName = std::wstring(sender.substr(1)); | ||
| message.text = std::wstring(text); | ||
| Show(message); | ||
| } | ||
| } // namespace UI::Chat::External | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // Chat messages written outside the game - today in a Discord channel that | ||
| // the server bridges into guild, alliance or world chat (#700). | ||
| // | ||
| // They are shown as such: the sender is marked with where they wrote, keeps | ||
| // a name longer than a character's, and can't be whispered, because there | ||
| // is no character behind it. | ||
| #pragma once | ||
|
|
||
| #include "UI/HUD/ChatLogWindow.h" | ||
|
|
||
| #include <cstddef> | ||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| namespace UI::Chat::External | ||
| { | ||
| enum class Source | ||
| { | ||
| Discord, | ||
| }; | ||
|
|
||
| // Which in-game chat the message belongs to; it takes that chat's colours. | ||
| enum class Scope | ||
| { | ||
| Guild, | ||
| Alliance, | ||
| World, | ||
| }; | ||
|
|
||
| // Discord's display names are at most 32 characters long. | ||
| inline constexpr std::size_t MaxDisplayNameLength = 32; | ||
|
|
||
| struct Message | ||
| { | ||
| Source source = Source::Discord; | ||
| Scope scope = Scope::World; | ||
| std::wstring displayName; | ||
| std::wstring text; | ||
| }; | ||
|
|
||
| // What the chat log shows as the sender: "[Discord] name", the name cut to | ||
| // MaxDisplayNameLength characters. | ||
| [[nodiscard]] std::wstring SenderLabel(Source source, std::wstring_view displayName); | ||
|
|
||
| // The chat log type whose colours the scope uses. | ||
| [[nodiscard]] mu::ui::window::MESSAGE_TYPE ScopeMessageType(Scope scope); | ||
|
|
||
| // The text as shown: cut to the length of an in-game chat message. | ||
| [[nodiscard]] std::wstring ShownText(std::wstring_view text); | ||
|
|
||
| // Shows the message in the chat log, in its scope and in the Discord view. | ||
| void Show(const Message& message); | ||
|
|
||
| // OpenMU's chat bridge (MUnique/OpenMU#1161) sends messages written in Discord | ||
| // through the ordinary guild and alliance chat, as the linked character with | ||
| // this prefix, which OpenMU doesn't allow in character names. | ||
| // | ||
| // This is a best-effort fallback for servers which don't send the dedicated | ||
| // ExternalChatMessage: the prefix is a convention of the server, not a | ||
| // guarantee the client can check - a server which allows it in character | ||
| // names would have such characters shown as Discord users. When a server | ||
| // sends ExternalChatMessage, that is the authoritative signal. | ||
| inline constexpr wchar_t BridgedSenderPrefix = L'@'; | ||
|
|
||
| [[nodiscard]] bool IsBridgedSender(std::wstring_view sender); | ||
|
|
||
| // Shows a guild or alliance chat line of a bridged sender as a message from | ||
| // Discord, named after the character without the prefix. | ||
| void ShowBridged(Scope scope, std::wstring_view sender, std::wstring_view text); | ||
| } // namespace UI::Chat::External |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.