mIRC Home    About    Download    Register    News    Help

Print Thread
#251791 03/03/15 11:10 PM
Joined: Mar 2014
Posts: 42
S
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
Hi, i was doodling around with an alias that creates a click to tweet link, and although it does work, it takes up to 15 seconds for me to receive a response from the server. So i was wondering if anyone notices anything wrong/missing from my script that causes that

Code:
alias newTweet {
  set %tweetmsg tweet= $+ $urlencode($1-) $+ &submit=Generate+New+Link
  sockclose newTweet
  sockopen -e newTweet clicktotweet.com 443
}

on *:sockopen:newTweet:{
  if ($sockerr) { return }
  sockwrite -n $sockname POST /link/basicSubmit? $+ %tweetmsg HTTP/1.1
  sockwrite -n $sockname Host: clicktotweet.com
  sockwrite -n $sockname Content-Length: $len(%tweetmsg)
  sockwrite -n $sockname Connection: close
  sockwrite -n $sockname $crlf
}

on *:sockread:newTweet:{
  var %tweetread
  sockread -f %tweetread
  write tweetread.txt %tweetread
}

on *:sockclose:newTweet:{
  var %tweetID = $remove($read(tweetread.txt,9),location: /basic/)
  echo -s Acquired response from server: www.clicktotweet.com/ $+ %tweetID
  unset %tweetmsg
  remove tweetread.txt
}

alias UrlEncode return $regsubex($1-,/([^\d\w])/g,$+(%,$base($asc(\t),10,16)))


If you see anything off (apart from my easymode sockread event) please let me know!

Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Well try use COM method it is a kind fast than sockets, try use this code:

Usage: //echo is $clicktotweet(test message)

Code:
alias -l urlencode { return $regsubex($$1-,/([^\d\w])/g,$+(%,$base($asc(\t),10,16))) }
alias clicktotweet {
  if (!$1) { return }
  var %url https://clicktotweet.com/link/basicSubmit?tweet= $+ $urlencode($1-) $+ &submit=Generate+New+Link
  var %com = click_ $+ $ticks $+ $ctime
  .comopen %com msxml2.xmlhttp 
  noop $com(%com, Open,1, bstr,GET,bstr,%url,bool,false) $com(%com,Send,1) $com(%com,ResponseText,2)
  var %a = $remove($com(%com).result,$chr(10),$chr(9),$chr(13))
  var %a = $gettok($wildtok(%a,*http://ctt.ec/*,$wildtok(%a,*http://ctt.ec/*,0,32),32),2,34)
  if ($comerr) { return 0 }
  if ($com(%com)) { .comclose %com }
  return %a
}


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Mar 2014
Posts: 42
S
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
Holy cow that is so much faster o_O thank you so much!
I guess i should learn more about this com function shocked

okay this com thing is waaaay out of my league. I cant even seem to decode what that code is doing lol.

I wonder why the socket was slow though, because im fairly confident it wasnt the actual socket that was slow, but more likely something i forgot/messed up.

Last edited by Sjoepele; 04/03/15 12:32 AM.
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
You are using /write inside the on sockread event, each time you call /write it has to open the file, write the content and then closr the file.
Whereas you could open the file once, write the data, and close it once inside the on sockclose event, this is most likely the issue here.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Also, the on socckread event is reading (in a wrong way but let's assume it's correct) line by line, which is much slower than reading everything at once, you don't need to read line by line:

Code:
 on *:sockopen:newTweet:{
 if ($sockerr) { return }
  sockwrite -n $sockname POST /link/basicSubmit? $+ %tweetmsg HTTP/1.1
  sockwrite -n $sockname Host: clicktotweet.com
  sockwrite -n $sockname Content-Length: $len(%tweetmsg)
  sockwrite -n $sockname Connection: close
  ;-n already sends a $crlf if the data you send doesn't end with a $crlf
  sockwrite -n $sockname
  .fopen -o newtweet tweetread.txt
}

on *:sockread:newTweet:{
  if ($sockerr) {
    .fclose newtweet
    return
  }
  sockread $sock(newtweet).rq &a
  .fwrite -b newtweet &a
}

on *:sockclose:newTweet:{
  .fclose newtweet
  var %tweetID = $remove($read(tweetread.txt,9),location: /basic/)
  echo -s Acquired response from server: www.clicktotweet.com/ $+ %tweetID
  unset %tweetmsg
  remove tweetread.txt
}


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
This is very useful info, thank you Wims.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Link Copied to Clipboard