categorized emtotepopup

This commit is contained in:
fourtf
2018-08-11 14:20:53 +02:00
parent 09b8a9d821
commit c719bb6b74
55 changed files with 420 additions and 604 deletions
+40 -40
View File
@@ -109,7 +109,7 @@ void PubSubClient::handlePong()
{
assert(this->awaitingPong_);
Log("Got pong!");
log("Got pong!");
this->awaitingPong_ = false;
}
@@ -144,7 +144,7 @@ void PubSubClient::ping()
}
if (self->awaitingPong_) {
Log("No pong respnose, disconnect!");
log("No pong respnose, disconnect!");
// TODO(pajlada): Label this connection as "disconnect me"
}
});
@@ -166,7 +166,7 @@ bool PubSubClient::send(const char *payload)
websocketpp::frame::opcode::text, ec);
if (ec) {
Log("Error sending message {}: {}", payload, ec.message());
log("Error sending message {}: {}", payload, ec.message());
// TODO(pajlada): Check which error code happened and maybe gracefully
// handle it
@@ -207,26 +207,26 @@ PubSub::PubSub()
action.state = ModeChangedAction::State::On;
if (!data.HasMember("args")) {
Log("Missing required args member");
log("Missing required args member");
return;
}
const auto &args = data["args"];
if (!args.IsArray()) {
Log("args member must be an array");
log("args member must be an array");
return;
}
if (args.Size() == 0) {
Log("Missing duration argument in slowmode on");
log("Missing duration argument in slowmode on");
return;
}
const auto &durationArg = args[0];
if (!durationArg.IsString()) {
Log("Duration arg must be a string");
log("Duration arg must be a string");
return;
}
@@ -314,7 +314,7 @@ PubSub::PubSub()
return;
}
} catch (const std::runtime_error &ex) {
Log("Error parsing moderation action: {}", ex.what());
log("Error parsing moderation action: {}", ex.what());
}
action.modded = false;
@@ -339,7 +339,7 @@ PubSub::PubSub()
return;
}
} catch (const std::runtime_error &ex) {
Log("Error parsing moderation action: {}", ex.what());
log("Error parsing moderation action: {}", ex.what());
}
action.modded = true;
@@ -380,7 +380,7 @@ PubSub::PubSub()
this->signals_.moderation.userBanned.invoke(action);
} catch (const std::runtime_error &ex) {
Log("Error parsing moderation action: {}", ex.what());
log("Error parsing moderation action: {}", ex.what());
}
};
@@ -410,7 +410,7 @@ PubSub::PubSub()
this->signals_.moderation.userBanned.invoke(action);
} catch (const std::runtime_error &ex) {
Log("Error parsing moderation action: {}", ex.what());
log("Error parsing moderation action: {}", ex.what());
}
};
@@ -436,7 +436,7 @@ PubSub::PubSub()
this->signals_.moderation.userUnbanned.invoke(action);
} catch (const std::runtime_error &ex) {
Log("Error parsing moderation action: {}", ex.what());
log("Error parsing moderation action: {}", ex.what());
}
};
@@ -462,7 +462,7 @@ PubSub::PubSub()
this->signals_.moderation.userUnbanned.invoke(action);
} catch (const std::runtime_error &ex) {
Log("Error parsing moderation action: {}", ex.what());
log("Error parsing moderation action: {}", ex.what());
}
};
@@ -493,7 +493,7 @@ void PubSub::addClient()
auto con = this->websocketClient.get_connection(TWITCH_PUBSUB_URL, ec);
if (ec) {
Log("Unable to establish connection: {}", ec.message());
log("Unable to establish connection: {}", ec.message());
return;
}
@@ -512,7 +512,7 @@ void PubSub::listenToWhispers(std::shared_ptr<TwitchAccount> account)
std::string userID = account->getUserId().toStdString();
Log("Connection open!");
log("Connection open!");
websocketpp::lib::error_code ec;
std::vector<std::string> topics({"whispers." + userID});
@@ -520,7 +520,7 @@ void PubSub::listenToWhispers(std::shared_ptr<TwitchAccount> account)
this->listen(createListenMessage(topics, account));
if (ec) {
Log("Unable to send message to websocket server: {}", ec.message());
log("Unable to send message to websocket server: {}", ec.message());
return;
}
}
@@ -544,11 +544,11 @@ void PubSub::listenToChannelModerationActions(
std::string topic(fS("chat_moderator_actions.{}.{}", userID, channelID));
if (this->isListeningToTopic(topic)) {
Log("We are already listening to topic {}", topic);
log("We are already listening to topic {}", topic);
return;
}
Log("Listen to topic {}", topic);
log("Listen to topic {}", topic);
this->listenToTopic(topic, account);
}
@@ -564,18 +564,18 @@ void PubSub::listenToTopic(const std::string &topic,
void PubSub::listen(rapidjson::Document &&msg)
{
if (this->tryListen(msg)) {
Log("Successfully listened!");
log("Successfully listened!");
return;
}
Log("Added to the back of the queue");
log("Added to the back of the queue");
this->requests.emplace_back(
std::make_unique<rapidjson::Document>(std::move(msg)));
}
bool PubSub::tryListen(rapidjson::Document &msg)
{
Log("tryListen with {} clients", this->clients.size());
log("tryListen with {} clients", this->clients.size());
for (const auto &p : this->clients) {
const auto &client = p.second;
if (client->listen(msg)) {
@@ -608,13 +608,13 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl,
rapidjson::ParseResult res = msg.Parse(payload.c_str());
if (!res) {
Log("Error parsing message '{}' from PubSub: {}", payload,
log("Error parsing message '{}' from PubSub: {}", payload,
rapidjson::GetParseError_En(res.Code()));
return;
}
if (!msg.IsObject()) {
Log("Error parsing message '{}' from PubSub. Root object is not an "
log("Error parsing message '{}' from PubSub. Root object is not an "
"object",
payload);
return;
@@ -623,7 +623,7 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl,
std::string type;
if (!rj::getSafe(msg, "type", type)) {
Log("Missing required string member `type` in message root");
log("Missing required string member `type` in message root");
return;
}
@@ -631,14 +631,14 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl,
this->handleListenResponse(msg);
} else if (type == "MESSAGE") {
if (!msg.HasMember("data")) {
Log("Missing required object member `data` in message root");
log("Missing required object member `data` in message root");
return;
}
const auto &data = msg["data"];
if (!data.IsObject()) {
Log("Member `data` must be an object");
log("Member `data` must be an object");
return;
}
@@ -654,7 +654,7 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl,
client.second->handlePong();
} else {
Log("Unknown message type: {}", type);
log("Unknown message type: {}", type);
}
}
@@ -699,7 +699,7 @@ PubSub::WebsocketContextPtr PubSub::onTLSInit(websocketpp::connection_hdl hdl)
boost::asio::ssl::context::no_sslv2 |
boost::asio::ssl::context::single_dh_use);
} catch (const std::exception &e) {
Log("Exception caught in OnTLSInit: {}", e.what());
log("Exception caught in OnTLSInit: {}", e.what());
}
return ctx;
@@ -714,12 +714,12 @@ void PubSub::handleListenResponse(const rapidjson::Document &msg)
rj::getSafe(msg, "nonce", nonce);
if (error.empty()) {
Log("Successfully listened to nonce {}", nonce);
log("Successfully listened to nonce {}", nonce);
// Nothing went wrong
return;
}
Log("PubSub error: {} on nonce {}", error, nonce);
log("PubSub error: {} on nonce {}", error, nonce);
return;
}
}
@@ -729,14 +729,14 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
QString topic;
if (!rj::getSafe(outerData, "topic", topic)) {
Log("Missing required string member `topic` in outerData");
log("Missing required string member `topic` in outerData");
return;
}
std::string payload;
if (!rj::getSafe(outerData, "message", payload)) {
Log("Expected string message in outerData");
log("Expected string message in outerData");
return;
}
@@ -745,7 +745,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
rapidjson::ParseResult res = msg.Parse(payload.c_str());
if (!res) {
Log("Error parsing message '{}' from PubSub: {}", payload,
log("Error parsing message '{}' from PubSub: {}", payload,
rapidjson::GetParseError_En(res.Code()));
return;
}
@@ -754,7 +754,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
std::string whisperType;
if (!rj::getSafe(msg, "type", whisperType)) {
Log("Bad whisper data");
log("Bad whisper data");
return;
}
@@ -765,7 +765,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
} else if (whisperType == "thread") {
// Handle thread?
} else {
Log("Invalid whisper type: {}", whisperType);
log("Invalid whisper type: {}", whisperType);
assert(false);
return;
}
@@ -777,30 +777,30 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
std::string moderationAction;
if (!rj::getSafe(data, "moderation_action", moderationAction)) {
Log("Missing moderation action in data: {}", rj::stringify(data));
log("Missing moderation action in data: {}", rj::stringify(data));
return;
}
auto handlerIt = this->moderationActionHandlers.find(moderationAction);
if (handlerIt == this->moderationActionHandlers.end()) {
Log("No handler found for moderation action {}", moderationAction);
log("No handler found for moderation action {}", moderationAction);
return;
}
// Invoke handler function
handlerIt->second(data, topicParts[2]);
} else {
Log("Unknown topic: {}", topic);
log("Unknown topic: {}", topic);
return;
}
}
void PubSub::runThread()
{
Log("Start pubsub manager thread");
log("Start pubsub manager thread");
this->websocketClient.run();
Log("Done with pubsub manager thread");
log("Done with pubsub manager thread");
}
} // namespace chatterino