summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bot/src/commands/command.cpp2
-rw-r--r--bot/src/modules/user.hpp95
-rw-r--r--docs/summary.md8
3 files changed, 101 insertions, 4 deletions
diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp
index 7dd4e47..169ca71 100644
--- a/bot/src/commands/command.cpp
+++ b/bot/src/commands/command.cpp
@@ -20,6 +20,7 @@
#include "../modules/settings.hpp"
#include "../modules/spam.hpp"
#include "../modules/timer.hpp"
+#include "../modules/user.hpp"
#include "../utils/chrono.hpp"
#include "request.hpp"
#include "response.hpp"
@@ -38,6 +39,7 @@ namespace bot {
this->add_command(std::make_unique<mod::Chatters>());
this->add_command(std::make_unique<mod::Spam>());
this->add_command(std::make_unique<mod::Settings>());
+ this->add_command(std::make_unique<mod::User>());
}
void CommandLoader::add_command(std::unique_ptr<Command> command) {
diff --git a/bot/src/modules/user.hpp b/bot/src/modules/user.hpp
new file mode 100644
index 0000000..71f2747
--- /dev/null
+++ b/bot/src/modules/user.hpp
@@ -0,0 +1,95 @@
+#pragma once
+
+#include <exception>
+#include <string>
+#include <vector>
+
+#include "../bundle.hpp"
+#include "../commands/command.hpp"
+#include "../commands/response_error.hpp"
+#include "cpr/api.h"
+#include "cpr/cprtypes.h"
+#include "cpr/response.h"
+#include "nlohmann/json.hpp"
+
+namespace bot {
+ namespace mod {
+ class User : public command::Command {
+ std::string get_name() const override { return "userid"; }
+
+ int get_delay_seconds() const override { return 10; }
+
+ command::Response run(const InstanceBundle &bundle,
+ const command::Request &request) const override {
+ if (!request.message.has_value()) {
+ throw ResponseException<ResponseError::NOT_ENOUGH_ARGUMENTS>(
+ request, bundle.localization, command::CommandArgument::VALUE);
+ }
+
+ std::vector<std::string> parts =
+ utils::string::split_text(request.message.value(), ',');
+
+ std::vector<std::string> ids;
+ std::vector<std::string> logins;
+
+ for (const std::string &part : parts) {
+ if (ids.size() + logins.size() >= 3) break;
+ try {
+ int id = std::stoi(part);
+ ids.push_back(part);
+ } catch (std::exception e) {
+ logins.push_back(part);
+ }
+ }
+
+ std::string query;
+
+ if (!ids.empty()) {
+ query += "id=";
+ query += utils::string::join_vector(ids, ',');
+
+ if (!logins.empty()) query += "&";
+ }
+
+ if (!logins.empty()) {
+ query += "login=";
+ query += utils::string::join_vector(logins, ',');
+ }
+
+ if (query.empty()) {
+ throw ResponseException<ResponseError::INCORRECT_ARGUMENT>(
+ request, bundle.localization, request.message.value());
+ }
+
+ cpr::Response response =
+ cpr::Get(cpr::Url{"https://api.ivr.fi/v2/twitch/user?" + query});
+
+ if (response.status_code != 200) {
+ throw ResponseException<ResponseError::EXTERNAL_API_ERROR>(
+ request, bundle.localization, response.status_code,
+ response.status_line);
+ }
+
+ nlohmann::json j = nlohmann::json::parse(response.text);
+
+ std::vector<std::string> msgs;
+
+ for (const auto &x : j) {
+ std::string name = x["login"];
+ std::string id = x["id"];
+
+ std::string is_banned = x["banned"] ? "⛔" : "✅";
+ std::string ban_reason;
+ if (x.contains("banReason")) ban_reason = x["banReason"];
+
+ std::string msg = is_banned + " " + name + " (" + id + ")" +
+ (ban_reason.empty() ? "" : ": ") + ban_reason;
+
+ msgs.push_back(request.user.get_alias_name() + ": " + msg);
+ }
+
+ return command::Response(msgs);
+ }
+ };
+ }
+}
diff --git a/docs/summary.md b/docs/summary.md
index f5b7a1e..a56d0a0 100644
--- a/docs/summary.md
+++ b/docs/summary.md
@@ -20,6 +20,10 @@
+ [Mass ping](/wiki/mod/mass-ping)
+ [Spam](/wiki/mod/spam)
+## User management
+
++ [User ban check](/wiki/user/ban-check)
+
## Miscellaneous
+ [Ping](/wiki/misc/ping)
@@ -34,10 +38,6 @@
+ [Emote usage leaderboard](/wiki/emotes/top)
+ [Emote set similarity check](/wiki/emotes/sim)
-## User management
-
-+ [User ban check](/wiki/user/ban-check)
-
## Miscellaneous
+ [Minecraft server status check](/wiki/misc/mcsrv)