This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Simple allmusic.com trigger

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
l
liljim
Voice
Posts: 12
Joined: Tue Dec 11, 2007 6:51 pm

Simple allmusic.com trigger

Post by liljim »

I would like a trigger script to return a search string for allmusic.com. The allmusic search string works as follows:

Artist: http://www.allmusic.com/cg/amg.dll?p=am ... iles|davis
Album: http://www.allmusic.com/cg/amg.dll?p=am ... nd|of|blue
Song: http://www.allmusic.com/cg/amg.dll?p=am ... freeloader
Style: http://www.allmusic.com/cg/amg.dll?p=amg&sql=4:jazz
Label: http://www.allmusic.com/cg/amg.dll?p=amg&sql=5:columbia

As you can see, spaces need to be replaced by | and sql=# changes according to the search type. Ideally I'd like to have a trigger for each search type like this:

<user> !artist nine inch nails
<bot> Artist search: http://www.allmusic.com/cg/amg.dll?p=am ... inch|nails
<user> !song hurt
<bot> Song search: http://www.allmusic.com/cg/amg.dll?p=amg&sql=3:hurt

I've tried to learn how to do this myself and I'm sure it's very simple, but I just can't wrap my mind around it. Help would be greatly appreciated.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

setudef flag allmusic

bind pubm -|- "*" allmusic:reply

proc allmusic:reply {nick uhand hand chan input} {
  # simple channel flag return if turned off
  if {[lsearch -exact [channel info $chan] +allmusic] == -1} { return 0 }
  switch [string tolower [lindex [split $input] 0]] {
    !artist { putserv "PRIVMSG $chan :Artist search: http://www.allmusic.com/cg/amg.dll?p=amg&sql=1:[string map -nocase {" "	"%20"} [join [lrange [split $input] 1 end]]]" }
    !album  { putserv "PRIVMSG $chan :Album search: http://www.allmusic.com/cg/amg.dll?p=amg&sql=2:[string map -nocase {" "	"%20"} [join [lrange [split $input] 1 end]]]" }
    !song   { putserv "PRIVMSG $chan :Song search: http://www.allmusic.com/cg/amg.dll?p=amg&sql=3:[string map -nocase {" "	"%20"} [join [lrange [split $input] 1 end]]]" }
    !style  { putserv "PRIVMSG $chan :Style search: http://www.allmusic.com/cg/amg.dll?p=amg&sql=4:[string map -nocase {" "	"%20"} [join [lrange [split $input] 1 end]]]" }
    !label  { putserv "PRIVMSG $chan :Label search: http://www.allmusic.com/cg/amg.dll?p=amg&sql=5:[string map -nocase {" "	"%20"} [join [lrange [split $input] 1 end]]]" }
    default { return 0 }
  }
}

#deny-word-wrap###############################################################################################################################################################
In and of itself, this is a very very basic beginning for you. You will still need to validate input and formulate some kind of flood protection.

What you have is the string map to change spaces to %20's which also works like your pipe's | do.. %20 is more logical to use in this case. Keep in mind you will more than likely need to trap bad user input (think people purposely trying to break your bot giving it invalid or special characters) during your input validation part and maybe lengthen the string map i've used in each switch to control them as well. You also have your switch for the different triggers. I used a single bind to * because it's easier to sort triggers with one proc, than to build several seperate ones. Not tested but should work, albeit with the minor problems mentioned above because I'm leaving some of the fun up to you in creating the script. :)

Edit: Added a simple chanset flag +/-allmusic. This way you can beter refine where this actually produces an output so as your tailoring this script it isn't possible for others to trigger it elsewhere if your bot resides in several channels. A helpful addition. ;)

Remember to 1 source scripts/this-script.tcl in your eggdrop.conf, 2 .rehash, 3 then finally .chanset #yourchan +allmusic for this to work at all.
Last edited by speechles on Mon Dec 17, 2007 8:16 pm, edited 1 time in total.
l
liljim
Voice
Posts: 12
Joined: Tue Dec 11, 2007 6:51 pm

Post by liljim »

Perfect. Thank you very much!
Post Reply