示例#1
0
        def evalrepl(match):
            if match.group('lookup'):  # <>
                if re.match(r'<a?([@#]|:.+:)[&!]{0,2}\d+>',
                            match.group(0)):  # ignore mentions
                    return match.group(0)
                out = match.group('lookup')
                evalresult = str(self.names.get(out, out))
            elif match.group('roll'):  # {}
                varstr = match.group('roll')
                curlyout = ""
                for substr in re.split(ops, varstr):
                    temp = substr.strip()
                    curlyout += str(self.names.get(temp, temp)) + " "
                try:
                    evalresult = str(self._limited_roll(curlyout))
                except:
                    evalresult = '0'
            elif match.group('drac1'):  # {{}}
                expr = match.group('drac1').strip()
                try:
                    evalresult = self.eval(expr)
                except Exception as ex:
                    raise EvaluationError(ex, expr)
            elif match.group('drac2'):  # <drac2>...</drac2>
                expr = textwrap.dedent(match.group('drac2')).strip()
                try:
                    evalresult = self.execute(expr)
                except Exception as ex:
                    raise EvaluationError(ex, expr)
            else:
                evalresult = None

            return str(evalresult) if evalresult is not None else ''
示例#2
0
 def transformed_str(self, string):
     """Transforms a dicecloud-formatted string (evaluating text in {})."""
     try:
         return re.sub(r'(?<!\\){(.+?)}',
                       lambda m: str(self.eval(m.group(1).strip())), string)
     except Exception as ex:
         raise EvaluationError(ex, string)
示例#3
0
        def evalrepl(match):
            try:
                if match.group('drac1'):  # {{}}
                    evalresult = self.eval(match.group('drac1').strip())
                elif match.group('roll'):  # {}
                    try:
                        evalresult = self.eval(match.group('roll').strip())
                    except:
                        evalresult = match.group(0)
                else:
                    evalresult = None
            except Exception as ex:
                raise EvaluationError(ex, match.group(0))

            return str(evalresult) if evalresult is not None else ''