Commit 968bd505 authored by Tim's avatar Tim

Removing colours & item links

parent b05eb2f3
......@@ -54,6 +54,18 @@ std::string unescape_json(const std::string &s) {
return o.str();
}
// Escapes special discord characters
std::string escape_discord(const std::string &s) {
std::ostringstream o;
for (auto c : s)
{
if (c == '`' || c == '*' || c == '_' || c == '~')
o << "\\";
o << c;
}
return o.str();
}
// Real simple client, all it does is invoke a callback when a message is received
class CallbackDiscordClient : public SleepyDiscord::DiscordClient {
public:
......@@ -95,7 +107,7 @@ void DiscordThread(std::string token, std::string channelId, std::string control
std::string msg, combinedMsg;
while (combinedMsg.length() <= 1800 && toDiscord.tryDequeue(msg))
{
combinedMsg += msg + "\n";
combinedMsg += escape_discord(msg) + "\n";
}
if (combinedMsg != "")
......
#include "DiscordClient.h"
#include <nlohmann\json.hpp>
#include <fstream>
#include <regex>
using nlohmann::json;
......@@ -340,25 +341,27 @@ PLUGIN_API VOID OnPulse(VOID)
void EnqueueIfMatch(const PCHAR Line)
{
char buffer[MAX_STRING] = { 0 };
strcpy_s(buffer, Line);
// Remove any colours
StripMQChat(Line, buffer);
// Remove any item links
std::regex re("\x12[A-F0-9]{56}([^\x12]*)\x12");
strcpy_s(buffer, std::regex_replace(buffer, re, "$1").c_str());
if (bRun.load() && blechAllow.Feed(buffer) && !blechBlock.Feed(buffer))
toDiscord.enqueue(Line);
toDiscord.enqueue(buffer);
}
PLUGIN_API DWORD OnWriteChatColor(PCHAR Line, DWORD Color, DWORD Filter)
{
char cleanLine[2048] = { 0 };
StripMQChat(Line, cleanLine);
EnqueueIfMatch(cleanLine);
EnqueueIfMatch(Line);
return 0;
}
PLUGIN_API DWORD OnIncomingChat(PCHAR Line, DWORD Color)
{
char cleanLine[2048] = { 0 };
StripMQChat(Line, cleanLine);
EnqueueIfMatch(cleanLine);
EnqueueIfMatch(Line);
return 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment