From 3bb85ee27712dea5907a3fd9e85330410b3c4f24 Mon Sep 17 00:00:00 2001 From: Nils Date: Wed, 23 Jun 2021 11:42:50 +0200 Subject: [PATCH] Some more test code --- services/test.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/services/test.cpp b/services/test.cpp index 44e0217..256a6cd 100644 --- a/services/test.cpp +++ b/services/test.cpp @@ -42,7 +42,7 @@ async::result TestService::intitialize() { }; 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(serviceChannel.get_topic("IRC Service channel", user.uid)); co_await i->send_event(user.get_notice("Test... Hello world!", serviceChannel.name)); } @@ -52,22 +52,30 @@ async::result TestService::on_event(const Event& event) { 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 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); + 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("Unknown command", author->uid); + response = user.get_notice("Insufficient arguments?", author->uid); } co_await i->send_event(response); }