Hawkee Snippet Search (with dialog)

By Zmodem on Aug 25, 2008

Update: Nov 02, 2013 - THIS SNIPPET IS NO LONGER SUPPORTED! I am leaving it here for archival purposes only. Thank you!

This snippet searches for other snippets from Hawkee. You can search through all of them, or specify a category.

Original source created by mountaindew here: http://www.hawkee.com/snippet/4164/

I merely added a dialog to it for him. At the request of the site-moderator, I have posted the entire code here.

Update! (26 AUGUST 2008): Added C++ to the available search properties.

Dialog Search Feature
Syntax: /snippet_search

Image

;~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
;           Hawkee Snippet Search                *
;            Made by MountainDew                 ~
; IRC.DeltaAnime.Net » #Lindrian #mIRC-Scripting *
;  US.UnderNet.Org » #Hawkee.com #mircscripting  ~
;*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*

on $*:TEXT:/^[.!@](snip(pets)?|hawk(ee)?)/Si:#:{
  set %s.chan $iif($chan == #msl,$nick,$v1)
  snippets $2-
}
alias snippets {
  if ($sock(snippets)) {
    %smsg Wait until the current search has been finished.
    halt
  }
  set %smsg $iif(%s.chan,$iif(%s.chan == #msl,notice,msg) %s.chan,echo -a)
  if (!$1) {
    %smsg Syntax: $iif(%s.chan,!,/) $+ snippets [-type] <search criteria>
    halt
  }
  if ($left($1,1) == -) {
    if ($istok(-asp|-cfm|-css|-java|-js|-jsp|-mirc|-mysql|-net|-perl|-php|-python|-ruby|-tcl|-myspace|-opensocial|-cpp|-hi5,$1,124)) {
      if (!$2) {
        %smsg Please specify search criteria.
        halt
      }
      set %s.prop $1
    }
    else {
      %smsg The available switches are: -asp -cfm -css -java -js -jsp -mirc -myspace -mysql -net -opensocial -perl -php -python -ruby -tcl -cpp -hi5
      halt
    }
  }
  set %s.search $iif(%s.prop,$2-,$1-)
  if ($dialog(snippet_search)) {
    snip_add Searching for $qt(%s.search) in $iif(%s.prop,$replace(%s.prop,-asp,ASP,-cfm,CFM,-css,CSS,-java,Java,-js,JavaScript,-jsp,JSP,-mirc,mIRC,-mysql,MYSQL,-net,.NET,-perl,Perl,-php,PHP,-python,Python,-ruby,Ruby,-tcl,TCL,-myspace,MySpace,-opensocial,OpenSocial,-cpp,C++,-hi5,Hi5)) Snippets...
    goto socket
  }
  $iif(%s.chan,describe %s.chan searches,echo -a Searching) for $qt(%s.search) in $iif(%s.prop,$replace(%s.prop,-asp,ASP,-cfm,CFM,-css,CSS,-java,Java,-js,JavaScript,-jsp,JSP,-mirc,mIRC,-mysql,MYSQL,-net,.NET,-perl,Perl,-php,PHP,-python,Python,-ruby,Ruby,-tcl,TCL,-myspace,MySpace,-opensocial,OpenSocial,-cpp,C++,-hi5,Hi5)) Snippets...
  :socket
  sockopen snippets www.hawkee.com 80
}
on *:sockopen:snippets:{
  set %s.url $iif(!%s.prop,/snippets/?user_id=&snippet_type=&search_query= $+ $replace(%s.search,$chr(32),+) $+ &search_type=snippet_title,/snippets/search/ $+ $replace(%s.search,$chr(32),+) $+ /cat/ $+ $remove(%s.prop,-) $+ /)
  unset %s.prop
  sockwrite -nt $sockname GET %s.url HTTP/1.1
  sockwrite -nt $sockname Host: www.hawkee.com
  sockwrite -nt $sockname $crlf
}
on *:sockread:snippets:{
  var %x, %m
  sockread %x
  if (We couldn't find any snippets to match your search. isin %x || We have not received any snippets for this section yet. isin %x) {
    %m = Sorry $+ $chr(44) no matches were found for $qt(%s.search) $+ .
    if ($dialog(snippet_search)) {
      if (Searching for * iswm $did(snippet_search,23,1)) { did -r snippet_search 23 }
      did -e snippet_search 4
      snip_add %m
      goto unset
    }
    %smsg %m
    :unset
    unset %s.*
    sockclose $sockname
  }
  if ($regex(%x,/<b>\+ (\d+)<\/b> likes<br>/i)) set %s.likes $regml(1)
  if ($regex(%x,/Score: <b>(\d+\.\d)<\/b>/i)) set %s.rating $regml(1)
  if ($regex(%x,/<a href='(\/snippet\/\d+\/)' class='large'>(.+)<\/a><br>/i)) {
    set %s.title $regml(2)
    set %s.url2 http://www.hawkee.com $+ $regml(1)
  }
  if ($regex(%x,/<a href="\/snippets\/cat\/.+\/">(.+)<\/a>/i)) set %s.lang $regml(1)
  if ($regex(%x,/Posted by <a href='.+'>(.+)<\/a> on <.+><b>(.+)<\/b><\/span>/i)) {
    set %s.by $regml(1)
    set %s.date $regml(2)
    inc %N
    if ($dialog(snippet_search)) {
      var %a = snip_add
      if (Searching for * iswm $did(snippet_search,23,1)) { did -r snippet_search 23 }
      did -e snippet_search 24
      %a Title: %s.title
      %a Author: $regml(1)
      %a Submitted: $regml(2)
      %a Language: %s.lang
      %a Score: %s.rating
      %a Likes: %s.likes
      %a URL: %s.url2
      %a $chr(32)
      goto next
    }
    %smsg 9• 4Title: %s.title 4Author: $regml(1) 4Sumbitted: $regml(2) 4Language: %s.lang 4Score: %s.rating 4Likes: %s.likes 4URL: %s.url2

    :next
    if ($dialog(snippet_search)) { did -e snippet_search 4 | did -b snippet_search 24 }
    if (%N == 3) {
      unset %s.* %N %smsg
      sockclose $sockname
    }
  }
  if (<div id="sidebar"> isin %x) sockclose $sockname
}
on *:sockclose:snippets:unset %s.* %N %smsg
alias hawk snippets $1-
alias snip snippets $1-
alias hawkee snippets $1-

alias snippet_search dialog $iif($dialog,-a,-m) snippet_search snippet_search

dialog -l snippet_search {
  title "Hawkee Snippet Search - Author: Mountain Dew"
  size -1 -1 179 201
  option dbu
  box "Search Options", 1, 4 2 171 87
  text "S&earch", 2, 9 14 21 9
  edit "", 3, 32 12 105 12
  button "&Search", 4, 142 12 27 12, default flat
  radio "Everything", 5, 9 26 37 9, flat
  radio "PHP", 6, 9 38 19 9, flat
  radio "Python", 7, 9 49 27 9, flat
  radio "Ruby", 8, 9 61 22 9, flat
  radio "Java", 9, 9 73 22 9, flat
  radio "mIRC", 10, 49 26 22 9, flat
  radio "ASP", 11, 49 38 19 9, flat
  radio "CFM", 12, 49 49 20 9, flat
  radio "CSS", 13, 49 61 19 9, flat
  radio "TCL", 14, 49 73 19 9, flat
  radio "JS", 15, 89 26 16 9, flat
  radio "JSP", 16, 89 38 19 9, flat
  radio "OpenSocial", 17, 89 49 37 9, flat
  radio "Perl", 18, 89 61 19 9, flat
  radio "MySQL", 19, 89 73 26 9, flat
  radio "NET", 20, 133 26 19 9, flat
  radio "MySpace", 21, 133 38 31 9, flat
  radio "C++", 22, 133 49 37 9, flat
  radio "Hi5", 27, 133 61 37 9, flat
  box "Search Results", 26, 4 93 171 84
  list 23, 8 101 163 72, size hsbar vsbar
  button "&Open Page", 24, 4 180 33 15
  button "&Close", 25, 142 180 33 15, cancel
}
ON *:DIALOG:snippet_search:*:*: {
  var %d = $dname, %e = $devent, %i = $did, %w
  if (%e == init) { new_search %d }
  if (%e == edit) { did $iif(($did(3) != $null) && ($remove($did(3),$chr(32)) != $null),-e,-b) %d 4 }
  if (%e == sclick) {
    if (%i == 4) {
      did -b %d 4
      did -r %d 23
      %w = 5
      while (%w <= 22) {
        if ($did(%w).state) { did -b %d 24 | hawkee $iif($did(%w) != Everything,- $+ $replace($did(%w),+,p)) $did(3) | return }
        inc %w
      }
      %w = 27
      while (%w <= 27) {
        if ($did(%w).state) { did -b %d 24 | hawkee $iif($did(%w) != Everything,- $+ $replace($did(%w),+,p)) $did(3) | return }
        inc %w
      }
    }
    if (%i == 23) { did - $+ $iif($did(23,$did(23).sel),e,b) %d 24 }
    if (%i == 24) { snip_run }
  }
  if ((%e == dclick) && (%i == 23)) { snip_run }
}
alias -l snip_add var %d = snippet_search | $iif($dialog(%d),did -a %d 23 $1-)
alias -l snip_run {
  var %d = snippet_search, %i = $did(%d,23).sel, %h = $did(%d,23,%i), %g, %r
  if (Title: * iswm %h) %g = 6
  if (Author: * iswm %h) %g = 5
  if (Submitted: * iswm %h) %g = 4
  if (Language: * iswm %h) %g = 3
  if (Score: * iswm %h) %g = 2
  if (Likes: * iswm %h) %g = 1
  if (URL: * iswm %i) %g = 0
  %r = $gettok($did(%d,23,$calc(%i + %g)),2-,58)
  if (%r) { run %r }
}
alias -l new_search {
  var %d = $1
  did -b %d 4,24
  did -c %d 5
}

Comments

Sign in to comment.
Cheiron   -  Apr 09, 2009

no worries Zmodem .. regards mountaindews edit on his last comment for the pm issue.. that needs work still as it noticed the nick the results instead of in pm. the pm does open with the "is searching for" message, but the results are given in notice. also the bot gets hit with the display notice in channel scroll and in the status windows. so be careful if you adopt that option :)

 Respond  
Zmodem   -  Apr 09, 2009

I am, most-likely, going to update this with mountaindew's updated version, too. Thanks!

 Respond  
Cheiron   -  Mar 28, 2009

tried to use this on my mirc 6.35 bot.. the bot had nothing else running on it to interfere but i couldnt get the snippet to work. came up with the initial searching.. but no results or anything got listed even after leaving it for 2-3mins.

 Respond  
Zmodem   -  Oct 02, 2008

The search for this has now been updated for hi5 in accordance with mountaindew's snippet update.

 Respond  
Zmodem   -  Aug 26, 2008

Well, if mountaindew wants the dialog, it's all his. I originally offered this up as a comment code-block on his snippet page, but Hawkee told me to just go ahead and make my own page, referencing the old one. This is completely mountaindew's.

 Respond  
EL   -  Aug 26, 2008

No to bad but still would have been better if it was original.`-.-´

 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.