My First script posted on Hawkee (code snippets, not forums. I use the forums more)
Anyhow, I made it so the command is !calc
It works with spaces; commas, m as in million, k as in thousand, b as in billion, and if it returns 0 it messages the channel why the result may be 0
Anyway, here it is!
-$comma made by FiberOPtics.
Previous description is for the old script. Now, basically it regsubs it. Used the $comma regex in still, credit of the regular expression of that to FiberOPtics still.
```mirc
on *:TEXT:!calc*:#: msg # $iif($regsubex($remove($2-,$chr(32),$chr(44)),/((^|[+-/^*%]+)(([0-9]|\56)+)(k|m|b)|(^|[+-/^*%]+)(([0-9]|\56)+)|(^|[+-/^*%]+)(\50(.+?)\51))/ig,),Syntax Error,$iif(!$2,Syntax Error,[!calc] $2- = $regsubex($ticks,$calc($regsubex($ticks,$remove($2-,$chr(44),$chr(32)),/(^|[+-/*%]+|[+-/*%]+\50)(([0-9]|\56)+)(k|m|b)/ig,\1 $+ ( $+ \2 $+ $iif(\4 == b,*1000000000,$iif(\4 == m,*1000000,*1000)) $+ ))),/\G([+-]?\d+?)(?=(?:\d{3})++(?=\.\d++$|$))/g,\1 $+ $chr(44))))
```
Okay, so this was in a high need of a recode.
First of all, with the method I used above it replaced 'm' with 1000000
That works in some cases, but if you have !calc 1m/1m it returns 1,000,000,000,000 instead of 1.
So I turned it into regex, making it do something like $calc((11000000)/(1*1000000))
However this wasn't capturing the . so I made another edit to incorporate that.
...then I made it one line xD
Old script for history to anyone who's interested, editing the new script above now.
alias -l comma {
var %a, %b = $regsub($ticks,$1,/\G([+-]?\d+?)(?=(?:\d{3})++(?=\.\d++$|$))/g,\1 $+ $chr(44),%a)
return %a
}
on *:text:!calc*:#: {
if ($1 == !calc) {
if ($2-) {
if ($chr(37) isin $1-) {
msg $chan You cannot use percent in this calculator, sorry.
}
else {
if ($remove($2-,k,m,b,$chr(44),.,+,-,/,*,^) !isnum) msg $chan Sorry $nick $+ , I can't calculate words.
else {
var %calc1 $comma($calc($replace($2-,k,*1000,m,*1000000,b,*1000000000,$chr(44),$null)))
timer 1 1 msg $chan 4Calculating: 03 $+ $2-
timer 1 2 msg $chan 4Result: 03 $+ %calc1
if (%calc1 == 0) {
timer 1 5 msg $chan If 0 is not the correct answer, that is because this calculator can't handle some or all of the characters used or the formula used.
}
}
else msg $chan I can't calculate nothing...
}
}
}
}
i just remembered an old post i made on another forum that would be quite relevant here:
http://forum.swiftirc.net/viewtopic.php?f=32&t=4003
both of the issues i mentioned in my post (about modulo and the effect of $replace() when used with certain operators) are present in this snippet.
about the k m b, on your main script, you use it to multiple if the person use
!calc 33K+44K , then the script will recognize that this is 33,000+44,000
we just used $replace, on this case, to replace k for 1000, m 1000000, b *1000000000
so the $calc identifier will multiply, in this case
$calc(33*1000) and 33k, will become 33,000
Hmmm
for isnum...
What will that do to the k,m,b? and * and + and things?
Sorry, I just prefer if ($1 == !calc) then adding a space, because if you use it for scripts that have like.... for instance a number association to a person, you can either do !number or !number nick and that doesnt work if there's a space up the top for just !number
correct me if I'm wrong.
look dont need the if $1 == !calc, cause if you put an space here
on *:text:!calc *:#: {
this
!calc123
will not happen, by the way, why dont u do a check for
if ($2 isnum)
to check if $2- is number, then you will send a message to channel like
if ($2 !isnum) { msg $chan ERROR: syntax: !calc 1+1 }
the $strip identifier, strip all incoming colors
So make it...
on *:text:!calc*:#: {
if ($1 == !calc) {
if ($2-) {
if ($chr(37) isin $1-) {
msg $chan You cannot use percent in this calculator, sorry.
}
else {
var %calc1 $comma($calc($replace($2-,k,*1000,m,*1000000,b,*1000000000,$chr(44),$null)))
timer 1 1 msg $chan Calculating $2- $+ ....
timer 1 2msg $chan Result: %calc1
if (%calc5 == 0) {
msg $chan If 0 is not the correct answer, that is because this calculator can't handle some or all of the characters used.
}
}
else msg $chan I can't calculate nothing...
}
}
}
Is that right?
Sorry if my BB code didn't work, by the way
Aside from the useless "Calculating...." Its a pretty nice script. The only reason I say this is because its nearly a split second for the results to be sent, and in my opinion its kind of a killer.
Could crunch down some of the prefix enumerating and calculating into
msg $chan $comma($calc($replace(%calc1,k,*1000,m,*1000000,b,*1000000000)))