summaryrefslogtreecommitdiff
path: root/bot/src/modules
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-12-07 17:24:25 +0500
committerilotterytea <iltsu@alright.party>2024-12-07 17:24:25 +0500
commit52fd4ea8bad5cd7d3940a41df4f8f54b4e72beae (patch)
tree28f13892e7da8ec023f4b4d1113bef88795724ca /bot/src/modules
parente604d12282b8fa9f9023bb79161b36c9a8b0be55 (diff)
feat: a special class for command responses
Diffstat (limited to 'bot/src/modules')
-rw-r--r--bot/src/modules/chatters.hpp14
-rw-r--r--bot/src/modules/custom_command.hpp24
-rw-r--r--bot/src/modules/event.hpp20
-rw-r--r--bot/src/modules/help.hpp15
-rw-r--r--bot/src/modules/join.hpp37
-rw-r--r--bot/src/modules/massping.hpp8
-rw-r--r--bot/src/modules/notify.hpp20
-rw-r--r--bot/src/modules/ping.hpp17
-rw-r--r--bot/src/modules/timer.hpp21
9 files changed, 88 insertions, 88 deletions
diff --git a/bot/src/modules/chatters.hpp b/bot/src/modules/chatters.hpp
index fe921ab..6e4c61c 100644
--- a/bot/src/modules/chatters.hpp
+++ b/bot/src/modules/chatters.hpp
@@ -4,7 +4,6 @@
#include <iomanip>
#include <sstream>
#include <string>
-#include <variant>
#include <vector>
#include "../bundle.hpp"
@@ -25,9 +24,8 @@ namespace bot::mod {
int get_delay_seconds() const override { return 10; }
- std::variant<std::vector<std::string>, std::string> run(
- const InstanceBundle &bundle,
- const command::Request &request) const override {
+ command::Response run(const InstanceBundle &bundle,
+ const command::Request &request) const override {
if (!bundle.configuration.url.paste_service.has_value()) {
throw ResponseException<ResponseError::ILLEGAL_COMMAND>(
request, bundle.localization);
@@ -65,9 +63,11 @@ namespace bot::mod {
std::string url = *bundle.configuration.url.paste_service + "/" + id;
- return bundle.localization
- .get_formatted_line(request, loc::LineId::ChattersResponse, {url})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::ChattersResponse,
+ {url})
+ .value());
} else {
throw ResponseException<ResponseError::EXTERNAL_API_ERROR>(
request, bundle.localization, response.status_code,
diff --git a/bot/src/modules/custom_command.hpp b/bot/src/modules/custom_command.hpp
index 50b3692..9fd1429 100644
--- a/bot/src/modules/custom_command.hpp
+++ b/bot/src/modules/custom_command.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <string>
-#include <variant>
#include <vector>
#include "../bundle.hpp"
@@ -21,9 +20,8 @@ namespace bot {
return {"new", "remove"};
}
- std::variant<std::vector<std::string>, std::string> run(
- const InstanceBundle &bundle,
- const command::Request &request) const override {
+ command::Response run(const InstanceBundle &bundle,
+ const command::Request &request) const override {
if (!request.subcommand_id.has_value()) {
throw ResponseException<NOT_ENOUGH_ARGUMENTS>(
request, bundle.localization, command::SUBCOMMAND);
@@ -68,10 +66,11 @@ namespace bot {
"', '" + m + "')");
work.commit();
- return bundle.localization
- .get_formatted_line(request, loc::LineId::CustomcommandNew,
- {name})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::CustomcommandNew,
+ {name})
+ .value());
} else if (subcommand_id == "remove") {
if (cmds.empty()) {
throw ResponseException<ResponseError::NOT_FOUND>(
@@ -82,10 +81,11 @@ namespace bot {
std::to_string(cmds[0][0].as<int>()));
work.commit();
- return bundle.localization
- .get_formatted_line(request, loc::LineId::CustomcommandDelete,
- {name})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(
+ request, loc::LineId::CustomcommandDelete, {name})
+ .value());
}
throw ResponseException<ResponseError::SOMETHING_WENT_WRONG>(
diff --git a/bot/src/modules/event.hpp b/bot/src/modules/event.hpp
index 4242f07..58695d9 100644
--- a/bot/src/modules/event.hpp
+++ b/bot/src/modules/event.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <string>
-#include <variant>
#include <vector>
#include "../bundle.hpp"
@@ -22,9 +21,8 @@ namespace bot {
return {"on", "off"};
}
- std::variant<std::vector<std::string>, std::string> run(
- const InstanceBundle &bundle,
- const command::Request &request) const override {
+ command::Response run(const InstanceBundle &bundle,
+ const command::Request &request) const override {
if (!request.subcommand_id.has_value()) {
throw ResponseException<NOT_ENOUGH_ARGUMENTS>(
request, bundle.localization, command::SUBCOMMAND);
@@ -119,9 +117,10 @@ namespace bot {
work.exec(query);
work.commit();
- return bundle.localization
- .get_formatted_line(request, loc::LineId::EventOn, {t})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::EventOn, {t})
+ .value());
} else if (subcommand_id == "off") {
if (event.empty()) {
throw ResponseException<ResponseError::NOT_FOUND>(
@@ -132,9 +131,10 @@ namespace bot {
std::to_string(event[0][0].as<int>()));
work.commit();
- return bundle.localization
- .get_formatted_line(request, loc::LineId::EventOff, {t})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::EventOff, {t})
+ .value());
}
throw ResponseException<ResponseError::SOMETHING_WENT_WRONG>(
diff --git a/bot/src/modules/help.hpp b/bot/src/modules/help.hpp
index 13af228..1341b86 100644
--- a/bot/src/modules/help.hpp
+++ b/bot/src/modules/help.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <string>
-#include <variant>
#include <vector>
#include "../bundle.hpp"
@@ -13,18 +12,18 @@ namespace bot {
class Help : public command::Command {
std::string get_name() const override { return "help"; }
- std::variant<std::vector<std::string>, std::string> run(
- const InstanceBundle &bundle,
- const command::Request &request) const override {
+ command::Response run(const InstanceBundle &bundle,
+ const command::Request &request) const override {
if (!bundle.configuration.url.help.has_value()) {
throw ResponseException<ResponseError::ILLEGAL_COMMAND>(
request, bundle.localization);
}
- return bundle.localization
- .get_formatted_line(request, loc::LineId::HelpResponse,
- {*bundle.configuration.url.help})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::HelpResponse,
+ {*bundle.configuration.url.help})
+ .value());
}
};
}
diff --git a/bot/src/modules/join.hpp b/bot/src/modules/join.hpp
index 16e8b4a..6818c01 100644
--- a/bot/src/modules/join.hpp
+++ b/bot/src/modules/join.hpp
@@ -2,7 +2,6 @@
#include <pqxx/pqxx>
#include <string>
-#include <variant>
#include <vector>
#include "../bundle.hpp"
@@ -14,9 +13,8 @@ namespace bot {
class Join : public command::Command {
std::string get_name() const override { return "join"; }
- std::variant<std::vector<std::string>, std::string> run(
- const InstanceBundle &bundle,
- const command::Request &request) const override {
+ command::Response run(const InstanceBundle &bundle,
+ const command::Request &request) const override {
if (!bundle.configuration.commands.join_allowed) {
std::string owner = "";
@@ -28,10 +26,11 @@ namespace bot {
.value();
}
- return bundle.localization
- .get_formatted_line(request, loc::LineId::JoinNotAllowed,
- {owner})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::JoinNotAllowed,
+ {owner})
+ .value());
}
if (!bundle.configuration.commands.join_allow_from_other_chats &&
@@ -59,14 +58,17 @@ namespace bot {
bundle.irc_client.join(channel.get_alias_name());
- return bundle.localization
- .get_formatted_line(request, loc::LineId::JoinRejoined, {})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::JoinRejoined,
+ {})
+ .value());
}
- return bundle.localization
- .get_formatted_line(request, loc::LineId::JoinAlreadyIn, {})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::JoinAlreadyIn, {})
+ .value());
}
work.exec("INSERT INTO channels(alias_id, alias_name) VALUES (" +
@@ -82,9 +84,10 @@ namespace bot {
{})
.value());
- return bundle.localization
- .get_formatted_line(request, loc::LineId::JoinResponse, {})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::JoinResponse, {})
+ .value());
}
};
}
diff --git a/bot/src/modules/massping.hpp b/bot/src/modules/massping.hpp
index 2957e34..23d67d3 100644
--- a/bot/src/modules/massping.hpp
+++ b/bot/src/modules/massping.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <string>
-#include <variant>
#include <vector>
#include "../bundle.hpp"
@@ -18,9 +17,8 @@ namespace bot {
int get_delay_seconds() const override { return 1; }
- std::variant<std::vector<std::string>, std::string> run(
- const InstanceBundle &bundle,
- const command::Request &request) const override {
+ command::Response run(const InstanceBundle &bundle,
+ const command::Request &request) const override {
auto chatters = bundle.helix_client.get_chatters(
request.channel.get_alias_id(), bundle.irc_client.get_bot_id());
@@ -55,7 +53,7 @@ namespace bot {
msgs2.push_back(base + m);
}
- return msgs2;
+ return command::Response(msgs2);
}
};
}
diff --git a/bot/src/modules/notify.hpp b/bot/src/modules/notify.hpp
index 3587e73..a25b34f 100644
--- a/bot/src/modules/notify.hpp
+++ b/bot/src/modules/notify.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <string>
-#include <variant>
#include <vector>
#include "../bundle.hpp"
@@ -18,9 +17,8 @@ namespace bot {
return {"sub", "unsub"};
}
- std::variant<std::vector<std::string>, std::string> run(
- const InstanceBundle &bundle,
- const command::Request &request) const override {
+ command::Response run(const InstanceBundle &bundle,
+ const command::Request &request) const override {
if (!request.subcommand_id.has_value()) {
throw ResponseException<NOT_ENOUGH_ARGUMENTS>(
request, bundle.localization, command::SUBCOMMAND);
@@ -105,9 +103,10 @@ namespace bot {
std::to_string(request.user.get_id()));
work.commit();
- return bundle.localization
- .get_formatted_line(request, loc::LineId::NotifySub, {t})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::NotifySub, {t})
+ .value());
} else if (subcommand_id == "unsub") {
if (subs.empty()) {
throw ResponseException<ResponseError::NOT_FOUND>(
@@ -118,9 +117,10 @@ namespace bot {
std::to_string(subs[0][0].as<int>()));
work.commit();
- return bundle.localization
- .get_formatted_line(request, loc::LineId::NotifyUnsub, {t})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::NotifyUnsub, {t})
+ .value());
}
throw ResponseException<ResponseError::SOMETHING_WENT_WRONG>(
diff --git a/bot/src/modules/ping.hpp b/bot/src/modules/ping.hpp
index 836917d..cc982f6 100644
--- a/bot/src/modules/ping.hpp
+++ b/bot/src/modules/ping.hpp
@@ -6,7 +6,6 @@
#include <chrono>
#include <string>
-#include <variant>
#include <vector>
#include "../bundle.hpp"
@@ -18,9 +17,8 @@ namespace bot {
class Ping : public command::Command {
std::string get_name() const override { return "ping"; }
- std::variant<std::vector<std::string>, std::string> run(
- const InstanceBundle &bundle,
- const command::Request &request) const override {
+ command::Response run(const InstanceBundle &bundle,
+ const command::Request &request) const override {
auto now = std::chrono::steady_clock::now();
auto duration = now - START_TIME;
auto seconds =
@@ -48,11 +46,12 @@ namespace bot {
cpp_info.append(" ยท ");
}
- return bundle.localization
- .get_formatted_line(
- request, loc::LineId::PingResponse,
- {cpp_info, uptime, std::to_string(used_memory)})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(
+ request, loc::LineId::PingResponse,
+ {cpp_info, uptime, std::to_string(used_memory)})
+ .value());
}
};
}
diff --git a/bot/src/modules/timer.hpp b/bot/src/modules/timer.hpp
index 36c3982..5fd3549 100644
--- a/bot/src/modules/timer.hpp
+++ b/bot/src/modules/timer.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <string>
-#include <variant>
#include <vector>
#include "../bundle.hpp"
@@ -21,9 +20,8 @@ namespace bot {
return {"new", "remove"};
}
- std::variant<std::vector<std::string>, std::string> run(
- const InstanceBundle &bundle,
- const command::Request &request) const override {
+ command::Response run(const InstanceBundle &bundle,
+ const command::Request &request) const override {
if (!request.subcommand_id.has_value()) {
throw ResponseException<NOT_ENOUGH_ARGUMENTS>(
request, bundle.localization, command::SUBCOMMAND);
@@ -86,9 +84,10 @@ namespace bot {
"', '" + m + "', " + std::to_string(interval_s) + ")");
work.commit();
- return bundle.localization
- .get_formatted_line(request, loc::LineId::TimerNew, {name})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::TimerNew, {name})
+ .value());
} else if (subcommand_id == "remove") {
if (timers.empty()) {
throw ResponseException<ResponseError::NOT_FOUND>(
@@ -99,9 +98,11 @@ namespace bot {
std::to_string(timers[0][0].as<int>()));
work.commit();
- return bundle.localization
- .get_formatted_line(request, loc::LineId::TimerDelete, {name})
- .value();
+ return command::Response(
+ bundle.localization
+ .get_formatted_line(request, loc::LineId::TimerDelete,
+ {name})
+ .value());
}
throw ResponseException<ResponseError::SOMETHING_WENT_WRONG>(