Skip to content
This repository was archived by the owner on Jan 18, 2021. It is now read-only.

Commit 73fed73

Browse files
committed
[bus] add chat api
1 parent f6d132f commit 73fed73

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

BuiltinMods/Bus/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
cmake_minimum_required (VERSION 3.8)
22

3-
def_mod (Bus LINK mini_bus DELAY_LINK CommandSupport)
3+
def_mod (Bus LINK mini_bus DELAY_LINK CommandSupport ChatAPI)

BuiltinMods/Bus/chat.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <Core/ServerInstance.h>
2+
3+
#include <base/playerdb.h>
4+
#include <base/base.h>
5+
#include <mods/ChatAPI.h>
6+
7+
#include "global.h"
8+
9+
void ChatHandler(
10+
Mod::PlayerEntry const &entry, std::string &displayName, std::string &content,
11+
Mod::CallbackToken<std::string> &token) {
12+
client->notify("chat", displayName + "\n" + content);
13+
}
14+
15+
static RegisterAPI reg("ChatAPI", true, [] {
16+
Mod::Chat::GetInstance().AddListener(SIG("chat"), {Mod::RecursiveEventHandlerAdaptor(ChatHandler)});
17+
client->register_handler("announce", [](std::string_view content) -> std::string {
18+
Mod::Chat::GetInstance().SendAnnounce(std::string{content});
19+
return "";
20+
});
21+
});

0 commit comments

Comments
 (0)