MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / makeChatCallbacks

Method makeChatCallbacks

source/frontend/StarInterfaceLuaBindings.cpp:53–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53LuaCallbacks LuaBindings::makeChatCallbacks(MainInterface* mainInterface, UniverseClient* client) {
54 LuaCallbacks callbacks;
55
56 auto chat = as<Chat>(mainInterface->paneManager()->registeredPane(MainInterfacePanes::Chat).get());
57
58 callbacks.registerCallback("send", [client](String const& message, Maybe<String> modeName, Maybe<bool> speak, Maybe<JsonObject> data) {
59 auto sendMode = modeName ? ChatSendModeNames.getLeft(*modeName) : ChatSendMode::Broadcast;
60 client->sendChat(message, sendMode, speak, data);
61 });
62
63 // just for SE compat - this shoulda been a utility callback :moyai:
64 callbacks.registerCallback("parseArguments", [](String const& args) -> LuaVariadic<Json> {
65 return Json::parseSequence(args).toArray();
66 });
67
68 callbacks.registerCallback("command", [mainInterface](String const& command) -> StringList {
69 return mainInterface->commandProcessor()->handleCommand(command);
70 });
71
72 callbacks.registerCallback("addMessage", [client, chat](String const& text, Maybe<Json> config) {
73 ChatReceivedMessage message({MessageContext::Mode::CommandResult, ""}, client->clientContext()->connectionId(), "", text);
74 if (config) {
75 if (auto mode = config->optString("mode"))
76 message.context.mode = MessageContextModeNames.getLeft(*mode);
77 if (auto channelName = config->optString("channelName"))
78 message.context.channelName = std::move(*channelName);
79 if (auto portrait = config->optString("portrait"))
80 message.portrait = std::move(*portrait);
81 if (auto fromNick = config->optString("fromNick"))
82 message.fromNick = std::move(*fromNick);
83 }
84 chat->addMessages({std::move(message)}, config ? config->getBool("showPane", true) : true);
85 });
86
87 callbacks.registerCallback("input", [chat]() -> String {
88 return chat->currentChat();
89 });
90
91 callbacks.registerCallback("setInput", [chat](String const& text, Maybe<bool> moveCursor) -> bool {
92 return chat->setCurrentChat(text, moveCursor.value(false));
93 });
94
95 callbacks.registerCallback("clear", [chat](Maybe<size_t> count) {
96 chat->clear(count.value(std::numeric_limits<size_t>::max()));
97 });
98
99 return callbacks;
100}
101
102}

Callers

nothing calls this directly

Calls 15

registeredPaneMethod · 0.80
sendChatMethod · 0.80
toArrayMethod · 0.80
commandProcessorMethod · 0.80
connectionIdMethod · 0.80
optStringMethod · 0.80
addMessagesMethod · 0.80
getBoolMethod · 0.80
currentChatMethod · 0.80
setCurrentChatMethod · 0.80
getMethod · 0.45
paneManagerMethod · 0.45

Tested by

no test coverage detected