1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Merge pull request #121 from DrBomb/patch-1

extract_argument
This commit is contained in:
FrankWang 2016-03-18 15:09:21 +08:00
commit c64fdf149e

View File

@ -224,3 +224,19 @@ def OrEvent(*events):
or_event.wait = busy_wait or_event.wait = busy_wait
changed() changed()
return or_event return or_event
def extract_arguments(text):
"""
Returns the argument after the command.
Examples:
extract_arguments("/get name"): 'name'
extract_arguments("/get"): ''
extract_arguments("/get@botName name"): 'name'
:param text: String to extract the arguments from a command
:return: the arguments if `text` is a command (according to is_command), else None.
"""
regexp = re.compile("\/\w*(@\w*)*\s*([\s\S]*)",re.IGNORECASE)
result = regexp.match(text)
return result.group(2) if is_command(text) else None