diff --git a/driver/main.cpp b/driver/main.cpp index 4a1f2ee..91f6394 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -86,7 +86,11 @@ static auto start_irc( bot->sig_command.connect([webhook, connection](const Bot::Command &cmd) { auto cursor = webhook_commands.find(std::string{cmd.command}); if (cursor != webhook_commands.end()) { - cursor->second(webhook, cmd); + try { + cursor->second(webhook, cmd); + } catch (const std::exception &e) { + BOOST_LOG_TRIVIAL(error) << "Command handler failed: " << e.what(); + } } }); diff --git a/driver/web.cpp b/driver/web.cpp index 6345e82..940c08a 100644 --- a/driver/web.cpp +++ b/driver/web.cpp @@ -484,49 +484,77 @@ std::map, const myirc::Bot::Comm std::string name; if (iss >> name) { - auto cursor = webhooks->settings_.projects.find(name); - if (cursor == webhooks->settings_.projects.end()) - { - return; - } - - auto &project = cursor->second; - + auto &project = webhooks->settings_.projects.at(name); if (not authorized_for_project(cmd, project, cmd.account)) { return; } - project.enabled = true; webhooks->save_settings(); reply_to(webhooks, cmd, "Enabled project " + name); } }}, {"disable-project", [](std::shared_ptr webhooks, const myirc::Bot::Command &cmd) { - //if (cmd.oper.empty()) - //{ - // return; - //} std::istringstream iss{std::string{cmd.arguments}}; std::string name; if (iss >> name) { - auto cursor = webhooks->settings_.projects.find(name); - if (cursor == webhooks->settings_.projects.end()) - { - return; - } - - auto &project = cursor->second; - + auto &project = webhooks->settings_.projects.at(name); if (not authorized_for_project(cmd, project, cmd.account)) { return; } - project.enabled = false; webhooks->save_settings(); reply_to(webhooks, cmd, "Disabled project " + name); } }}, + {"add-access", [](std::shared_ptr webhooks, const myirc::Bot::Command &cmd) { + if (cmd.oper.empty()) + { + return; + } + std::istringstream iss{std::string{cmd.arguments}}; + std::string name, account; + if (iss >> name >> account) + { + auto &project = webhooks->settings_.projects.at(name); + if (not authorized_for_project(cmd, project, cmd.account)) + { + return; + } + auto [_, inserted] = project.authorized_accounts.insert(account); + if (inserted) { + webhooks->save_settings(); + reply_to(webhooks, cmd, "Access added"); + } + else + { + reply_to(webhooks, cmd, "Access already set"); + } + } + }}, + {"drop-access", [](std::shared_ptr webhooks, const myirc::Bot::Command &cmd) { + if (cmd.oper.empty()) + { + return; + } + std::istringstream iss{std::string{cmd.arguments}}; + std::string name, account; + if (iss >> name >> account) + { + auto &project = webhooks->settings_.projects.at(name); + if (not authorized_for_project(cmd, project, cmd.account)) + { + return; + } + auto removed = project.authorized_accounts.erase(account); + if (removed) { + webhooks->save_settings(); + reply_to(webhooks, cmd, "Access dropped"); + } else { + reply_to(webhooks, cmd, "Access not found"); + } + } + }}, };