summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-08 01:09:32 +0400
committerilotterytea <iltsu@alright.party>2025-04-08 01:09:32 +0400
commite1e754cff8d04269ff9276f7c42c94c8cfe8b85a (patch)
treed8b624a515777a2c560ec02ce68d2b14f80fcfd8
parentdcf15f90e75e127e76e59b431cfc22755f57681a (diff)
feat: !massping in lua
-rw-r--r--bot/src/commands/command.cpp3
-rw-r--r--bot/src/modules/massping.hpp60
-rw-r--r--luamods/massping.lua46
3 files changed, 46 insertions, 63 deletions
diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp
index e29b8bf..19cd31c 100644
--- a/bot/src/commands/command.cpp
+++ b/bot/src/commands/command.cpp
@@ -18,7 +18,6 @@
#include "../modules/event.hpp"
#include "../modules/help.hpp"
#include "../modules/join.hpp"
-#include "../modules/massping.hpp"
#include "../modules/mcsrv.hpp"
#include "../modules/notify.hpp"
#include "../modules/settings.hpp"
@@ -27,7 +26,6 @@
#include "../modules/user.hpp"
#include "../utils/chrono.hpp"
#include "commands/lua.hpp"
-#include "logger.hpp"
#include "modules/lua.hpp"
#include "request.hpp"
#include "response.hpp"
@@ -35,7 +33,6 @@
namespace bot {
namespace command {
CommandLoader::CommandLoader() {
- this->add_command(std::make_unique<mod::Massping>());
this->add_command(std::make_unique<mod::Event>());
this->add_command(std::make_unique<mod::Notify>());
this->add_command(std::make_unique<mod::Join>());
diff --git a/bot/src/modules/massping.hpp b/bot/src/modules/massping.hpp
deleted file mode 100644
index 23d67d3..0000000
--- a/bot/src/modules/massping.hpp
+++ /dev/null
@@ -1,60 +0,0 @@
-#pragma once
-
-#include <string>
-#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; }
-
- 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());
-
- 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 &current_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 command::Response(msgs2);
- }
- };
- }
-}
diff --git a/luamods/massping.lua b/luamods/massping.lua
new file mode 100644
index 0000000..ca700ec
--- /dev/null
+++ b/luamods/massping.lua
@@ -0,0 +1,46 @@
+return {
+ name = "massping",
+ delay_sec = 5,
+ options = {},
+ subcommands = {},
+ minimal_rights = "moderator",
+ handle = function(request)
+ chatters = twitch_get_chatters()
+
+ m = ""
+
+ if request.message ~= nil then
+ m = request.message .. " ·"
+ end
+
+ base = "📣 " .. m .. " "
+ userlines = { "" }
+ index = 1
+
+ max_line_length = 500
+
+ for i = 1, #chatters, 1 do
+ chatter = chatters[i]
+ curmsg = userlines[index]
+ x = "@" .. chatter.login
+
+ if #base + #curmsg + 1 + #x >= max_line_length then
+ index = index + 1
+ end
+
+ if index > #userlines then
+ table.insert(userlines, x)
+ else
+ userlines[index] = curmsg .. " " .. x
+ end
+ end
+
+ msgs = {}
+
+ for i = 1, #userlines, 1 do
+ table.insert(msgs, base .. userlines[i])
+ end
+
+ return msgs
+ end
+}