feat(notify): add notify-server
This commit is contained in:
parent
b5aeb3532e
commit
31846cf5c1
@ -14,7 +14,8 @@ local LIST_TURTLE_CONFIG_FILES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local LIST_SERVER_FILES = {
|
local LIST_SERVER_FILES = {
|
||||||
'inferium-server.lua'
|
'inferium-server.lua',
|
||||||
|
'notify-server.lua'
|
||||||
}
|
}
|
||||||
|
|
||||||
local LIST_SERVER_CONFIG_FILES = {
|
local LIST_SERVER_CONFIG_FILES = {
|
||||||
|
|||||||
@ -4,12 +4,12 @@ local notify = {}
|
|||||||
|
|
||||||
local DEFAULT_PREFIX = 'chatBox'
|
local DEFAULT_PREFIX = 'chatBox'
|
||||||
|
|
||||||
notify.NOTIFY_SERVER = 'notify.com'
|
notify.SERVER = 'notify.com'
|
||||||
|
|
||||||
notify.sendChatMessage = function(message, prefix)
|
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',
|
type = 'notify-chat',
|
||||||
payload = {
|
payload = {
|
||||||
prefix = prefix,
|
prefix = prefix,
|
||||||
|
|||||||
31
notify-server.lua
Normal file
31
notify-server.lua
Normal file
@ -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()
|
||||||
Loading…
Reference in New Issue
Block a user