Google Calculator

By Kiddo96 on Nov 27, 2011

This is my version of a Google Calculator. It can do more than a regular calculator, such as calculating measures, converting etc. A few examples are coming.
The commands are either > !calc -calculation here-
or
/calculate -calculation here-
Use !calc in a channel, and it will message you there. In pm and it will respond you there. /calculate simply echos it to your active window.
If you find any bugs, please let me know.> !calc (4 + 6) 6
(4 + 6)
6 = 60
!calc meter to inches
1 meter = 39.3700787 inches
!calc meter to foot
1 meter = 3.2808399 feet
!calc eur to usd
1 Euro = 1.3491 U.S. dollars
!calc 2m3cm
(2 meters)
3 centimeters = 0.06 m^2I got this idea from Jethro, thank you! :-) ( http://www.hawkee.com/snippet/8248/ )
Update - Made an update to my snippet as I found 2 bugs. Please see to it.

on $*:text:/^!calc /Si:#,?:{
  calculate $2-
}
alias calculate {
  if $sock(calculate) || $sock($+(calculate,$nick)) {
    sockclose $v1
  }
  sockopen $iif($event == text,$+(calculate,$nick),calculate) www.google.com 80
  sockmark $iif($event == text,$+(calculate,$nick) msg $iif(#,#,$nick),calculate echo -a) $1-
}
on *:sockopen:calculate*:{
  tokenize 32 $sock($sockname).mark
  sockwrite -nt $sockname GET $+(/ig/calculator?hl=en&q=,$urlencode($3-)) HTTP/1.1
  sockwrite -nt $sockname Host: www.google.com
  sockwrite -nt $sockname Connection: close
  sockwrite -nt $sockname $crlf
}
on *:sockread:calculate*:{
  sockread &greader
  var %greader $bvar(&greader,1-).text
  tokenize 32 $sock($sockname).mark
  if $regex(answer $+ $2,%greader,/rhs: "(.*?)"/) && $regex(calc $+ $2,%greader,/lhs: "(.*?)"/) {
    $1-2 $iif($regml(answer $+ $2,1) == $null,4Something is wrong with the calculation!,03 $&
      $+ $csub($cchr($sup($replace($regml(calc $+ $2,1) = $v1,+,04+03,-,06-03,*,13*03,/,07/03,=,10=03)))))
    sockclose $sockname
  }
}
alias cchr return $regsubex($1,/\\x26#(\d+?);/g,$chr(\1))
alias sup return $regsubex($1,/\\x3csup\\x3e([\d-]+?)\\x3c\/sup\\x3e/Sg,12^\13)
alias urlencode return $regsubex($1,/(\W)/g,% $+ $base($asc(\1),10,16,2)))
alias csub return $regsubex($1,/\\x3csub\\x3e(.+?)\\x3c\/sub\\x3e/g,\1)

Comments

Sign in to comment.
Somsubhra1   -  Jan 11, 2016

Doesn't work on mirc 7.38

 Respond  
Rfsancho   -  Dec 16, 2013

Seems it doesn't work anymore. mIRC ver 7.27 if that's relevant.

Cold_Fussion  -  Jan 05, 2014

nope doesnt work anymore at all...

Sign in to comment

Ryuko   -  Nov 23, 2012

Is there a way to get it to format numbers so that commas are there?

 Respond  
amclay   -  May 12, 2012

yeah that worked. Thanks!

 Respond  
Kiddo96   -  May 11, 2012

Those are colour codes that seem to have dissapeared. Maybe a channel mode or something. Try this colour-free version:

on $*:text:/^!calc /Si:#,?:{
  calculate $2-
}
alias calculate {
  if $sock(calculate) || $sock($+(calculate,$nick)) {
    sockclose $v1
  }
  sockopen $iif($event == text,$+(calculate,$nick),calculate) www.google.com 80
  sockmark $iif($event == text,$+(calculate,$nick) msg $iif(#,#,$nick),calculate echo -a) $1-
}
on *:sockopen:calculate*:{
  tokenize 32 $sock($sockname).mark
  sockwrite -nt $sockname GET $+(/ig/calculator?hl=en&q=,$urlencode($3-)) HTTP/1.1
  sockwrite -nt $sockname Host: www.google.com
  sockwrite -nt $sockname Connection: close
  sockwrite -nt $sockname $crlf
}
on *:sockread:calculate*:{
  sockread &greader
  var %greader $bvar(&greader,1-).text
  tokenize 32 $sock($sockname).mark
  if $regex(answer $+ $2,%greader,/rhs: "(.*?)"/) && $regex(calc $+ $2,%greader,/lhs: "(.*?)"/) {
    $1-2 $iif($regml(answer $+ $2,1) == $null,Something is wrong with the calculation!,$&
      $+ $csub($cchr($sup($regml(calc $+ $2,1) = $v1))))
    sockclose $sockname
  }
}
alias cchr return $regsubex($1,/\\x26#(\d+?);/g,$chr(\1))
alias sup return $regsubex($1,/\\x3csup\\x3e([\d-]+?)\\x3c\/sup\\x3e/Sg,^\1)
alias urlencode return $regsubex($1,/(\W)/g,% $+ $base($asc(\1),10,16,2)))
alias csub return $regsubex($1,/\\x3csub\\x3e(.+?)\\x3c\/sub\\x3e/g,\1)
Somsubhra1  -  Jan 11, 2016

Doesn't work.

Sign in to comment

amclay   -  May 11, 2012

I'm getting weird responses with the calculations in the middle of the answer, is there a way to not have those?

[05:59] <@sys> !calc 2+4
[05:59] 032 04+03 4 10=03 6

[05:52] <@sys> !calc 4 miles in k
[05:52] 034 miles 10=03 6.437376 kilometers

 Respond  
Rfsancho   -  Mar 06, 2012

Flawless~
Thanks :)

 Respond  
Kiddo96   -  Mar 06, 2012

@Rfsancho I edited it and it should work better now! :-)

 Respond  
Rfsancho   -  Mar 04, 2012

works awesome, but got a weird response from it:

[14:07:47] !calc 10m in feet
[14:07:47] 0310 meters = 32.808399 feet (32 feet 912^453⁄\x3csub\x3e64\x3c/sub\x3e inches)

 Respond  
Kiddo96   -  Dec 29, 2011

Thank you for the like and score :-). I made a small edit to the script, so if you find yours to not work, please update it with the current and it should!

 Respond  
Abcdefmonkey   -  Dec 27, 2011

Good snippet. I only use the alias portion. There's plenty of bots on the SwiftIRC network that have a calc command. Just figured I'd snatch this up and replace my alias I made. :P Excellent. 10/10

 Respond  
henbone11   -  Dec 26, 2011

good job. had to fiddle with it a bit to output to chan instead of notice user, but everything works great. thanks.

 Respond  
uneek   -  Dec 07, 2011

Awesome, thanks for the changes Kiddo. Can swear I changed what you did. Oh well, works great.

 Respond  
Destiny98   -  Dec 05, 2011

the bot's name funirc

 Respond  
Kiddo96   -  Dec 05, 2011

The script worked great for everyone else... My guess would be that you put it in a bad place with a bracket missing which lead it to, somehow, try execute the command "funirc".

 Respond  
Destiny98   -  Dec 05, 2011

It works,but i think it wasnt mine mistake,all scripts were working but not yours.

 Respond  
Kiddo96   -  Dec 05, 2011

What? It doesn't work now too?

 Respond  
Destiny98   -  Dec 05, 2011

After that problem it wasnt work too...

 Respond  
Kiddo96   -  Dec 05, 2011

Well, it was something in your remote that caused the problem, not me ;-)
Thanks for the like though :-)

 Respond  
Destiny98   -  Dec 05, 2011

Now it works,i said something is wrong :D I'll like it....

 Respond  
Kiddo96   -  Dec 04, 2011

I made an update to the script, found some bugs. If you have this snippet please delete the one you have and repaste the one from here.

 Respond  
Kiddo96   -  Dec 03, 2011

Then do a ctrl + f search and paste the scripts with that keyword into pastebin.com

 Respond  
Destiny98   -  Dec 03, 2011

not easy to show all scripts,i have a lot of scripts.

 Respond  
Kiddo96   -  Dec 03, 2011

I'm trying to help you Destiny98, but you're not making it simple. PLEASE show me what script/scripts contains "funirc" in your remote and I'll try to help you out.

 Respond  
Destiny98   -  Dec 03, 2011

I get it,its my bot lol,on my computer,i downloaded mirc and start the work.I tried !calc 6+6 or so.

 Respond  
Kiddo96   -  Dec 01, 2011

uneek, change to this:

sockmark $iif($event == text,$+(calculate,$nick) msg #,calculate echo -a) $1-

and the on text event to

on $*:text:/^!calc /Si:#:{

We don't want it to get triggered in a pm and get an error :-)
Thank you both by the way for the likes and scores!

 Respond  
TMFKSOFT   -  Dec 01, 2011

It really needs to be a rule that people using stuff like invision shouldn't bother loading scripts and complaining,

As for this script, I haven't tested it but it looks like a good idea and using igoogles calculator would never have occured to me!

Have a like :)

 Respond  
uneek   -  Nov 30, 2011

Nice script. Very useful.

Although, Ive tried changing this line

sockmark $iif($event == text,$+(calculate,$nick) $iif(#,notice,msg) $nick,calculate echo -a) $1-

to get it to post to channel instead of notice nick...how would I do that?

 Respond  
Jethro   -  Nov 30, 2011

Again, Denstiny98, how did you get "FunIRC?" :/

 Respond  
Kiddo96   -  Nov 30, 2011

What kind of calculation are you trying out?

 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.