Skip to content

Commit

Permalink
fix register_call function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Faizal B H authored and ahmadfaizalbh committed Aug 1, 2020
1 parent 523536a commit 27bf980
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ In think mode
```
## Get matched group
for grouping in regex refer [Python regular expression docs](https://docs.python.org/3/howto/regex.html#non-capturing-and-named-groups)
#### Get N<sup>th</sup> matched group of client pattern
```
%N
Expand All @@ -110,8 +111,16 @@ Example to get first matched
```
%1
```
#### Get matching named group of client pattern
```
%Client_pattern_group_name
```
Example to get matching named group `person`
```
%person
```
#### Get N<sup>th</sup> matched group of bots pattern
#### Get N<sup>th</sup> matched group of bots message pattern
```
%!N
```
Expand All @@ -120,6 +129,15 @@ Example to get first matched
%!1
```
#### Get matching named group of bots message pattern
```
%!Bot_pattern_group_name
```
Example to get matching named group `region`
```
%!region
```
## Recursion
Get response as if client said this new statement
```
Expand Down
8 changes: 6 additions & 2 deletions chatbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def call(self, string, session_id):
_function_call = MultiFunctionCall()


def register_call(function_name):
def register_call(function_name=None):
def wrap(function):
if type(function).__name__ != 'function':
raise TypeError("function expected found %s" % type(function).__name__)
Expand All @@ -54,10 +54,14 @@ def wrap(function):
mapper[name] = function
return function

if function_name is None:
return register_call
if type(function_name).__name__ in ('unicode', 'str'):
name = function_name
return wrap
name = function.__name__
if type(function_name).__name__ != 'function':
raise TypeError("String is expected for function name found %s" % type(function).__name__)
name = function_name.__name__
return wrap(function_name)


Expand Down

0 comments on commit 27bf980

Please sign in to comment.