-
-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regex parser : No parsed group detected when using two skills with regex_matcher #872
Comments
Ok i thnink i found why this issue is present; We can understand the problem trough the debug log bellow
First problem :The function async def parse_regex(opsdroid, skills, message): in regex.py parser file look for any function with a regex macher and then parse the message against it. the problem is that this function alter message object each time here :
Second problem :The function async def parse(self, message): in core.py always use the original message object instead of the one sent by parse_regex function
I fixed those two problems like this :
...
...
import copy
async def parse_regex(opsdroid, skills, message):
...
...
if regex:
currentMessage = copy.copy(message)
data.regex = regex
matched_skills.append({
"score": await calculate_score(
opts["expression"], opts["score_factor"]),
"skill": skill,
"config": skill.config,
"message": currentMessage
})
return matched_skills
async def parse(self, message):
"""Parse a string against all skills."""
self.stats["messages_parsed"] = self.stats["messages_parsed"] + 1
tasks = []
if message is not None:
if str(message.text).strip():
_LOGGER.debug(_("Parsing input: %s"), message.text)
tasks.append(
self.eventloop.create_task(parse_always(self, message)))
unconstrained_skills = await self._constrain_skills(
self.skills, message)
ranked_skills = await self.get_ranked_skills(
unconstrained_skills, message)
if ranked_skills:
tasks.append(
self.eventloop.create_task(
self.run_skill(ranked_skills[0]["skill"],
ranked_skills[0]["config"],
ranked_skills[0]["message"])))
return tasks Now all is working fine
I would like to have your feedback before doing a PR with the fix Regards |
Thanks for this! That sounds like a reasonable solution. I would be keen for you to check the other parsers to see if they suffer form the same problem when raising your PR. |
I checked some parsers, those seems ok. Proposition : It will be a good thing to allow user to choose between a full match (re.fullmatch) or a simple match (re.match) This will prevent a confusion between two skills the first parsing hi and the second parsing hihi (it's just an example :-) ) |
Sounds good. There is already a kwarg to set whether the regex is case sensitive or not. You could add this as another one. |
ok, to keep subjects separated, i will work on the fix first and after on adding the choices between a full or a simple match |
Hi
Description
When activating more than one skill using regex (example : hello skill and welcome skill or loudnoise skill) if the second skill use group name in regex parser, no group are detected and passed into message.regex.group
Steps to Reproduce
1- clone the last version of opsdroid
2- activate regex parser in config file
3- activate hello skill in config file
4- activate welcome skill in config file (parsing sentence like : welcome iobreaker to paris)
5- Activate telegram connector (I tested using telegram)
6- send : welcome iobreaker to paris
7- error will appear in opsdroid logs
Expected Functionality
Experienced Functionality
You can use this skill (welcome skill) i created to facilitate the debug
When sending the message welcome iobreaker to paris without activating hello skill all works fine
When activating the hello skill and the welcome skill the error happened : IndexError: no such group
Perhaps I am missing something !! but it's a strange as a behaviour/isue
Versions
Configuration File
Regards
The text was updated successfully, but these errors were encountered: