Skip to content

Commit

Permalink
* Update TTS functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Jun 13, 2024
1 parent 0c32d3c commit b6f7426
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/discord/DiscordInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ std::string DiscordInstance::ResolveMentions(const std::string& str, Snowflake g
return finalStr;
}

std::string DiscordInstance::ReverseMentions(const std::string& message, Snowflake guildID)
std::string DiscordInstance::ReverseMentions(const std::string& message, Snowflake guildID, bool ttsMode)
{
bool hasMent = false;
bool hasOpen = false;
Expand Down Expand Up @@ -1045,9 +1045,9 @@ std::string DiscordInstance::ReverseMentions(const std::string& message, Snowfla
Snowflake sf = (Snowflake)GetIntFromString(mentDest);

if (isRole)
resultStr = "@" + LookupRoleName(sf, guildID);
resultStr = (ttsMode ? "" : "@") + LookupRoleName(sf, guildID);
else
resultStr = "@" + LookupUserNameGlobally(sf, guildID);
resultStr = (ttsMode ? "" : "@") + LookupUserNameGlobally(sf, guildID);

break;
}
Expand All @@ -1060,7 +1060,7 @@ std::string DiscordInstance::ReverseMentions(const std::string& message, Snowfla
if (!pChan)
goto ErrorParsing;

resultStr = pChan->GetTypeSymbol() + pChan->m_name;
resultStr = (ttsMode ? "" : pChan->GetTypeSymbol()) + pChan->m_name;
break;
}

Expand Down Expand Up @@ -1094,6 +1094,10 @@ std::string DiscordInstance::ReverseMentions(const std::string& message, Snowfla
}

assert(!resultStr.empty() && resultStr[0] == ':' && resultStr[resultStr.size() - 1] == ':');

if (ttsMode && resultStr.size() >= 2)
resultStr = " emoji " + resultStr.substr(1, resultStr.size() - 2);

break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/discord/DiscordInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class DiscordInstance
std::string ResolveMentions(const std::string& str, Snowflake guild, Snowflake channel);

// Transform snowflake mentions into user, channel, or emoji mentions.
std::string ReverseMentions(const std::string& message, Snowflake guild);
std::string ReverseMentions(const std::string& message, Snowflake guild, bool ttsMode = false);

// Send a message to the current channel.
bool SendMessageToCurrentChannel(const std::string& msg, Snowflake& tempSf, Snowflake reply = 0, bool mentionReplied = true);
Expand Down
12 changes: 11 additions & 1 deletion src/windows/MessageList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3315,15 +3315,18 @@ LRESULT CALLBACK MessageList::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
bool mayDelete = isThisMyMessage || mayManageMessages;
bool mayEdit = isThisMyMessage;
bool mayPin = mayManageMessages;
bool maySpeak = !IsActionMessage(pRCMsg->m_msg.m_type) && !pRCMsg->m_msg.m_message.empty();

#ifdef OLD_WINDOWS
EnableMenuItem(menu, ID_DUMMYPOPUP_DELETEMESSAGE, mayDelete ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(menu, ID_DUMMYPOPUP_EDITMESSAGE, mayEdit ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(menu, ID_DUMMYPOPUP_PINMESSAGE, mayPin ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(menu, ID_DUMMYPOPUP_SPEAKMESSAGE, maySpeak ? MF_ENABLED : MF_GRAYED);
#else
if (!mayDelete) RemoveMenu(menu, ID_DUMMYPOPUP_DELETEMESSAGE, MF_BYCOMMAND);
if (!mayEdit) RemoveMenu(menu, ID_DUMMYPOPUP_EDITMESSAGE, MF_BYCOMMAND);
if (!mayPin) RemoveMenu(menu, ID_DUMMYPOPUP_PINMESSAGE, MF_BYCOMMAND);
if (!maySpeak) RemoveMenu(menu, ID_DUMMYPOPUP_SPEAKMESSAGE, MF_BYCOMMAND);
#endif

TrackPopupMenu(menu, TPM_RIGHTBUTTON, xPos, yPos, 0, hWnd, NULL);
Expand Down Expand Up @@ -3440,7 +3443,14 @@ LRESULT CALLBACK MessageList::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
case ID_DUMMYPOPUP_SPEAKMESSAGE:
{
TextToSpeech::Speak(pMsg->m_msg.m_author + " said " + pMsg->m_msg.m_message);
if (IsActionMessage(pMsg->m_msg.m_type))
break;

std::string action = " said ";
if (pMsg->m_msg.m_type == MessageType::REPLY)
action = " replied to " + pMsg->m_msg.m_referencedMessage.m_author + " ";

TextToSpeech::Speak(pMsg->m_msg.m_author + action + GetDiscordInstance()->ReverseMentions(pMsg->m_msg.m_message, pThis->m_guildID, true));
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/windows/TextInterface_Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ void MdDrawString(DrawingContext* context, const Rect& rect, const String& str,
setColor = true;
}
if (styleFlags & (WORD_MENTION | WORD_EVERYONE)) {
oldColor = SetTextColor(context->m_hdc, context->InvertIfNeeded(COLOR_MENT));
oldColor = SetTextColor(context->m_hdc, GetSysColor(COLOR_MENT));
setColor = true;
oldColorBG = SetBkColor(context->m_hdc, LerpColor(context->m_bkColor, context->InvertIfNeeded(COLOR_MENT), 10, 100));
oldColorBG = SetBkColor(context->m_hdc, LerpColor(context->m_bkColor, GetSysColor(COLOR_MENT), 10, 100));
setColorBG = true;
}
if (styleFlags & (WORD_CODE | WORD_MLCODE)) {
Expand Down

0 comments on commit b6f7426

Please sign in to comment.