################################################################################################
### Mar 06 1999 ################################################################################
################################################################################################
####                                                                                        ####
####  ICQ-drop Ver 1.5  simple on Undernet (simple@utw.com)                                 ####
####       Cleaned up the sloppy code and changed up some of the fields, also added a       ####
####       public bind just for fun, because it was easy to do. Variable names are now      ****
####       also much clearer and easier to understand. Kudos to ^Dark^ for this great idea  ####
####                                                                                        ####
####  ICQ-drop Ver 1.0  ^DaRk^ on EFnet (Darkbringer@Rocketmail.com) (Edited by Xanith)     ####
####       For Eggdrop 1.3.*                                                                ####
####       as always: the code IS sloppy since im teaching myself TCL as i go...            ####
####       learned another 30 or so new commands while making this script heh               ####
####                                                                                        ####
####  This script is simple in theroy (took me forever to make it actually work outside of  ####
####       Theroy though) the bot is able to create a raw socket to ICQ's web server and    ####
####       post to their CGI exactly (almost) as one would to submit a WWPager message.     ####
####       people are able to have the bot send you ICQ messages when youre not on IRC.     ####
####       the possibilities with this script are virtualy limitless depending on what you  ####
####       wish to be notified about. the only requirements are that you run a slightly     ####
####       edited userinfo1.0.tcl <included> (to add the ICQ field in XTRA) and that you    ####
####       and/or any other user on the bot defines their ICQ UIN# with the .icq <UIN#>     ####
####       command.                                                                         ####
####                                                                                        ####
################################################################################################

################################################################################################
####                                                                                        ####
####  Syntax:                                                                               #### 
####     MSG: /msg <bot> icqsend <recipient> <message>                                      ####
####     PUB: !icqsend <recipient> <message>                                                ####
####     DCC: .icqsend <recipient> <message>                                                ####
####                                                                                        ####
################################################################################################

################################################################################################
####                                                                                        ####
####  Extra thanks to Gecko and Noob from #TCL who helped me ALOT with the sockets and      ####
####       regsub commands, and never once losing patients with my constant questions (I    ####
####       really DO know how to add in TCL, i just temporarily forgot)                     ####
####                                                                                        ####
####  Greetz to my bros ReJeCt-, DarKni9hT, _Tenchi_, and Frmbob                            ####
####                                                                                        ####
####  Still much hate to reddog`` who still holds my chan :/                                ####
####                                                                                        ####
################################################################################################
################################################################################################
#
# - If you use/edit/rip/sell my code, at LEAST gimme credit for it -
#
bind dcc - icqsend sendicqdcc
bind msg - !icqsend sendicqmsg
bind pub - !icqsend sendicqpub
#noob and gecko
#edited by simple
proc sendicqdcc {hand idx rest} {
 global botnick
 set whom [lindex $rest 0]
 if {[getuser $whom XTRA ICQ] == "" } {
  putdcc $idx "no ICQ # for $whom registered.. (make sure you have the userfile modified to hold an ICQ field"
  return 0
 }
 set icq [getuser $whom XTRA ICQ]
 set from "$botnick, the IRC bot"
 set head "From+$hand@$botnick"
 set origmsg [lrange $rest 1 end]
 regsub -all " " $origmsg + msg
 set body $head
 append body $msg
 set var $body
 append var $hand $from $hand
 set ln [expr [string length $var] + 41]
 go_connect $from $body $icq $ln $msg $head $hand
 return 1
}

proc sendicqpub {nick uhost hand chan rest} {
 sendicqmsg $nick $uhost $hand $rest
 return 0
}

proc sendicqmsg {nick uhost hand rest} {
 global botnick
 set whom [lindex $rest 0]
 if {[validuser $whom] == 0 } {
  putserv "NOTICE $nick :no user by that name, sorry"
 }
 if {[getuser $whom XTRA ICQ] == "" } {
  putserv "NOTICE $nick :no ICQ # for $whom registered.. "
  return 0
 }
 set icq [getuser $whom XTRA ICQ ] 
 set from "$botnick, the IRC bot"
 set head "From+$hand@$botnick"
 set origmsg [lrange $rest 1 end]
 regsub -all " " $origmsg + msg
 set body $head
 append body $msg
 set var $body
 append var $hand $from $botnick
 set ln [expr [string length $var] + 41]
 go_connect $from $body $icq $ln $msg $head $hand
 putserv "NOTICE $nick :ICQ message sent to $whom"
 return 0
}


### sock proc: Gecko's idea (i had thought to use putdcc)
### but this works much better than putdcc
proc go_connect {from body icq ln msg head hand} {
 if [catch {socket "wwp.icq.com" 80} sockresult] {
  putlog "Could not connectfor ICQ: $sockresult"
  return 0
 }
 putlog "Socket $sockresult was opened for ICQ"
 fconfigure $sockresult -translation auto -buffering line -blocking 0
 puts $sockresult "POST /scripts/WWPMsg.dll HTTP/1.1"
 puts $sockresult "Accept: application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"
 puts $sockresult "Referer: http://nothing.com"
 puts $sockresult "Accept-Language: en-u"
 puts $sockresult "s"
 puts $sockresult "Content-Type: application/x-www-form-urlencoded"
 puts $sockresult "Accept-Encoding: gzip, deflate"
 puts $sockresult "User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)"
 puts $sockresult "Host: x"
 puts $sockresult "Content-Length: $ln"
 puts $sockresult "Connection: Keep-Alive"
 puts $sockresult ""
 puts $sockresult "subject=$head&to=$icq&from=$hand&fromemail=$from&body=$msg&x=90&y=50"
 close $sockresult
 return 0
}
putlog "ICQ-Drop v1.5 - by simple (simple@utw.com) Greetings from Undernet #TCL!"
