-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdummy.py
58 lines (46 loc) · 1.81 KB
/
dummy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Defines dummy bot"""
from __future__ import annotations
from typing import TYPE_CHECKING
from ..comm.message import MessageContext
if TYPE_CHECKING:
from ..comm.chat_instance import ChatInstance
class DummyBot:
"""Dummy bot that only repeats user messages"""
def __init__(self):
self.format_str = "{}, ditto"
@classmethod
def config(cls):
"""Defines configuration inputs for bot"""
return {"format_str": ('text', {"value": "{}, ditto"})}
def start(self, instance: ChatInstance, data: dict):
"""Initializes bot"""
self.format_str = data.get("format_str", self.format_str)
instance.history.append(MessageContext.create_message(
(f"Hello, I am a dummy bot that repeats messages using the template {self.format_str}"),
"bot"
))
instance.config["enable_autocomplete"] = False
def refresh(self, instance: ChatInstance):
"""Refresh chatbot"""
# pylint: disable=no-self-use
instance.sync_chat("refresh")
def process_message(self, context: MessageContext) -> None:
"""Processes user messages"""
# pylint: disable=unused-argument
context.reply(self.format_str.format(context.text))
return self
def process_autocomplete(self, instance: ChatInstance, request_id: int, query: str):
"""Processes user autocomplete query"""
# pylint: disable=unused-argument
# pylint: disable=no-self-use
instance.send({
"operation": "autocomplete-response",
"responseId": request_id,
"items": [],
})
def save(self):
"""Saves bot"""
return {'format_str': self.format_str}
def load(self, data):
"""Loads bot"""
self.format_str = data.get('format_str', self.format_str)