Skip to content

Commit

Permalink
Feat: Add scripts for MPD channels
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Jun 2, 2024
1 parent 6973cf5 commit 303d771
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Channel/ChannelReadMessages.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- {"order":1,"arguments":[]}

local rc, result = mympd.api("MYMPD_API_CHANNEL_MESSAGES_READ", {})

if rc == 1 or result.totalEntities == 0 then
return
end

local messages = ""
for _, msg in pairs(result.data) do
messages = messages .. msg.channel .. ": " .. msg.message
end

return messages
15 changes: 15 additions & 0 deletions Channel/ChannelSendMessage.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- {"order":1,"arguments":["channel", "message"]}

local channel = mympd_arguments.channel
if not channel or channel == "" then
channel = "myMPD"
end

local rc, result = mympd.api("MYMPD_API_CHANNEL_MESSAGE_SEND", {
channel = channel,
message = mympd_arguments.message
})

if rc == 1 then
return "Failure sending message: " .. result.data.msg
end
14 changes: 14 additions & 0 deletions Channel/ChannelSubscribe.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- {"order":1,"arguments":["channel"]}

local channel = mympd_arguments.channel
if not channel or channel == "" then
channel = "myMPD"
end

local rc, result = mympd.api("MYMPD_API_CHANNEL_SUBSCRIBE", {
channel = channel
})

if rc == 1 then
return "Failure subscribing to the channel: " .. result.data.msg
end
9 changes: 9 additions & 0 deletions Channel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Channel

Scripts for MPD channels.

| SCRIPT | DESCRIPTION |
| ------ | ----------- |
| `ChannelSubscribe.lua` | Subscribes to a channel. Connect it to the `mympd_connected` event to subscribe myMPD to a channel. |
| `ChannelReadMessages.lua` | Reads all messages from a channel. Connect it to the `mpd_message` to receive messages. |
| `ChannelSendMessage.lua` | Sends a message to a channel. |

0 comments on commit 303d771

Please sign in to comment.