1
0
Fork 0
mirror of https://gitlab.com/niansa/asbots.git synced 2025-03-06 20:48:25 +01:00
asbots/services/test.cpp
2021-06-21 15:54:49 +02:00

73 lines
2.4 KiB
C++

/*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "test.hpp"
#include "../utility.hpp"
#include <async/result.hpp>
#include <fmt/format.h>
using fmt::operator""_format;
async::result<void> 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<void> TestService::on_event(const Event& event) {
co_return;
}
async::result<void> 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 first", author->uid);
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);
}
co_await i->send_event(response);
}