Professional Documents
Culture Documents
/nick ZDC-BOT
/msg Q@CServe.quakenet.org AUTH
//mode $me +x
/msg Q invite #Highlyinsane
/join #Highlyinsane
set %ch #Highlyinsane
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;adding admin;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;
on *:text:.addadmin*:#: {
/write ranks.txt $auth($2) admin
Notice $nick $2 was promoted to admin
}
on *:Text:.test:#: {
if ($read(ranks.txt, s, $auth($nick)) == admin ) {
msg # zodiac pro fffsssss
}
else {
msg $nick You dont have enought power to do this!
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;youtube;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
on *:TEXT:*youtube.com/*:*: {
; Get the first youtube.com link from the text the users say. We use the $mid
just so we don;t have to worry about the http://www.you... crap in our $pos
var %link = $mid($wildtok($1-, *youtube.com/*,1,32),10)
; Get the location by returning everything after and including the /
var %location = $mid(%link,$pos(%link,/))
; Call alias youtubelookup
youtubelookup %location
}
alias youtubelookup {
; We make sure the location was given to us, otherwise we echo an error and st
op doing things
if ($0 != 1) { echo -a * /youtubelookup: invalid parameters | halt }
; We generate our random name and make absolutely certain this name isn't take
n. Note since our on text can work for both channels and queries, we use an iif
var %name = youtubelookup $+ $ticks
if ($sock(%name)) { msg $iif(#,#,$nick) Youtube lookup error, name was in use
( $+ %name $+ ) | halt }
;
sockopen %name www.youtube.com 80
; We will need a way to tell which channel or nick to respond to once we get o
ur reply from youtube's servers. We use sockmark for this.
;Sockmark is a simple way to store data related to a socket in text form. Plea
se click the link for more information
sockmark %name $iif(#,#,$nick) $1
}
on *:SOCKOPEN:youtubelookup*: {
; We set an variable as an alias to write the data to the socket so we don't h
ave to type it every time
var %n = sockwrite -n $sockname
; We GET the location we parsed out in our on text event. If you recall, we se
t this as the second word in our sockmark in the alias above.
%n GET $gettok($sock($sockname).mark,2,32) HTTP/1.1
; Some IPs have many web sites on them. We need to tell the web server that w
ww.youtube.com is the host we are using.
%n Host: www.youtube.com
; Some web sites only allow certain web browsers, so we lie a bit here and tel
l youtube we are firefox 5.0.
%n User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/
20100401 Firefox/4.0 (.NET CLR 3.5.30729)
; We make sure youtube closes its connection with us as soon as its sent every
thing we asked for
%n Connection: close
; This empty line is the HTTP protocol way to tell it that we are done sending
our data.
%n
}
on *:SOCKREAD:youtubelookup*: {
; If there was an error, $sockerr will contain the error number. We will messa
ge the user and tell them about the error, then stop.
if ($sockerr) { msg $gettok($sock($sockname).mark,1,32) There was an error whi
le verifying youtube link: $sock($sockname).wsmsg | sockclose $sockname | halt }
;
:read
; We will read the data we received
sockread -f &data
; We will write the data to the end of the file with the same name as the sock
et. The -1 means the end of the file.
if ($sockbr > 0) { bwrite $sockname -1 &data }
; $sockbr (sock bytes read) contains the number of bytes (read: ascii letters)
that we received this time. We want to keep reading until we can't read anymor
e!
; Note: Once $sockbr is 0, this doesn't mean the server doesn't have more to s
end! It just means we haven't gotten any more.
while ($sockbr > 0) { goto read }
;
}
on *:SOCKCLOSE:youtubelookup*: {
; The place to send the data
var %target = $gettok($sock($sockname).mark,1,32)
; Read the file into the binary file &data
bread $sockname 1 $file($sockname).size &data
; Gets the position of <title> in the document
var %start = $bfind(&data,1,<title>).text
; Gets the position of </title> in the document
var %end = $bfind(&data,%start,</title>).text
; If we could not find these tags, the file likely is not valid.
if (!%start || !%end) { msg %target Invalid youtube link. | halt }
; get the data in between %start and %end, excluding the 7 letters for <title>
echo -atg Test: $bvar(&data,$calc(%start +7),$calc(%end - %start - 7))
; Remove new lines
breplace &data 10 32
breplace &data 13 32
var %title = $bvar(&data, $calc(%start + 7), $calc(%end - %start - 7)).text
; Tell target
msg %target 3Youtube Link: 7 %title
; Delete the file
.remove $sockname
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;commands;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;