Random Links Snippet

By Bielie on Mar 30, 2011

Screenshots

This snippet saves any links that starts with http://. It will also shows a random link when the !rlink command is used.

Update:
Wont save links more then once. (Doesnt matter wich nickname has applied it!)
Added !lastlink
Added Floodcontrol
Added an $iif identifier for the usage of @ public and !. private commands.

Example:

Nick: http://google.com
Bot: (echo) Links saved by Nick | Written http://google.com ( $+ By Nick $+ ) in links.txt

Nick: !rlink
Bot: Here is your random link: http://hawkee.com (By Bielie993)

Nick: !lastlink
Bot: This is the last link that has been saved: http://google.com (By Nick)

Check the printscreen for an example!!!!!!

on *:TEXT:*:#:{
  if ($isurl($1-) == $true) { 
    if ($linkcheck($wildtok($1-,*http://*.*,1,32)) == $true) { /echo Skipping the link since its already on the 4links.txt 1file! | return }
    else {
      /echo Link: ( $+ $wildtok($1-,*http://*.*,1,32) $+ ) saved by4 $nick | write links.txt $wildtok($1-,*http://*.*,1,32) ( $+ By4 $nick $+ 1) | set %lastlink $wildtok($1-,*http://*.*,1,32) ( $+ By4 $nick $+ 1) 
    }
  }
  if ($1 == !rlink) || ($1 == .rlink) || ($1 == @rlink) { $iif($left($1,1) == @,/msg #,/notice $nick) Here is your random link: $linkss | .ignore -u2 $nick }
  if ($1 == !lastlink) || ($1 == .lastlink) || ($1 == @lastlink) { $iif($left($1,1) == @,/msg #,/notice $nick) This is the last link that has been saved: %lastlink | .ignore -u2 $nick }
}

alias linkss { 
  if (!$read(links.txt)) { return Nothing Found }
  else { return $read(links.txt) }
}

alias linkcheck {
  if ($read(links.txt,nw,$+(*,$1-,*)) != $null) { return $true }
  else { return $false }
}

alias isurl return $iif($regex($1-,/\b(?:(?:htt|ft)ps?://(?:www|ftp\.)?|www|ftp\.).*(?:\.[a-z]{2,4})(?::\d+)?(?:/\w+(?:/\w*/*)*|(?:\.[a-z]{2,4})|\?\S*)*\b/gi),$iif($prop,$regml($v1),$true))

Comments

Sign in to comment.
Jethro   -  Oct 01, 2011

I see that you have used regex in your code, why not take advantage of it more?

This:> if ($1 == !rlink) || ($1 == .rlink) || ($1 == @rlink) { $iif($left($1,1) == @,/msg #,/notice $nick) Here is your random link: $linkss | .ignore -u2 $nick }
if ($1 == !lastlink) || ($1 == .lastlink) || ($1 == @lastlink) { $iif($left($1,1) == @,/msg #,/notice $nick) This is last link that has been saved: %lastlink | .ignore -u2 $nick }can be done as:

if ($regex($1,/^([!@.])(r|last)link$/iS)) { 
$iif($regml(1) == @,msg #,notice $nick) $iif($regml(2) == r,$&
Here is your random link: $linkss,$&
This is last link that has been saved: %lastlink)
.ignore -u2 $nick
}
 Respond  
Bielie   -  Oct 01, 2011

Updated the snippet to work 100%. The first version was only usable if you made a new snippet page for the other on text events.

This is all fixed now.

 Respond  
jaydawg   -  Jun 12, 2011

not working for me its saving the quotes but !rlink and !lastlink not working.

 Respond  
IllogicTC   -  Apr 09, 2011

Isn't this pretty much a scripted version of the built-in URL catcher?

 Respond  
Jethro   -  Mar 31, 2011

The regex pattern you've gotten now is redundant.

 Respond  
Bielie   -  Mar 31, 2011

This should work without problems now

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.