--[[ ShoutCast 2.0 LUA 5.1x [Strict][Eximius] By Mutor 05/01/09 Control your ShoutCast via user commands - Requires 'clever.exe' a command line utility to control Winamp 2.x - 5.x. http://www.jukkis.net/ - Offers custom 'level' to restrict commands by profile. - Provides context menus [right click] - Always replies in pm - Option to report command usage to all with that command permission ]] --/ Script Specs, change this and I'll find you and kill you! /-- ScriptDev = "Mutor" ScriptName = "ShoutCast" ScriptVersion = "2.0" ScriptDate = "05/01/09" Path = frmHub:GetStartupPath().."\\Scripts\\" Pfxs = frmHub:GetPrefix():gsub("[ ]","") --//-- -- "Botname" ["" = Use hub bot for Bot] local Bot = "[ShoutCast]" -- "Command Menu" ["" = hub name] Menu = "Eximius" -- "Command SubMenu" ["" = script name] SubMenu = "ShoutCast" -- Path to Clever executable Dir = "C:\\clever\\" -- Report command usage to all with that level or higher? true/false [false = reply to user only] Report = true -- *Minimum profile=[permission level] for ShoutCast commands. Level = {[0] = 4,[1] = 3,[2] = 2,[3] = 1} --[[Command table, with the following assignments; name = {"ToArrival parsing pattern","User command argument prompt","Command Description","SubMenu Title",*MinLevel as Integer} *Min level is the minimum profile level required to receive/use this command. Set levels in table above.]] Cmds = { prev = {"","","Play the previous song in the playlist","Playback Control\\",3}, rewind = {"","","Rewind the current song","Playback Control\\",3}, play = {" ?(%d*)"," %[line:Song Number]","Play the song in playlist position ","Playback Control\\",3}, start = {" ?(%d*)","","Start playback","Playback Control\\",3}, pause = {"","","Pause playback","Playback Control\\",3}, stop = {"","","Stop playback","Playback Control\\",3}, forward = {"","","Skip ahead in the current song","Playback Control\\",3}, status = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Displays current player status","Playback Control\\",1}, next = {"","","Play the next song in the playlist","Playback Control\\",3}, playpause = {"","","Start playing / pause song","Playback Control\\",4}, add = {" (%w+)"," %[line:filename]","Add specified file to pl (mp3 or playlist)","Playlist Management\\",4}, addplay = {""," %[line:filename]","Same as Add, start to play if stopped","Playlist Management\\",3}, load = {" (.+)"," %[line:filename]","Change to specified file (mp3 or playlist)","Playlist Management\\",4}, loadplay = {" (.+)"," %[line:filename]","Same as Load, and start to play","Playlist Management\\",4}, getplpos = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Displays the playlist position starting from 1","Playlist Management\\",4}, setplpos = {" (%d+)"," %[line:Number]","Sets the playlist position starting from 1","Playlist Management\\",4}, clear = {"","","Clears current playlist","Playlist Management\\",4}, getinfo = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Current song samplerate, bps and channels","Playlist Management\\",1}, playlist = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Info about current playlist","Playlist Management\\",1}, volume = {" (%d+)"," %[line:volume (0-255)]","Set volume (0-255)","Volume Control\\",4}, volup = {"","","Increase volume","Volume Control\\",4}, voldn = {"","","Decrease volume","Volume Control\\",4}, np = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Current song title","Now Playing\\",1}, position = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Time elapsed on the current song","Now Playing\\",4}, timeleft = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Time left on the current song","Now Playing\\",4}, songlength = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Length of the currently loaded song","Now Playing\\",4}, alwaysontop = {"","","Toggle Always on Top","Configuration Settings\\",4}, getshuffle = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Displays shuffle state","Configuration Settings\\",2}, swshuffle = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Changes shuffle state. Displays new state","Configuration Settings\\",4}, getrepeat = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Displays repeat state","Configuration Settings\\",2}, swrepeat = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Changes repeat state. Displays new state","Configuration Settings\\",4}, visual = {"","","Execute current visualization plug-in","Configuration Settings\\",4}, licence = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Display Clever BSD Licence","ShoutCast Info\\",1}, whatsnew = {"( %> "..Path.."temp.txt)"," > "..Path.."temp.txt","Display new commands info for Clever","ShoutCast Info\\",1}, schelp = {"","","Display help for all enabled commands","ShoutCast Info\\",1}, } Main = function() if Bot == "" then Bot = frmHub:GetHubBotName() else Bot = Bot:gsub("[$|<>:?*\"/\\]","_") HubBot:Reg(Bot) end if Menu == "" then Menu = frmHub:GetHubName():sub(1,-4) end if SubMenu == "" then SubMenu = ScriptName.." "..ScriptVersion end local t = {} for i,v in pairs(Cmds) do table.insert(t,{i,v[3]}) end table.sort(t, function(a,b) return a[1] < b[1] end) Help = "" for i,v in ipairs(t) do Help = Help.." "..string.format("%-20.20s",v[1]).."\t"..v[2].."\r\n" end Help = "\r\n\r\n"..Help.."\r\n" --SendToNick("Mutor","\r\n\r\n"..Help.."\r\n") end NewUserConnected = function(user) if user.bUserCommand then local lvl,x = Level[user.iProfileNumber],"" if lvl then local t = {} for i,v in pairs(Cmds) do table.insert(t,{i,v[3]}) end table.sort(t, function(a,b) return a[2] < b[2] end) for i,v in pairs(t) do if lvl >= Cmds[v[1]][5] then local uc,mn,sm = "$UserCommand 1 3 ",Menu.."\\",SubMenu.."\\"..Cmds[v[1]][4] local pre = "$<%[mynick]> "..Pfxs:sub(1,1) local pm,p = "$$To: "..Bot.." From: %[mynick] ","||" x = x..uc..mn..sm..Cmds[v[1]][3]..pm..pre..v[1]..Cmds[v[1]][2]..p end end if #x > 0 then user:SendData(x) end collectgarbage("collect") end end end OpConnected = NewUserConnected ToArrival = function(user,data) local lvl = Level[user.iProfileNumber] local _,_,to = data:find("^$To: (%S+) From:") if to and to == Bot then local _,_,cmd = data:find("%b<> ["..Pfxs.."](%l+)") if lvl and cmd and Cmds[cmd] and lvl >= Cmds[cmd][5] then local arg,reply = "","" if cmd:lower() == "schelp" then local t = {} for i,v in pairs(Cmds) do if lvl >= v[5] then table.insert(t,{i,v[4]..v[3]}) end end table.sort(t, function(a,b) return a[1] < b[1] end) for i,v in ipairs(t) do reply = reply.." "..string.format("%-20.20s",v[1]).."\t"..v[2].."\r\n" end user:SendPM(Bot,"ShoutCast commands for "..user.sProfileName.."'s\r\n\r\n"..reply.."\r\n") return 1 else if Cmds[cmd][1] ~= "" then _,_,arg = data:find("%b<> ["..Pfxs.."]"..cmd..Cmds[cmd][1]) end arg = " "..arg or "" local x = os.execute(Dir.."clever.exe "..cmd:gsub("np","playlist"):gsub("start","play")..arg) if arg ~= "" then if arg:find(">",1,true) then local f,e = io.open(Path.."temp.txt") if f then reply = f:read("*a") f:close() if reply ~= "" then if cmd == "np" then local _,_,track = reply:find("(%b><)") if track then reply = "Now Playing: Track#"..track:sub(4,-4) end else reply,n = reply:gsub("[\r\n]","%1") if n > 2 then reply = "you selected the command: ".. cmd..". Result: \r\n\r\n"..reply else reply = "you selected the command: ".. cmd..". Result: "..reply end end end os.remove(Path.."temp.txt") end else if x == 0 then reply = "you used the command: "..cmd..arg..", it was successful." else reply = "you used the command: "..cmd..arg..", it failed." end end else if x == 0 then reply = "you used the command: "..cmd..arg..", it was successful." else reply = "you used the command: "..cmd..arg..", it failed." end end end if reply ~= "" then Send = function(b,n,c,s) local t = GetOnlineUsers(-1) if next(t) then for i,u in ipairs(t) do local usr = GetUserByName(u.sName) if usr and usr.sName:lower() ~= n then local rank = Level[usr.iProfileNumber] if rank and rank >= Cmds[c][5] then usr:SendPM(b,s) end end end end end if Report then Send(Bot,user.sName:lower(),cmd,user.sName.." "..reply:gsub("you ","")) user:SendPM(Bot,reply) else user:SendPM(Bot,reply) end end end end end