All pastes #106027 Raw Edit

Anonymous

public text v1 · immutable
#106027 ·published 2006-07-30 02:03 UTC
rendered paste body
; ############################################################################# 
; ## Simple Multi-Socketed Price Guide Script                                ## 
; ## Written by CrazyMan1975                                                 ## 
; ## trulyinsane@crazyman.org                                                ## 
; ## irc.swiftirc.net - #RsPrices                                            ## 
; ##                        - NOTE -                                         ## 
; ## This script is actually NOTHING like the one that my main bot           ## 
; ## TrulyInsane1 uses. I put this together because I was asked enough       ## 
; ## times for a price guide script that worked well.                        ## 
; ## This one does the job, but if you want it fancy like Truly's then       ## 
; ## You're going to have to put in the hours. -.-                           ## 
; ############################################################################# 

; ############################################################################# 
; ## Alias/Identifier $preplace(<text>)                                      ## 
; ## This can be used to replace anything that the web site does not already ## 
; ## catch. Simply create a file called replace.txt in the main mirc         ## 
; ## directory, then add what you want to be replaced in the following       ## 
; ## Format: <text_to_replace>,<replacement_text>                            ## 
; ## Examples: drag pl8legs,Dragon Platelegs                                 ## 
; ##           potion (4),Potion                                             ## 
; ############################################################################# 
ALIAS -l PReplace { 
  VAR %pr.cnt = 1 | VAR %pr.total = $Lines(Replace.txt) | VAR %pr.text = $1- 
  WHILE (%pr.cnt <= %pr.total) { 
    VAR %pr.text = $Replace(%pr.text, [ [ $Read(Replace.txt,%pr.cnt) ] ] ) 
    INC %pr.cnt 
  } 
  RETURN %pr.text 
} 

; ############################################################################# 
; ## Remote Trigger, Allows !, @ or . to be used as the command character &  ## 
; ## price* to be used as the command.                                       ## 
; ############################################################################# 
ON $*:TEXT:/^[!@.]price/Si:#: { 
  IF (!$2) { .notice $nick *** [4Price Guide]: Please give me something to search for! | HALT } 
  ; # This sets up the Multiple Sockets, increasing the Variable %i until that socket is not in use. 
  VAR %i 1 
  WHILE ($Sock(price. $+ %i)) { INC %i } 
  ; # Store the Nickname, Where to send and how, and the item to find using our %i identifier. 
  SET %price.user. [ $+ [ %i ] ] $Nick 
  SET %price.target. [ $+ [ %i ] ] $IIF($Left($1,1) == !,.Notice $Nick ***,.Msg $Chan) [4Price Guide]: 
  SET %price.search. [ $+ [ %i ] ] $PReplace($2-) 
  ; # Open the socket - http://thexx.6te.net 
  SockOpen $+(price.,%i) thexx.6te.net 80 
} 

; ############################################################################# 
; ## SockOpen - Once our socket has been opened, This will run.              ## 
; ## This sets up our request for the web page so we can retrieve the data.  ## 
; ## Note the price.* in the on SockOpen, that is Necessary to pick up the   ## 
; ## sequential socket names.                                                ## 
; ############################################################################# 
ON *:SOCKOPEN:price.*:{ 
  SockWrite -nt $SockName GET /xxprice.php?item= [ $+ [ $Replace(%price.search. [ $+ [ $Right($SockName,-6) ] ] ,$Chr(32),$Chr(37) $+ 20) ] ] HTTP/1.1 
  SockWrite -nt $SockName Host: thexx.6te.net 
  SockWrite -nt $SockName $CRLF 
} 


; ############################################################################# 
; ## SockRead - Now we're going to find the data and return it to the user.  ## 
; ############################################################################# 
ON *:SOCKREAD:price.*:{ 
  ; # Store the socket number in %i (Local Variable) 
  VAR %i = $Right($SockName,-6) 
  ; # Read a Line from the socket. 
  SockRead -f %priceread 
  ; # If something went wrong, report it to the user and clear the variables. 
  IF ($SockErr) { 
    %price.target. [ $+ [ %i ] ] Socket error: $SockErr $+ , while looking up %price.search. [ $+ [ %i ] ] 
    UNSET %price.*. [ $+ [ %i ] ] 
  } 
  ; # If nothing happened during the initial read process, we can begin. 
  ELSE { 
    :NextRead 
    SockRead -f %priceread 
    ; # $sockbr is set if data was actually read in to the %priceread variable. 
    IF ($SockBr) { 
      ; # For this site, the price info is preceeded with "TheXX.Co.Nr" so we'll look for that. 
      IF ((TheXX.Co.Nr IsIn %priceread) && ($NumTok(%priceread,32) > 1)) { 
        ; # Output the match we found to the user. 
        %price.target. [ $+ [ %i ] ] 12 $+ $Remove(%priceread,TheXX.Co.Nr $+ $Chr(32)) 
        UNSET %price.*. [ $+ [ %i ] ] 
      } 
      ; # if the Variable contains only "TheXX.Co.Nr" then we did not find a match, report it. 
      ELSEIF (%priceread == TheXX.Co.Nr) { %price.target. [ $+ [ %i ] ] Unable to find a match for $qt(%price.search. [ $+ [ %i ] ] ) } 
      ; # Goto's as a general rule are BAD, in an on SockRead event is the ONLY time I will use them. 
      GOTO NextRead 
    } 
    ELSE SockClose $SockName 
  } 
} 

; ############################################################################# 
; ## I hope this helps you out, and possibly you can learn a little about    ## 
; ## Sockets from it. Enjoy!                                                 ## 
; ## Not too shabby for 100 lines including comments ;)                      ## 
; #############################################################################