summaryrefslogtreecommitdiff
path: root/bot/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-12 17:33:47 +0500
committerilotterytea <iltsu@alright.party>2025-04-12 17:33:47 +0500
commit1b34dc98d33c78cf2d09f0e46b83aceee0c43694 (patch)
tree30a2fe896701fdc5a23249645da3aa624a77080a /bot/src
parent1f5f33fc2f2c8f5d2239d5506ba53438a090d52d (diff)
feat: !mcsrv in lua
Diffstat (limited to 'bot/src')
-rw-r--r--bot/src/commands/command.cpp2
-rw-r--r--bot/src/modules/join.hpp94
-rw-r--r--bot/src/modules/mcsrv.hpp82
3 files changed, 0 insertions, 178 deletions
diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp
index 8360e63..ad18cd2 100644
--- a/bot/src/commands/command.cpp
+++ b/bot/src/commands/command.cpp
@@ -16,7 +16,6 @@
#include "../modules/custom_command.hpp"
#include "../modules/event.hpp"
#include "../modules/help.hpp"
-#include "../modules/mcsrv.hpp"
#include "../modules/notify.hpp"
#include "../modules/settings.hpp"
#include "../modules/timer.hpp"
@@ -37,7 +36,6 @@ namespace bot {
this->add_command(std::make_unique<mod::Help>());
this->add_command(std::make_unique<mod::Settings>());
this->add_command(std::make_unique<mod::User>());
- this->add_command(std::make_unique<mod::MinecraftServerCheck>());
this->add_command(std::make_unique<mod::LuaExecution>());
this->add_command(std::make_unique<mod::LuaRemoteExecution>());
diff --git a/bot/src/modules/join.hpp b/bot/src/modules/join.hpp
deleted file mode 100644
index 6818c01..0000000
--- a/bot/src/modules/join.hpp
+++ /dev/null
@@ -1,94 +0,0 @@
-#pragma once
-
-#include <pqxx/pqxx>
-#include <string>
-#include <vector>
-
-#include "../bundle.hpp"
-#include "../commands/command.hpp"
-#include "../schemas/channel.hpp"
-
-namespace bot {
- namespace mod {
- class Join : public command::Command {
- std::string get_name() const override { return "join"; }
-
- command::Response run(const InstanceBundle &bundle,
- const command::Request &request) const override {
- if (!bundle.configuration.commands.join_allowed) {
- std::string owner = "";
-
- if (bundle.configuration.owner.name.has_value()) {
- owner = " " + bundle.localization
- .get_formatted_line(
- request, loc::LineId::MsgOwner,
- {*bundle.configuration.owner.name})
- .value();
- }
-
- return command::Response(
- bundle.localization
- .get_formatted_line(request, loc::LineId::JoinNotAllowed,
- {owner})
- .value());
- }
-
- if (!bundle.configuration.commands.join_allow_from_other_chats &&
- request.channel.get_alias_name() !=
- bundle.irc_client.get_bot_username()) {
- return bundle.localization
- .get_formatted_line(request, loc::LineId::JoinFromOtherChat,
- {bundle.irc_client.get_bot_username()})
- .value();
- }
-
- pqxx::work work(request.conn);
-
- pqxx::result channels =
- work.exec("SELECT * FROM channels WHERE alias_id = " +
- std::to_string(request.user.get_alias_id()));
-
- if (!channels.empty()) {
- schemas::Channel channel(channels[0]);
-
- if (channel.get_opted_out_at().has_value()) {
- work.exec("UPDATE channels SET opted_out_at = null WHERE id = " +
- std::to_string(channel.get_id()));
- work.commit();
-
- bundle.irc_client.join(channel.get_alias_name());
-
- return command::Response(
- bundle.localization
- .get_formatted_line(request, loc::LineId::JoinRejoined,
- {})
- .value());
- }
-
- return command::Response(
- bundle.localization
- .get_formatted_line(request, loc::LineId::JoinAlreadyIn, {})
- .value());
- }
-
- work.exec("INSERT INTO channels(alias_id, alias_name) VALUES (" +
- std::to_string(request.user.get_alias_id()) + ", '" +
- request.user.get_alias_name() + "')");
- work.commit();
-
- bundle.irc_client.join(request.user.get_alias_name());
- bundle.irc_client.say(
- request.user.get_alias_name(),
- bundle.localization
- .get_formatted_line(request, loc::LineId::JoinResponseInChat,
- {})
- .value());
-
- return command::Response(
- bundle.localization
- .get_formatted_line(request, loc::LineId::JoinResponse, {})
- .value());
- }
- };
- }
-}
diff --git a/bot/src/modules/mcsrv.hpp b/bot/src/modules/mcsrv.hpp
deleted file mode 100644
index 8027fc2..0000000
--- a/bot/src/modules/mcsrv.hpp
+++ /dev/null
@@ -1,82 +0,0 @@
-#pragma once
-
-#include <string>
-
-#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 MinecraftServerCheck : public command::Command {
- std::string get_name() const override { return "mcsrv"; }
-
- 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);
- }
-
- cpr::Response response = cpr::Get(cpr::Url{
- "https://api.mcsrvstat.us/3/" + request.message.value()});
-
- 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::string online = j["online"] ? "✅" : "⛔";
- std::string ip = "IP N/A";
-
- if (j.contains("ip")) ip = j["ip"];
-
- std::string player_count = "PLAYERS N/A";
-
- if (j.contains("players")) {
- auto players = j["players"];
- player_count = std::to_string(players["online"].get<int>());
- player_count += "/";
- player_count += std::to_string(players["max"].get<int>());
- }
-
- std::string version = "VERSION N/A";
-
- if (j.contains("protocol")) {
- auto protocol = j["protocol"];
- if (protocol.contains("name")) version = protocol["name"];
- }
-
- std::string motd = "MOTD N/A";
-
- if (j.contains("motd")) {
- auto motd_json = j["motd"];
- if (motd_json.contains("clean")) {
- motd.clear();
- for (const auto &line : motd_json["clean"]) {
- motd += line;
- motd += " / ";
- }
- motd = motd.substr(0, motd.size() - 3);
- motd = "\"" + motd + "\"";
- }
- }
-
- std::string msg = online + " " + request.message.value() + " (" + ip +
- ") | " + player_count + " | " + motd + " | " +
- version;
-
- return command::Response(msg);
- }
- };
- }
-}