diff options
| author | ilotterytea <iltsu@alright.party> | 2024-05-02 02:08:01 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-05-02 02:08:01 +0500 |
| commit | 9bb97ad75e32d50a682571fa36bafa79f1e2d014 (patch) | |
| tree | 2b1e34c15ac3c53cb060c3a25075e7ab26efc9ff /src | |
| parent | 645c58e5145027be710ebbec4c4a4a5530f4d1f6 (diff) | |
feat: massping command
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands/command.cpp | 2 | ||||
| -rw-r--r-- | src/modules/massping.hpp | 62 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/commands/command.cpp b/src/commands/command.cpp index 8c097a9..60db7c5 100644 --- a/src/commands/command.cpp +++ b/src/commands/command.cpp @@ -9,6 +9,7 @@ #include <string> #include "../bundle.hpp" +#include "../modules/massping.hpp" #include "../modules/ping.hpp" #include "../utils/chrono.hpp" #include "request.hpp" @@ -17,6 +18,7 @@ namespace bot { namespace command { CommandLoader::CommandLoader() { this->add_command(std::make_unique<mod::Ping>()); + this->add_command(std::make_unique<mod::Massping>()); } void CommandLoader::add_command(std::unique_ptr<Command> command) { diff --git a/src/modules/massping.hpp b/src/modules/massping.hpp new file mode 100644 index 0000000..2957e34 --- /dev/null +++ b/src/modules/massping.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include <string> +#include <variant> +#include <vector> + +#include "../bundle.hpp" +#include "../commands/command.hpp" + +namespace bot { + namespace mod { + class Massping : public command::Command { + std::string get_name() const override { return "massping"; } + + schemas::PermissionLevel get_permission_level() const override { + return schemas::PermissionLevel::MODERATOR; + } + + 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 { + auto chatters = bundle.helix_client.get_chatters( + request.channel.get_alias_id(), bundle.irc_client.get_bot_id()); + + std::string m; + + if (request.message.has_value()) { + m = request.message.value() + " ·"; + } + + std::string base = "📣 " + m + " "; + std::vector<std::string> msgs = {""}; + int index = 0; + + for (const auto &chatter : chatters) { + const std::string ¤t_msg = msgs.at(index); + std::string x = "@" + chatter.login; + + if (base.length() + current_msg.length() + 1 + x.length() >= 500) { + index += 1; + } + + if (index > msgs.size() - 1) { + msgs.push_back(x); + } else { + msgs[index] = current_msg + " " + x; + } + } + + std::vector<std::string> msgs2; + + for (const auto &m : msgs) { + msgs2.push_back(base + m); + } + + return msgs2; + } + }; + } +} |
