Skip to content

Commit

Permalink
modified: messages/messages.py
Browse files Browse the repository at this point in the history
  • Loading branch information
obervinov committed Oct 11, 2024
1 parent 9909143 commit 8a6524a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions messages/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, config_path: str = 'configs/messages.json') -> None:

if not self._templates_is_valid():
raise TemplatesIsNotValid(
"Templates have invalid elements. Please check your configuration file."
"Templates have invalid elements. Please check your configuration file. "
"Otherwise, check examples: https://github.com/obervinov/messages-package?tab=readme-ov-file#-usage-examples"
)

Expand Down Expand Up @@ -79,13 +79,15 @@ def _templates_is_valid(self) -> bool:
if 'templates' in self.configuration:
for template in self.configuration['templates'].values():
if 'text' not in template or 'args' not in template.values():
print(f"[Messages]: there are no text or args in template {template}")
return False
if not isinstance(template['text'], str) or not isinstance(template['args'], list):
print(f"[Messages]: text or args in template {template} has an invalid data type")
return False

args_provided = len(template['args'])
args_expected = len(re.findall(r"{.*?}", template['text']))
if args_provided != args_expected:
print(f"[Messages]: the number of arguments in the template {template} does nots match")
return False
return True

Expand Down

0 comments on commit 8a6524a

Please sign in to comment.