plugin: handle question aliases
This commit is contained in:
parent
7cbcd5eb85
commit
06dfb99635
|
@ -42,7 +42,7 @@ Missing features
|
||||||
- [ ] Wolframalpha
|
- [ ] Wolframalpha
|
||||||
- [x] Youtube: parsing for title, requests for channel or video
|
- [x] Youtube: parsing for title, requests for channel or video
|
||||||
- [x] Command aliases
|
- [x] Command aliases
|
||||||
- [ ] Question aliases
|
- [x] Question aliases
|
||||||
- [x] Sleep
|
- [x] Sleep
|
||||||
- [x] Various macros:
|
- [x] Various macros:
|
||||||
- [x] asks someone to stop doing something
|
- [x] asks someone to stop doing something
|
||||||
|
|
|
@ -159,16 +159,18 @@ class Plugin:
|
||||||
|
|
||||||
# Is it a question I can answer?
|
# Is it a question I can answer?
|
||||||
question = message[len(words[0]):].strip()
|
question = message[len(words[0]):].strip()
|
||||||
for q in self.config.get("questions", []):
|
for preamble in self.config.get("questions", []):
|
||||||
if question.startswith(q):
|
aliases = self.config.get("aliases", {}).get(preamble, [])
|
||||||
content = question[len(q):].strip()
|
for q in (preamble, *aliases):
|
||||||
content = content.rstrip("?").rstrip()
|
if question.startswith(q):
|
||||||
question = Question(q, content)
|
content = question[len(q):].strip()
|
||||||
self.question = question
|
content = content.rstrip("?").rstrip()
|
||||||
self.bot.log_d(
|
question = Question(preamble, content)
|
||||||
f"Answering question from plugin {self.name}: {question}"
|
self.question = question
|
||||||
)
|
self.bot.log_d(
|
||||||
return True
|
f"Answering from plugin {self.name}: {question}"
|
||||||
|
)
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def should_handle_command(
|
def should_handle_command(
|
||||||
|
@ -278,7 +280,7 @@ class Plugin:
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Question:
|
class Question:
|
||||||
preambule: str
|
preamble: str
|
||||||
content: str
|
content: str
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue