11#include " Event.hpp"
2+ #include " Features/Demo/NetworkGhostPlayer.hpp"
23#include " Modules/Client.hpp"
34#include " Modules/Engine.hpp"
45#include " Utils/TwitchConnection.hpp"
@@ -26,17 +27,17 @@ ON_EVENT(PRE_TICK) {
2627 }
2728 auto twitchMsgs = twitchConnection.FetchNewMessages ();
2829 for (auto msg : twitchMsgs) {
30+ std::string message = msg.message ;
31+ std::string author = msg.username ;
32+ if (message.length () == 0 || author.length () == 0 )
33+ continue ;
34+
2935 if (sar_twitch_chat_enabled.GetInt () == 2 ) {
30- std::string message = msg.message ;
31- message.erase (remove_if (message.begin (), message.end (), [](char c) {
32- return c == ' "' || c == ' \n ' || c == ' \r ' || c == ' \0 ' ;
33- }), message.end ());
34- std::string author = msg.username ;
35- author.erase (remove_if (author.begin (), author.end (), [](char c) {
36- return c == ' "' || c == ' \n ' || c == ' \r ' || c == ' \0 ' ;
37- }), author.end ());
3836 if (Utils::StartsWith (message.c_str (), " !spec " )) {
3937 std::string specName = message.substr (6 );
38+ specName.erase (remove_if (specName.begin (), specName.end (), [](char c) {
39+ return c == ' "' || c == ' \n ' || c == ' \r ' || c == ' \0 ' ;
40+ }), specName.end ());
4041 if (specName.length () > 0 ) {
4142 specName = std::string (" ghost_spec_pov \" " ) + specName.c_str () + " \"\n " ;
4243 engine->ExecuteCommand (specName.c_str (), true );
@@ -56,7 +57,6 @@ ON_EVENT(PRE_TICK) {
5657 // i promise i can be trusted :P
5758 std::string command = message.substr (5 );
5859 if (command.length () > 0 ) {
59- command = command + " \n " ;
6060 engine->ExecuteCommand (command.c_str (), true );
6161 }
6262 } else {
@@ -65,16 +65,16 @@ ON_EVENT(PRE_TICK) {
6565 } else if (Utils::StartsWith (message.c_str (), " !" ) || Utils::ICompare (author, " nightbot" ) || Utils::ICompare (author, " streamelements" )) {
6666 // Ignore bots and bot commands
6767 } else if (Utils::ICompare (author, sar_twitch_chat_channel.GetString ())) {
68- std::string out = std::string (" ghost_message \" " ) + message + " \"\n " ;
69- engine->ExecuteCommand (out.c_str (), true );
68+ networkManager.SendMessageToAll (message);
7069 } else {
71- std::string out = std::string (" ghost_message \" (TTV) " ) + author + " : " + message + " \"\n " ;
72- engine->ExecuteCommand (out.c_str (), true );
70+ networkManager.SendMessageToAll (" (TTV) " + author + " : " + message);
7371 }
7472 } else {
75- std::string message = msg.username + " : " + msg.message ;
76- Color color = Utils::GetColor (sar_twitch_chat_color.GetString ()).value_or (Color (255 , 255 , 255 ));
77- client->Chat (color, message.c_str ());
73+ if (!(Utils::StartsWith (message.c_str (), " !" ) || Utils::ICompare (author, " nightbot" ) || Utils::ICompare (author, " streamelements" ))) {
74+ std::string message = msg.username + " : " + msg.message ;
75+ Color color = Utils::GetColor (sar_twitch_chat_color.GetString ()).value_or (Color (255 , 255 , 255 ));
76+ client->Chat (color, message.c_str ());
77+ }
7878 }
7979 }
8080}
0 commit comments