~aj00200/bbottheircbot/bbottheircbot8

« back to all changes in this revision

Viewing changes to modules/mathbot.py

  • Committer: AJ00200
  • Date: 2011-03-14 00:46:00 UTC
  • Revision ID: aj0020020@live.com-20110314004600-lt7dhe2e3h5isdqy
BBot v7.0.0b5 - Fixed bug #12 - Fixed the bug causing errors when using functions with multiple arguments by allowing spaces to be evaluated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
    '..22..':'geo.line(', 
69
69
    '..23..':'geo.cm(', 
70
70
    '..24..':'geo.inch('
71
 
    
72
71
    }
73
 
    chars = '_ghijklmnopqrstuvwyz#@$\'"!: = '
 
72
    chars = '_ghijklmnopqrstuvwyz#@$\'"!:='
74
73
 
75
74
    def math(self, nick, channel, param = None):
76
75
        '''Functions and operators supported are: +, -, *, /, %, sqrt, pow, ceil, floor, log, sin, cos, tan'''
82
81
                expr = expr.replace(each, '')
83
82
            for each in self.invert:
84
83
                expr = expr.replace(' %s ' % each, self.invert[each])
85
 
            expr = expr.replace('//', '.0/')
86
84
            try:
87
85
                if '**' in expr:
88
86
                    raise Disallowed('**')
90
88
            except Exception, e:
91
89
                self.report_error(channel, e)
92
90
 
93
 
    def report_error(self, channel, e):
 
91
    def report_error(self, channel, error):
94
92
        '''Report an error encountered while evaluating an expression
95
93
        to the channel from which the command orgionated'''
96
 
        self.msg(channel, 'Error %s; with arguments %s' % (type(e), e.args))
 
94
        self.msg(channel, 'Error %s; Arguments %s' % (type(error), error.args))
97
95
 
98
96
class Disallowed(Exception):
99
97
    def __init__(self, string):