/* * asbots * Copyright (C) 2021 niansa * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "test.hpp" #include "../utility.hpp" #include #include using fmt::operator""_format; async::result TestService::intitialize() { co_await i->netInfo.wait_ready(); user = { .server = i->config.server.uid, .nick = "services", .ident = "services", .realhost = "services.", .uid = uuid, .realname = i->netInfo.name, .loginName = "serviceD" }; Channel serviceChannel = { .server = i->config.server.uid, .name = std::string(getConfig("testservice", "channel").value_or("#services")) }; co_await mark_ready(user); co_await i->send_event(serviceChannel.get_sjoin(user.uid)); //co_await i->send_event(serviceChannel.get_topic("IRC Service channel", user.uid)); co_await i->send_event(user.get_notice("Test... Hello world!", serviceChannel.name)); } async::result TestService::on_event(const Event& event) { co_return; } async::result TestService::on_direct_privmsg(std::string_view msg, u_User &author) { auto cmd = Utility::strSplit(msg, ' ', 1); auto command = Utility::lowers(cmd[0]); Event response = user.get_notice("You need to log in as NetOP first", author->uid); if (cmd.size() == 2 && !cmd[1].empty()) { if (command == "login") { co_await i->send_event(author->get_encap_su(cmd[1])); response = user.get_notice("Logged in!", author->uid); } else if (command == "send") { if (author->loginName.value_or("") == "NetOP") { Event event; try { event.parse(cmd[1]); co_await i->send_event(event); response = user.get_notice("Sent.", author->uid); } catch (std::exception&e) { response = user.get_notice(e.what(), author->uid); } } } else { response = user.get_notice("Unknown command", author->uid); } } else { response = user.get_notice("Insufficient arguments?", author->uid); } co_await i->send_event(response); }