calculator updated a bit

By Stewie1k94 on Apr 04, 2011

Commands: !calc .

Feel free to comment.

$comma() Alias made by: Fibre0Ptics

alias -l comma {
  var %a, %b = $regsub($ticks,$1,/\G([+-]?\d+?)(?=(?:\d{3})++(?=\.\d++$|$))/g,\1 $+ $chr(44),%a)
  return %a
}
on $*:text:/^!calc\s(.*)/iS:#:{
  if (!$2-) msg # I can't calculate nothing $nick $+ ...
  elseif ($chr(37) isin $1-) msg # You cannot use percent in this calculator, sorry. 
  elseif ($remove($2-,k,m,b,$chr(44),$chr(32),.,+,-,/,*,^) !isnum) msg # Sorry $nick $+ , I can't calculate words.
  else {
    var %calc $calc($replace($remove($2-,$chr(32),$chr(36),$chr(44)),k,*1000,m,*1000000,b,*1000000000)))
    msg # $+([,!calc,]) Calculating: $2-
    msg # $+([,!calc,]) The Result: $comma($calc(%calc))
  }
}

Comments

Sign in to comment.
Stewie1k94   -  Sep 20, 2011

Updated again

 Respond  
Stewie1k94   -  Jun 15, 2011

Ok thankyou for your comment and i will have a look at this later

 Respond  
Jethro   -  Jun 14, 2011

It's best you use $wildsite and local variables like so:

on $*:text:/^(!|@)Calc( |$)/Si:#:{
  var %n = notice $nick, %m = $iif($regml(1) == !,%n,msg #), %2 = $strip($replace($2-,x,*))
  if (!$ignore($wildsite)) {
    if (!$strip($2)) {
      %n please use !calc <calculation>
    }
    else {
      %m Calculating: %2
      %m Result is: $calc(%2)
      .ignore -u4 $wildsite
    }
  }
}

Edit - I see what you're getting at. You only want the trigger to ignore for the else condition. Then it's best you notice the $nick to check for $2, so that it doesn't appear flood-y if messaged in the channel when someone messes with you.

I've taken the liberty of making a couple of adjustments.

 Respond  
Stewie1k94   -  Jun 14, 2011

Ok i have updated it to

$iif($regml(1) == !,notice $nick,msg $chan)

i have also added some flood protection

.ignore -u4 $nick
 Respond  
Jethro   -  Jun 14, 2011

Why didn't you use $regml(1) in place of $left($1,1) ?

 Respond  
Stewie1k94   -  Jun 14, 2011

i have added

$iif($left($1,1) == !,notice $nick,msg $chan) 
 Respond  
Stewie1k94   -  Apr 30, 2011

ive also added

if ($2 == $null) {
    msg $chan please use !calc <calculation>
  }
  else {
 Respond  
Stewie1k94   -  Apr 30, 2011

ok thanks

 Respond  
Jethro   -  Apr 29, 2011
on $*:text:/^[!@](c)?(alc)?(ulate)?( |$)/Si:#:{

This is more precise.

 Respond  
Stewie1k94   -  Apr 29, 2011

well i dont really want a calculater for more stuff but im only trying wantto know what ppl think

btw i added

on $*:text:/^[!@]c|calc|calculate/Si:#:{
 Respond  
Jethro   -  Apr 20, 2011

The whole purpose of the original snippet is for simple calculations. I doubt the author has thought up a prudent calculation snippet as "fancy" as what you have demonstrated here. Let's not get into the matter of tampering with its fallacy by "digging more holes" :p Nothing is 100% perfect.; perfection is far too subjective.

 Respond  
Dani_l11   -  Apr 20, 2011

Bielie, you can use if ($1 isnum 1000000-999999999), also your script will fail if the calculation includes spaces. Remove chr(32). And you are only calling %output once,
$iif($left($1,1) == @,/msg #,/notice $nick) $num(%calc) $iif($short(%scalc),$v1,$chr(32)) would work. You can even leave the $chr(32), just $iif($short(%scalc),$v1)

#calc on
on $*:TEXT:/^[!.@]calc(ulate)?\w/Si:#: {
  if (!$2) { notice $nick Please use the correct syntax: !calc <calculation> | halt }
if ($regex($1-,/[^1-9][mbkt]/i)) { notice $nick Invalid expression | halt }
if ($regex($remove($2-,m,b,k,t),/\D/)) { notice $nick Invalid expression | halt }
  var %calc $calc($replace($remove($2-,$chr(32)), :, /, x, *,t,*1000b,b,*1000m,m,*1000m,k,*1000))
 $iif($left($1,1) == @,/msg #,/notice $nick) 4=2 $bytes(%calc,bd) $iif($short(%scalc),$chr(40) $+ $v1),)
  .ignore -u3 $nick
}

alias short {
  if ($1 < 0) { scon 0 return - $!+ $!short( $abs($1) ) }
  if ($1 isnum 1000-999999) { return 3( $+ $round($calc($1- / 1000),2) $+ k $+ 3) }
  if ($1 isnum 1000000-999999999) { return 3( $+ $round($calc($1- / 1000000),2) $+ m $+ 3) }
  if ($1 isnum 1000000000-999999999999) { return 3( $+ $round($calc($1- / 1000000000),2) $+ b $+ 3) }
  if ($1 >= 1000000000000) { return 3( $+ $round($calc($1- / 1000000000000),2) $+ t $+ 3) }
}
#calc end

Not waterproof but works in most cases

 Respond  
troll   -  Apr 20, 2011

such an advanced script

 Respond  
Bielie   -  Apr 08, 2011

You should use something that works with more characters: This is mine ;)

#calc on
on $*:TEXT:/^[!.@]calc|calculate/Si:#: {
  if (!$2) { notice $nick Please use the correct syntax: !calc <calculation> | halt }
  var %output $iif($left($1,1) == @,/msg #,/notice $nick)
  var %scalc $calc($2-)
  var %calc $calc($replace($2-, :, /, x, *))
  %output $2- 4=2 $num(%calc) $iif($short(%scalc),$v1,$chr(32))
  .ignore -u3 $nick
}

alias num { return $bytes($1-,bd) }
alias short {
  if ($1 < 0) { scon 0 return - $!+ $!short( $abs($1) ) }
  if ($1 >= 1000) && ($1 <= 999999) { return 3( $+ $round($calc($1- / 1000),2) $+ k $+ 3) }
  if ($1 >= 1000000) && ($1 < 999999999) { return 3( $+ $round($calc($1- / 1000000),2) $+ m $+ 3) }
  if ($1 >= 1000000000) && ($1 < 999999999999) { return 3( $+ $round($calc($1- / 1000000000),2) $+ b $+ 3) }
  if ($1 >= 1000000000000) && ($1 < 999999999999999) { return 3( $+ $round($calc($1- / 1000000000000),2) $+ t $+ 3) }
}
#calc end
 Respond  
Stewie1k94   -  Apr 07, 2011

how do i get the code in a code box ?

 Respond  
Stewie1k94   -  Apr 07, 2011

well i am using the script like this atm

on :TEXT: :#:{
if ($1 == !calc) msg $chan 3 calculating $2- = $calc($2-)
}

 Respond  
HaLF_EviL   -  Apr 06, 2011

hmm its kewl ~! , just tell me one thing how we will solve this space problem ? mate ?? have u any idea @tocalfane1 ? :=)

 Respond  
Dani_l11   -  Apr 06, 2011

This will fail when there are spaces inside the sum. Example: !Calc 1 + 1

Use tokenize 32 $remove($2-,$chr(32))
Also replace common used characters, like x and :
tokenize 32 $replace($remove($2-,$chr(32)),x,*,:,/)

And add spamprotection.

 Respond  
Jethro   -  Apr 04, 2011

No, it ain't the same. There's no such word as "rusult." It's a misspelling. That said, you should add a trigger protection to your code to safeguard yourself from being flooded out if someone's gonna screw you. You'll be screwed without it. Last but not least, leave a space between > !calc *so the code doesn't get triggered for an empty value if the $2- aren't filled.

 Respond  
Stewie1k94   -  Apr 04, 2011

thanks and aint that the same

 Respond  
Neo--   -  Apr 04, 2011

Nice,
Only change :

the rusult is:

to

the result is:

 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.