Skip to content

Instantly share code, notes, and snippets.

@fczuardi
Created September 12, 2010 04:14
Show Gist options
  • Save fczuardi/575830 to your computer and use it in GitHub Desktop.
Save fczuardi/575830 to your computer and use it in GitHub Desktop.
jerkenstein calc plugin
var basic = /[0-9\+\-\*\/\%\.\,\(\)\s]/
,math_properties = /E|LN2|LN10|LOG2E|LOG10E|PI|SQRT1_2|SQRT2/
,math_methods = /abs|acos|asin|atan|atan2|ceil|cos|exp|floor|log|max|min|pow|random|round|sin|sqrt|tan/
,pattern = new RegExp('^\\?calc (('+basic.source+'|Math\\.('+math_properties.source+'|(('+math_methods.source+')\\()))+)$')
this.plugin = {
'name': 'calc'
,'pattern': pattern
,'description': 'Calculate basic arithmetic.'
,'example': '?calc 2+2.'
,'action': function(message) {
try{
message.say(message.user + ': ' + message.match_data[1]+ ' = ' + eval(message.match_data[1]).toString())
}catch(e){
message.say('err')
}
}
,'url': 'http://gist.github.com/575830'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment