Top

Send a dedication


mIRC Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  4.0 (of 1 scores)
Date Added  Oct 16, 2009
Last Updated  Oct 16, 2009
Tags  dedicate  dedication  songs  youtube 

Introduction

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 <targetnick> <song/artist> <song/artist>

Code:

[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:
Code:
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.

Grab the Code

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
    }
  }
}

Comments

  (15)  RSS
Testor
Comments: 83
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 1:03 pm
Should add the . trigger, as a lot of people use it for speed over ! trigger.
sunslayer
Comments: 267
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 3:08 pm
Code:
if (*id="video-main-content-* iswm %url) {
      noop $regex(%url,/id="video-main-content-(.+?)"/i)
why not just use the regex in the if statement?
Riffpilgrim
Comments: 7
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 3:21 pm
Thats a good point, I didn't think of that at the time - I'm not the most logical of thinkers really.
Changed, thanks for the tip sunslayer :)
Jethro_
Comments: 437
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 4:22 pm
You regex trigger can be simplified to:
Code:
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:
Code:
on $*:text:/^[!@](\w+)/Si:#: {
  if ($regml(1) == dedi) || ($regml(1) == dedicate) { ...
}
Or
Code:
on $*:text:/^[!@](\w+)/Si:#: {
  if ($istok(dedi dedicate,$regml(1),32)) { ...
gooshie
Comments: 66
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 7:08 pm
Maybe Riffpilgrim meant:
/^[!@]dedicat(e|ion)/Si
Riffpilgrim
Comments: 7
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 7:27 pm
To me:
Quote:
on $*:text:/^[!@](\w+)/Si:#: {
if ($regml(1) == dedi) || ($regml(1) == dedicate) { ...
}
Or
Code:
on $*:text:/^[!@](\w+)/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
sunslayer
Comments: 267
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 7:41 pm
Quote:
Is it ever so necessary for every comment to be a criticism of the trigger?
yes. however....

Code:
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?

Code:
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) == @

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)
gooshie
Comments: 66
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 8:22 pm
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.

You may want to add flood protection.

Code:
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> }
}
Riffpilgrim
Comments: 7
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 8:29 pm
Quote:

Code:
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?

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 :p
Quote:

Code:
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.

Quote:

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.
gooshie
Comments: 66
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 8:51 pm
Riffpilgrim
Scroll up to my previous post. All that
!$2 !$3 !ison negative logic can be rearranged
and simplified to give same results as your
original with less keystrokes and easier to read.
FordLawnmower
Comments: 412
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 9:28 pm
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
Code:
var %sockname $+(durl.,$right($ticks,5)),%whom $2

And then just use %sockname instead of $+(durl.,%dedi)

Good working code though Riffpilgrim :)
Jethro_
Comments: 437
 
mIRC Snippet:  Send a dedication
Posted on Oct 16, 2009 11:56 pm
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.
Riffpilgrim
Comments: 7
 
mIRC Snippet:  Send a dedication
Posted on Oct 17, 2009 6:24 am
Quote:
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
gooshie
Comments: 66
 
mIRC Snippet:  Send a dedication
Posted on Oct 17, 2009 8:14 am
btw.. i had already mentioned the
hash table name in my earlier post.
Riffpilgrim
Comments: 7
 
mIRC Snippet:  Send a dedication
Posted on Oct 17, 2009 8:43 am
Yes I know sorry but your antiflood link distracted me enough to forget you had mentioned it XD

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom