calculator

By alimak96 on Sep 05, 2012

its a simple calculator code for a bot and you can edit it to use ctcp and answer with echo for personal use

synax : !calc < * or + or - or / >
you can turn it on and off using [ !calc on - !calc off ]
and you can use it in a channel or in a private msg

------------------------
| Code By [ Alimak96 ] |
------------------------

on the channel :
#calc on
on *:TEXT:!cinfo:#: { notice $nick $nick , You Can Use !calc <number> < * or + or - or / > <number> }
on *:TEXT:!calc *:#: {
  if ($2 isnum) && ($4 isnum) && ($3 == +) || ($3 == -) || ($3 == *) || ($3 == /) { msg $chan $2- = $calc($2-) }
  elseif ($2 == on) { .enable #calc }
  elseif ($2 == off) { .disable #calc }
  else { notice $nick , You Can Only Use Numbers And ( +,-,*,/ ) }
}
on private msg :
on *:TEXT:!calc *:?: {
  if ($2 isnum) && ($4 isnum) && ($3 == +) || ($3 == -) || ($3 == *) || ($3 == /) { msg $nick $2- = $calc($2-) }
  else { msg $nick  4 You Can Only Use Numbers And ( +,-,*,/ ) }
}
#calc end

Comments

Sign in to comment.
alimak96   -  Sep 08, 2012

Updated "

before you can just use [ numbet +,-,,/ number ] now you can use [ number +,-,,/ number +,-,*,/ number .... etc ]

 Respond  
sunslayer   -  Sep 06, 2012

@alimak96 > added [ ($3 == +) || ($3 == -) || ($3 == ) || ($3 == /) ] in ( if )
if the person didnt use on of these it will send a notice to him
You Can Only Use Numbers And ( +,-,
,/ )That's what I was talking about

 Respond  
Stewie1k94   -  Sep 06, 2012

True. ;)

 Respond  
alimak96   -  Sep 06, 2012

@Stewie1k94
@Jethro
while $calc($2 $3 $4)
works fine
idont have to change it :P

but if ppl want to use them they can simply change it

 Respond  
Stewie1k94   -  Sep 06, 2012

And there's that too. :D

 Respond  
Jethro   -  Sep 06, 2012

You could do:

$calc($2-4)

this will only match the range between $2 and $4.

 Respond  
Stewie1k94   -  Sep 06, 2012

I still think my suggestion would work better, you could also use this check

if ($2-) {
 Respond  
Sorasyn   -  Sep 06, 2012

It is, now. Lol. As for the matching algorithm, you could use regex, but I firmly believe that you should calculate the equation as a whole instead of nit picking it apart. Doing so just makes it's job, and yours harder.

"Don't work harder, work smarter."

 Respond  
alimak96   -  Sep 06, 2012

@Stewie1k94
becauz i think if i use $calc($2-)

this maybe not work :P
if ($2 isnum) && ($4 isnum) && ($3 == +) || ($3 == -) || ($3 == *) || ($3 == /)

 Respond  
Stewie1k94   -  Sep 06, 2012

Why not have

$calc($2-)

instead of

$calc($2 $3 $4)
 Respond  
wazer   -  Sep 06, 2012

(15:02:24) (@user) !calc 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000001
(15:02:25) (@Bot) 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0.000000000000000000000000000000000000000000000000000000000000000000000000000000000001 = 0

Perhaps you should check for this and the other post i made, should give an nan error or something?

 Respond  
alimak96   -  Sep 06, 2012

updated :
you can use [ !calc on ] and [ !calc off ]
and you can use it on private msg to

@Sorasyn I wouldn't have bothered sharing 4 lines of code
its 16 line

@sunslayer There should be some sort of validation on $3 making sure its an operator
what do you mean ?!

 Respond  
alimak96   -  Sep 06, 2012

updated :
added [ ($3 == +) || ($3 == -) || ($3 == ) || ($3 == /) ] in ( if )
if the person didnt use on of these it will send a notice to him
You Can Only Use Numbers And ( +,-,
,/ )

and with
!cinfo
it will notice the person with
nickname , You Can Use !calc < * or + or - or / >

 Respond  
wazer   -  Sep 06, 2012

(14:07:54) (@user) !calc 1 / 0
(14:07:54) (@bot) 1 / 0 = 0

gahhhh

 Respond  
sunslayer   -  Sep 06, 2012

There should be some sort of validation on $3 making sure its an operator

 Respond  
Sorasyn   -  Sep 05, 2012

Sweet. :)

 Respond  
alimak96   -  Sep 05, 2012

@Sorasyn
P.S. You're sporting an opening bracket on line 4, rather than a closing bracket.

updated

 Respond  
Sorasyn   -  Sep 05, 2012

Could expand upon it, based on what kind of calculating it was designed for. At its current state, I wouldn't have bothered sharing 4 lines of code, that won't work as-is anyway.

P.S. You're sporting an opening bracket on line 4, rather than a closing bracket.

 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.