Commit de1e2f98 authored by Guillaume Binet's avatar Guillaume Binet Committed by GitHub

Templates forced on failing arg botcmd (#973)

* Reproduction for #972

* added a closer repro case.

* Don't template if we got an error from processing.
parent 546ccbbf
......@@ -21,6 +21,7 @@ import traceback
from datetime import datetime
from threading import RLock
import collections
from threadpool import ThreadPool, WorkRequest
from errbot import CommandError
......@@ -412,7 +413,9 @@ class ErrBot(Backend, StoreMixin):
def process_template(template_name, template_parameters):
# integrated templating
if template_name:
# The template needs to be set and the answer from the user command needs to be a mapping
# If not just convert the answer to string.
if template_name and isinstance(template_parameters, collections.Mapping):
return tenv().get_template(template_name + '.md').render(**template_parameters)
# Reply should be all text at this point (See
......@@ -10,3 +10,11 @@ class Test(BotPlugin):
def test_template2(self, msg, args):
return {'variable': 'ok'}
def test_template3(self, msg, args):
yield {'variable': 'ok'}
@arg_botcmd('my_var', type=str, template='test')
def test_template4(self, msg, my_var=None):
return {'variable': my_var}
......@@ -11,3 +11,15 @@ def test_templates_1(testbot):
def test_templates_2(testbot):
assert 'ok' in testbot.exec_command('!test template2')
def test_templates_3(testbot):
assert 'ok' in testbot.exec_command('!test template3')
def test_templates_4(testbot):
assert 'ok' in testbot.exec_command('!test template4 ok')
def test_templates_5(testbot):
assert 'the following arguments are required: my_var' in testbot.exec_command('!test template4')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment