From 31846cf5c186c19bb7f4c47d52d6fc78686cc668 Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Sun, 26 May 2024 20:36:25 +0200 Subject: [PATCH] feat(notify): add notify-server --- install.lua | 3 ++- libs/notify.lua | 6 +++--- notify-server.lua | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 notify-server.lua diff --git a/install.lua b/install.lua index cba62a2..7d895d8 100644 --- a/install.lua +++ b/install.lua @@ -14,7 +14,8 @@ local LIST_TURTLE_CONFIG_FILES = { } local LIST_SERVER_FILES = { - 'inferium-server.lua' + 'inferium-server.lua', + 'notify-server.lua' } local LIST_SERVER_CONFIG_FILES = { diff --git a/libs/notify.lua b/libs/notify.lua index 567fc27..0910ff1 100644 --- a/libs/notify.lua +++ b/libs/notify.lua @@ -4,12 +4,12 @@ local notify = {} local DEFAULT_PREFIX = 'chatBox' -notify.NOTIFY_SERVER = 'notify.com' +notify.SERVER = 'notify.com' notify.sendChatMessage = function(message, prefix) - prefix = prefix or DEFAULT_PREFIX + prefix = prefix or os.getComputerLabel() or DEFAULT_PREFIX - return net.sendQuery(notify.NOTIFY_SERVER, { + return net.sendQuery(notify.SERVER, { type = 'notify-chat', payload = { prefix = prefix, diff --git a/notify-server.lua b/notify-server.lua new file mode 100644 index 0000000..2d291f9 --- /dev/null +++ b/notify-server.lua @@ -0,0 +1,31 @@ +local notify = require('libs/notify') +local net = require('libs/net') + +local VERSION = '1.0.0' + +local chatBox = peripheral.find('chatBox') or error('no chatBox peripheral found', 0) + +local function notifyChat(message, prefix) + if not message then + print('warning: no message provided') + return + end + + chatBox.sendMessage(message, prefix) +end + +local function main() + net.openRednet() + + print('Notify Server v' .. VERSION .. ' started') + + net.listenQuery(notify.SERVER, function(message) + if message.type == 'notify-chat' and message.payload then + notifyChat(message.payload.message, message.payload.prefix) + end + end) + + net.closeRednet() +end + +main() \ No newline at end of file