summaryrefslogtreecommitdiff
path: root/bot/src/commands
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-12-04 01:26:30 +0500
committerilotterytea <iltsu@alright.party>2025-12-04 01:26:30 +0500
commit428998889e9bb60c7dc46388184b07c489ddaeb2 (patch)
tree872a11239eebbf930c85d846f7cec9f828a43ab5 /bot/src/commands
parent638622d66dbe58ff96b7d1c2c6ec4b040b27da6d (diff)
feat: trusted users
Diffstat (limited to 'bot/src/commands')
-rw-r--r--bot/src/commands/lua.cpp2
-rw-r--r--bot/src/commands/lua.hpp4
-rw-r--r--bot/src/commands/request.cpp11
-rw-r--r--bot/src/commands/request.hpp2
4 files changed, 15 insertions, 4 deletions
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<ResponseError::ILLEGAL_COMMAND>(
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 <string>
#include <vector>
+#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<Requester> get_requester(
const irc::Message<irc::MessageType::Privmsg> &irc_message,
- std::unique_ptr<db::BaseDatabase> &conn) {
+ std::unique_ptr<db::BaseDatabase> &conn, const Configuration &cfg) {
// fetching channel
std::vector<schemas::Channel> chans = conn->query_all<schemas::Channel>(
"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<Requester> get_requester(
const irc::Message<irc::MessageType::Privmsg> &irc_message,
- std::unique_ptr<db::BaseDatabase> &conn);
+ std::unique_ptr<db::BaseDatabase> &conn, const Configuration &cfg);
}