forked from githtz/mpd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvote.lua
More file actions
68 lines (59 loc) · 1.75 KB
/
vote.lua
File metadata and controls
68 lines (59 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--mpd
--vote.lua - vote module to change songs
function mpd.vote_play(name, param)
id=tonumber(param)
if id and id>0 and id<=#mpd.songs then
vote.new_vote(name, {
description = "Play "..mpd.song_human_readable(id),
help = "/yes or /no",
duration = 20,
perc_needed = 0.4,
on_result = function(self, result, results)
if result == "yes" then
minetest.chat_send_all("Vote to play " .. mpd.song_human_readable(id) .. " passed " ..
#results.yes .. " to " .. #results.no)
mpd.play_song(id)
else
minetest.chat_send_all("Vote to play " .. mpd.song_human_readable(id) .. " failed " ..
#results.yes .. " to " .. #results.no)
end
end,
on_vote = function(self, name, value)
minetest.chat_send_all(name .. " voted " .. value .. " to '" ..
self.description .. "'")
end,
})
return true
end
return false,"Invalid song ID! See available song IDs using /mpd_list"
end
minetest.register_chatcommand("vote_mpd_play", {
func = mpd.vote_play
})
function mpd.vote_next(name, param)
vote.new_vote(name, {
description = "Play next song",
help = "/yes or /no",
duration = 20,
perc_needed = 0.4,
on_result = function(self, result, results)
minetest.chat_send_all(result..dump(results))
if result == "yes" then
minetest.chat_send_all("Vote to play next song passed " ..
#results.yes .. " to " .. #results.no)
mpd.next_song()
else
minetest.chat_send_all("Vote to play next song failed " ..
#results.yes .. " to " .. #results.no)
end
end,
on_vote = function(self, name, value)
minetest.chat_send_all(name .. " voted " .. value .. " to '" ..
self.description .. "'")
end
})
return true
end
minetest.register_chatcommand("vote_mpd_next", {
func = mpd.vote_next
})