MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / InstantMessage

Method InstantMessage

KBotExt/GameTab.h:1172–1304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1170 }
1171
1172 static void InstantMessage(const bool instantMute = false, const bool sideNotification = false)
1173 {
1174 auto start = std::chrono::system_clock::now();
1175 while (true)
1176 {
1177 auto now = std::chrono::system_clock::now();
1178 std::chrono::duration<double> diff = now - start;
1179 if (diff.count() > 10) // took 10 seconds and still didn't connect to chat
1180 {
1181 return;
1182 }
1183
1184 std::this_thread::sleep_for(std::chrono::milliseconds(1));
1185 Json::Value root;
1186 Json::CharReaderBuilder builder;
1187 const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
1188 JSONCPP_STRING err;
1189
1190 LCU::SetCurrentClientRiotInfo();
1191 std::string getChat = cpr::Get(cpr::Url{ std::format("https://127.0.0.1:{}/chat/v5/participants", LCU::riot.port) },
1192 cpr::Header{ Utils::StringToHeader(LCU::riot.header) }, cpr::VerifySsl{ false }).text;
1193 if (!reader->parse(getChat.c_str(), getChat.c_str() + static_cast<int>(getChat.length()), &root, &err))
1194 {
1195 continue;
1196 }
1197
1198 const auto& participantsArr = root["participants"];
1199 if (!participantsArr.isArray())
1200 {
1201 continue;
1202 }
1203 if (participantsArr.size() <= 1)
1204 {
1205 continue;
1206 }
1207
1208 std::string cid = "";
1209 for (auto& i : participantsArr)
1210 {
1211 if (i["cid"].asString().contains("champ-select"))
1212 {
1213 cid = i["cid"].asString();
1214 break;
1215 }
1216 }
1217 if (cid == "")
1218 {
1219 continue;
1220 }
1221
1222 if (instantMute || sideNotification)
1223 {
1224 std::string champSelect = LCU::Request("GET", "/lol-champ-select/v1/session");
1225 Json::Value rootCSelect;
1226 if (!champSelect.empty() && champSelect.find("RPC_ERROR") == std::string::npos)
1227 {
1228 if (reader->parse(champSelect.c_str(), champSelect.c_str() + static_cast<int>(champSelect.length()), &rootCSelect, &err))
1229 {

Callers

nothing calls this directly

Calls 3

c_strMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected