plugin: handle question aliases

This commit is contained in:
dece 2020-11-05 22:45:21 +01:00
parent 7cbcd5eb85
commit 06dfb99635
2 changed files with 14 additions and 12 deletions

View file

@ -42,7 +42,7 @@ Missing features
- [ ] Wolframalpha
- [x] Youtube: parsing for title, requests for channel or video
- [x] Command aliases
- [ ] Question aliases
- [x] Question aliases
- [x] Sleep
- [x] Various macros:
- [x] asks someone to stop doing something

View file

@ -159,14 +159,16 @@ class Plugin:
# Is it a question I can answer?
question = message[len(words[0]):].strip()
for q in self.config.get("questions", []):
for preamble in self.config.get("questions", []):
aliases = self.config.get("aliases", {}).get(preamble, [])
for q in (preamble, *aliases):
if question.startswith(q):
content = question[len(q):].strip()
content = content.rstrip("?").rstrip()
question = Question(q, content)
question = Question(preamble, content)
self.question = question
self.bot.log_d(
f"Answering question from plugin {self.name}: {question}"
f"Answering from plugin {self.name}: {question}"
)
return True
return False
@ -278,7 +280,7 @@ class Plugin:
@dataclass
class Question:
preambule: str
preamble: str
content: str