feat: support sending typing state
This commit is contained in:
parent
0b20e0ac1a
commit
3bef3e1a51
1 changed files with 26 additions and 1 deletions
27
src/bot.py
27
src/bot.py
|
@ -80,6 +80,8 @@ class Bot:
|
||||||
self.image_generation_backend: str = image_generation_backend
|
self.image_generation_backend: str = image_generation_backend
|
||||||
self.timeout = timeout or 120.0
|
self.timeout = timeout or 120.0
|
||||||
|
|
||||||
|
self.bot_id = None
|
||||||
|
|
||||||
self.base_path = Path(os.path.dirname(__file__)).parent
|
self.base_path = Path(os.path.dirname(__file__)).parent
|
||||||
|
|
||||||
if not os.path.exists(self.base_path / "images"):
|
if not os.path.exists(self.base_path / "images"):
|
||||||
|
@ -134,6 +136,9 @@ class Bot:
|
||||||
|
|
||||||
async def login(self) -> None:
|
async def login(self) -> None:
|
||||||
await self.driver.login()
|
await self.driver.login()
|
||||||
|
# get user id
|
||||||
|
resp = await self.driver.users.get_user(user_id="me")
|
||||||
|
self.bot_id = resp["id"]
|
||||||
|
|
||||||
async def run(self) -> None:
|
async def run(self) -> None:
|
||||||
await self.driver.init_websocket(self.websocket_handler)
|
await self.driver.init_websocket(self.websocket_handler)
|
||||||
|
@ -187,6 +192,13 @@ class Bot:
|
||||||
if self.gpt_prog.match(message):
|
if self.gpt_prog.match(message):
|
||||||
prompt = self.gpt_prog.match(message).group(1)
|
prompt = self.gpt_prog.match(message).group(1)
|
||||||
try:
|
try:
|
||||||
|
# sending typing state
|
||||||
|
await self.driver.users.publish_user_typing(
|
||||||
|
self.bot_id,
|
||||||
|
options={
|
||||||
|
"channel_id": channel_id,
|
||||||
|
},
|
||||||
|
)
|
||||||
response = await self.chatbot.oneTimeAsk(prompt)
|
response = await self.chatbot.oneTimeAsk(prompt)
|
||||||
await self.send_message(channel_id, f"{response}", root_id)
|
await self.send_message(channel_id, f"{response}", root_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -197,6 +209,13 @@ class Bot:
|
||||||
elif self.chat_prog.match(message):
|
elif self.chat_prog.match(message):
|
||||||
prompt = self.chat_prog.match(message).group(1)
|
prompt = self.chat_prog.match(message).group(1)
|
||||||
try:
|
try:
|
||||||
|
# sending typing state
|
||||||
|
await self.driver.users.publish_user_typing(
|
||||||
|
self.bot_id,
|
||||||
|
options={
|
||||||
|
"channel_id": channel_id,
|
||||||
|
},
|
||||||
|
)
|
||||||
response = await self.chatbot.ask_async(
|
response = await self.chatbot.ask_async(
|
||||||
prompt=prompt, convo_id=user_id
|
prompt=prompt, convo_id=user_id
|
||||||
)
|
)
|
||||||
|
@ -225,7 +244,13 @@ class Bot:
|
||||||
prompt = self.pic_prog.match(message).group(1)
|
prompt = self.pic_prog.match(message).group(1)
|
||||||
# generate image
|
# generate image
|
||||||
try:
|
try:
|
||||||
# generate image
|
# sending typing state
|
||||||
|
await self.driver.users.publish_user_typing(
|
||||||
|
self.bot_id,
|
||||||
|
options={
|
||||||
|
"channel_id": channel_id,
|
||||||
|
},
|
||||||
|
)
|
||||||
b64_datas = await imagegen.get_images(
|
b64_datas = await imagegen.get_images(
|
||||||
self.httpx_client,
|
self.httpx_client,
|
||||||
self.image_generation_endpoint,
|
self.image_generation_endpoint,
|
||||||
|
|
Loading…
Reference in a new issue