Well i posted this on the swiftirc showcase and dont see any reason why not to post it on here also.
Its just a little snippet that allows you to send a song dedication to another user in the channel along with a youtube link.
[!@]dedi|dedication <song/artist> <song/artist>
[16:03] <Riffpilgrim> !dedicate darkdan alter bridge broken wings
[16:03] -Bot- ((Dedication)) Dedication sent to darkdan!
[16:19] <Riffpilgrim> !dedi riffpilgrim I shot the sheriff Eric clapton
[16:19] -Bot- ((Dedication)) Riffpilgrim has dedicated: I shot the sheriff Eric clapton to you! [Associated video] www.youtube.com/watch?v=10qLYy6hiFQ
heres a color alias also just incase you don't have one already:
alias c1 return $+($chr(3),07,$1-,$chr(3))
alias c2 return $+($chr(3),14,$1-,$chr(3))
Its just something a bit different I originally made for my bot Beard on the swiftirc network, hope you like it.
alias -l logo return $remove($+($c1($chr(40),$chr(40),$c2($1-),$c1($chr(41),$chr(41)))),$chr(32))
on $*:text:/^[!@]dedi(cate)?/Si:#: {
if (!$2) || (!$3) || ($2 !ison $chan) { .notice $nick $logo(Error) Please specify a song/nick $chr(124) !dedication <nick> <song> <artist> | halt }
if ($left($1,1) == !) .notice $nick $logo(Dedication) $c2(Dedication sent to $2 $+ !)
var %dedi $right($ticks,5),%whom $2
hadd -m $+(durl.,%dedi) whom $2 | hadd -m $+(durl.,%dedi) from $nick | hadd -m $+(durl.,%dedi) info $replace($3-,$chr(32),+)
hadd -m $+(durl.,%dedi) send $iif($left($1,1) == @,.msg $chan,.notice %whom) | hadd -m $+(durl.,%dedi) ornot $iif($left($1,1) == @,to1 %whom,to you!))
sockopen $+(durl.,%dedi) www.youtube.com 80
}
on *:SOCKOPEN:durl.*: {
sockwrite -nt $sockname GET $+(/results?search_query=,$hget($sockname,info),&search=Search) HTTP/1.1
sockwrite -nt $sockname Host: www.youtube.com
sockwrite -nt $sockname $crlf
}
on *:sockread:durl.*: {
if (!$sockerr) {
var %url
sockread %url
if (*No videos found* iswm %url) {
$hget($sockname,send) $logo(Dedication) No videos found
hfree $sockname
}
if ($regex(%url,/id="video-main-content-(.+?)"/i)) {
hadd -m $sockname end $regml(1)
$hget($sockname,send) $logo(Dedication) 1 $hget($sockname,from) $c2(has dedicated:) $c1($replace($hget($sockname,info),+,$chr(32))) $c2($hget($sockname,ornot)) $c1([Associated video]) $c2($+(www.youtube.com/watch?v=,$hget($sockname,end)))
hfree $sockname
sockclose $sockname
}
}
}
Quote:
Is it ever so necessary for every comment to be a criticism of the trigger
Actually if you see it as an "open discussion," rather than a "criticism," it can benefit every one of us to learn from each other and gain more knowledge.
Agreed.
-Cool gooshie I shall steer towards your method next time :)
-fordlawnmower, good idea about using a variable to store the sockname throughout the opening hash table. :D As for using sockmark instead, I simply havn't tried it yet- I think I will give it a go next time though :)
Thanks for the feedback guys
Interesting use of hashtables Riffpilgrim :)
I was just curious why you didn't just use /Sockmark
Your code looks nice and neat except for this redundancy.
--->> $+(durl.,%dedi) <<---
You use it 6 times so it should be a variable like %sockname
Since %dedi is only used with $+(durl.,%dedi)
I would suggest something like this
var %sockname $+(durl.,$right($ticks,5)),%whom $2
And then just use %sockname instead of $+(durl.,%dedi)
Good working code though Riffpilgrim :)
Code:
if (!$2) || (!$3) || ($2 !ison $chan) { .notice $nick $logo(Error) Please specify a song/nick $chr(124) !dedication | halt }
you could remove the !$2 part of the /if statement seeing as if $2 isnt on $chan it wouldnt matter if there was a $2?
I can see what you mean however, in the unlikely event that someone in the channel shares the same name as the dedication i think it should stay in :pCode:
if ($left($1,1) == !) .notice $nick $logo(Dedication) $c2(Dedication sent to $2 $+ !)
may be deliberate but i dont see anything for if $left($1,1) == @
This was deliberate to prevent ".notice $nick $logo(Dedication) $c2(Dedication sent to $2 $+ !)" occurring if the command is used publicly, theres no point displaying the message if they can see the result in the channel.Code:
hadd -m $sockname end $regml(1)
seems redundant if ur just gonna free the table in a few lines comepared to just using $regml(1) instead of $hget($sockname,end)
This however, is very true thanks for pointing it out.
I wasn't expecting to come under as much scrutiny as this :o
& thanks gooshie about the hash tables, i wasn't aware that -m can be used once, when the table is created. Also, this snippet was originally made for my bot which has flood protection - the snippet performs the task outlined and simple flood protection can be added easily.
Well whatever you want to do with the trigger.
Add the \b (boundary) such that it matches on
!dedi !dedicate and !dedication since without
the \b it was gonna match on !dedication anyway
and anything that followed !dedi command.
You could rearrange the whole if !$2 || !$3
to be as follows. No need for %whom just use $2
Only the first hadd needs the -m and %dedi
can be used for the whole hash table name one
time like below.
[size=17]You may want to add flood protection.[/size]
on $*:text:/^[!@]dedi(cate|cation)?\b/Si:#: {
if ($3) && ($2 ison #) {
if ($left($1,1) == !) .notice $nick $logo(Dedication) $c2(Dedication sent to $2 $+ !)
var %dedi $+(durl.,$right($ticks,5))
hadd -m %dedi whom $2
hadd %dedi from $nick
hadd %dedi info $replace($3-,$chr(32),+)
hadd %dedi send $iif($left($1,1) == @,.msg #,.notice $2)
hadd %dedi ornot $iif($left($1,1) == @,to1 $2,to you!))
sockopen %dedi www.youtube.com 80
}
else { .notice $nick $logo(Error) Please specify a song/nick $chr(124) !dedication <nick> <song> <artist> }
}
Is it ever so necessary for every comment to be a criticism of the trigger?yes. however....
if (!$2) || (!$3) || ($2 !ison $chan) { .notice $nick $logo(Error) Please specify a song/nick $chr(124) !dedication <nick> <song> <artist> | halt }
you could remove the !$2 part of the /if statement seeing as if $2 isnt on $chan it wouldnt matter if there was a $2?
if ($left($1,1) == !) .notice $nick $logo(Dedication) $c2(Dedication sent to $2 $+ !)
may be deliberate but i dont see anything for if $left($1,1) == @
hadd -m $sockname end $regml(1)
seems redundant if ur just gonna free the table in a few lines comepared to just using $regml(1) instead of $hget($sockname,end)
To me: > on $:text:/^!@/Si:#: {
if ($regml(1) == dedi) || ($regml(1) == dedicate) { ...
}
Or
Code:
on $:text:/^!@/Si:#: {
if ($istok(dedi dedicate,$regml(1),32)) {
does not seem simplified, if anything you are complicating things. I was indeed aiming for it to just match "dedi" or "dedicate".
Is it ever so necessary for every comment to be a criticism of the trigger?
As much as I appreciate it as I do have alot still to learn about regex maybe give me a little feedback on the rest of it too? :D
You regex trigger can be simplified to:
on $*:text:/^([!@]dedi)/Si:#: {
since that'll catch dedi or dedicate. I don't see the need for grouping...
Then again, if you only want to match for (!@)dedi and (!@)dedicate exactly, you can do:
on $*:text:/^[!@](\w+)/Si:#: {
if ($regml(1) == dedi) || ($regml(1) == dedicate) { ...
}
Or
on $*:text:/^[!@](\w+)/Si:#: {
if ($istok(dedi dedicate,$regml(1),32)) { ...