PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: frankyk on 31 March, 2004, 07:30:52

Title: Music Bot
Post by: frankyk on 31 March, 2004, 07:30:52
Hi,

can someone write me a script that will say something like this:

User [username] tells us he is currently listening to the SONG: [song name] by BAND: [band]

so like:

+listen Jimmy Eat World - In the Middle

would get this displayed:

Bot Name: User BillyBob tells us he is currently listening to the SONG: In the Middle by BAND: Jimmy Eat World

I suppose the - would divide name of the song and band, so spaces wouldn't matter until the - shows up
Title:
Post by: nErBoS on 31 March, 2004, 13:01:09
Hi,

Hope it helps..

--Requested by frankyk
--Made by nErBoS

sBot = "Music-Bot"

function Main()
frmHub:RegBot(sBot)
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd=="!listen") then
ListenMusic(user, data)
return 1
end
end
end

function ListenMusic(user, data)
local s,e,author,music = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.*)")
if (author == nil or music == nil) then
user:SendData(sBot, "Syntax Error, !listen , you must write a name to the author and to the music.")
else
SendToAll(sBot, "User "..user.sName.." tells us he is currently listening to the SONG: "..music.." by BAND: "..author)
end
end

In the Author Name i must have instead of space a underscore in the music name is no problem.

Best regards, nErBoS
Title:
Post by: tezlo on 31 March, 2004, 13:50:04
or with spaces..
+listen -<br><div class="codeheader"><span class="code floatleft">Code</span> <a class="codeoperation smf_select_text">Select</a> <a class="codeoperation smf_expand_code hidden" data-shrink-txt="Shrink" data-expand-txt="Expand">Expand</a></div><code class="bbc_code">function DataArrival(user, data)<br><span style="white-space: pre;"> </span>if strsub(data,1,1) == "<" then<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>local s, e, cmd, args = strfind(data, "^%b<> %+(%a+)%s*(.*)%|$")<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>if s and cmd == "listen" then<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>local s, e, artist, title = strfind(args, "^(.-)%s*%-%s*(.+)$")<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>if s then<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>SendToAll("*** "..user.sName.." now playing "..artist.."-"..title)<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>else<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>user:SendData(">> syntax: +listen <artist>-<title>")<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>end<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return 1<span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>end<br><span style="white-space: pre;"> </span>end<br>end</code> </div><!-- .postbody --> <div class="postheader"> Title: <strong></strong><br> Post by: <strong>frankyk</strong> on <strong>31 March, 2004, 18:48:58</strong> </div> <div class="postbody"> Good script, could you make it so instead of underscore, it takes a space, like linkin park - runaway would display linkin park and song is runaway instead of linkin name, song park runaway or something<br><br>Thanks! </div><!-- .postbody --> <div class="postheader"> Title: <strong></strong><br> Post by: <strong>tezlo</strong> on <strong>31 March, 2004, 19:10:22</strong> </div> <div class="postbody"> right </div><!-- .postbody --> </div><!-- #posts --> <div class="print_options"> <strong><a href="http://forum.ptokax.org/index.php?action=printpage;topic=1761.0">Text only</a></strong> | <a href="http://forum.ptokax.org/index.php?action=printpage;topic=1761.0;images">Text with Images</a> </div><!-- .print_options --> <div id="footer" class="smalltext"><a href="http://forum.ptokax.org/index.php?action=credits" title="License" target="_blank" rel="noopener">SMF 2.1.4 © 2023</a>, <a href="https://www.simplemachines.org" title="Simple Machines" target="_blank" rel="noopener">Simple Machines</a></div> </body> </html>