From 428998889e9bb60c7dc46388184b07c489ddaeb2 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 4 Dec 2025 01:26:30 +0500 Subject: feat: trusted users --- bot/src/commands/lua.cpp | 2 ++ bot/src/commands/lua.hpp | 4 +++- bot/src/commands/request.cpp | 11 +++++++++-- bot/src/commands/request.hpp | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) (limited to 'bot/src/commands') diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index f0d3dab..9e84f8e 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -1005,6 +1005,8 @@ namespace bot::command::lua { this->level = schemas::PermissionLevel::MODERATOR; } else if (rights_text == "broadcaster") { this->level = schemas::PermissionLevel::BROADCASTER; + } else if (rights_text == "trusted") { + this->level = schemas::PermissionLevel::TRUSTED; } else { this->level = schemas::PermissionLevel::USER; } diff --git a/bot/src/commands/lua.hpp b/bot/src/commands/lua.hpp index 2f236f2..1a1c9f9 100644 --- a/bot/src/commands/lua.hpp +++ b/bot/src/commands/lua.hpp @@ -97,7 +97,8 @@ namespace bot::command::lua { command::Response run(const InstanceBundle& bundle, const command::Request& request) const override { - if (!bundle.configuration.lua.allow_arbitrary_scripts) { + if (!bundle.configuration.lua.allow_arbitrary_scripts && + request.requester.user_rights.get_level() < schemas::TRUSTED) { throw ResponseException( request, bundle.localization); } @@ -126,6 +127,7 @@ namespace bot::command::lua { } if (!bundle.configuration.lua.allow_arbitrary_scripts && + request.requester.user_rights.get_level() < schemas::TRUSTED && !std::any_of(bundle.configuration.lua.script_whitelist.begin(), bundle.configuration.lua.script_whitelist.end(), [&request](const std::string& i) { diff --git a/bot/src/commands/request.cpp b/bot/src/commands/request.cpp index d8a91f9..28638ef 100644 --- a/bot/src/commands/request.cpp +++ b/bot/src/commands/request.cpp @@ -6,9 +6,11 @@ #include #include +#include "config.hpp" #include "constants.hpp" #include "database.hpp" #include "schemas/channel.hpp" +#include "schemas/user.hpp" #include "utils/string.hpp" namespace bot::command { @@ -38,7 +40,7 @@ namespace bot::command { std::optional get_requester( const irc::Message &irc_message, - std::unique_ptr &conn) { + std::unique_ptr &conn, const Configuration &cfg) { // fetching channel std::vector chans = conn->query_all( "SELECT * FROM channels WHERE alias_id = $1", @@ -109,7 +111,12 @@ namespace bot::command { schemas::PermissionLevel level = schemas::PermissionLevel::USER; const auto &badges = irc_message.sender.badges; - if (user.get_alias_id() == channel.get_alias_id()) { + if (std::any_of(cfg.twitch.trusted_user_ids.begin(), + cfg.twitch.trusted_user_ids.end(), [&user](const int &x) { + return x == user.get_alias_id(); + })) { + level = schemas::PermissionLevel::TRUSTED; + } else if (user.get_alias_id() == channel.get_alias_id()) { level = schemas::PermissionLevel::BROADCASTER; } else if (std::any_of(badges.begin(), badges.end(), [&](const auto &x) { return x.first == "moderator"; diff --git a/bot/src/commands/request.hpp b/bot/src/commands/request.hpp index 00d8afc..d76fa6e 100644 --- a/bot/src/commands/request.hpp +++ b/bot/src/commands/request.hpp @@ -43,5 +43,5 @@ namespace bot::command { std::optional get_requester( const irc::Message &irc_message, - std::unique_ptr &conn); + std::unique_ptr &conn, const Configuration &cfg); } -- cgit v1.2.3