2024-06-10 16:46:07 +08:00
|
|
|
from typing import TYPE_CHECKING, TypeVar
|
2024-06-28 23:19:10 +08:00
|
|
|
import platform
|
|
|
|
import PIL.Image
|
|
|
|
import io
|
2024-06-10 16:46:07 +08:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ica_typing import IcaNewMessage, IcaClient
|
|
|
|
from ica_typing import TailchatReciveMessage, TailchatClient
|
|
|
|
else:
|
|
|
|
IcaNewMessage = TypeVar("NewMessage")
|
|
|
|
IcaClient = TypeVar("IcaClient")
|
|
|
|
TailchatReciveMessage = TypeVar("TailchatReciveMessage")
|
|
|
|
TailchatClient = TypeVar("TailchatClient")
|
2024-02-22 12:47:20 +08:00
|
|
|
|
2024-03-16 16:58:18 +08:00
|
|
|
def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
|
2024-02-22 14:38:37 +08:00
|
|
|
if not (msg.is_from_self or msg.is_reply):
|
|
|
|
if msg.content == "/bot":
|
2024-03-16 00:15:49 +08:00
|
|
|
reply = msg.reply_with(f"ica-async-rs({client.version})-sync-py {client.ica_version}")
|
2024-02-22 12:47:20 +08:00
|
|
|
client.send_message(reply)
|
2024-06-04 23:48:01 +08:00
|
|
|
|
|
|
|
|
2024-06-05 00:03:19 +08:00
|
|
|
def on_tailchat_message(msg: TailchatReciveMessage, client: TailchatClient) -> None:
|
|
|
|
# if not (msg.is_from_self or msg.is_reply):
|
|
|
|
if not (msg.is_reply):
|
|
|
|
if msg.content == "/bot":
|
2024-06-05 21:52:15 +08:00
|
|
|
reply = msg.reply_with(f"tailchat-async-rs({client.version})-sync-py {client.tailchat_version}")
|
2024-06-05 00:03:19 +08:00
|
|
|
client.send_message(reply)
|
2024-06-28 23:19:10 +08:00
|
|
|
elif msg.content == "/image":
|
|
|
|
image = PIL.Image.new("RGB", (100, 100), (255, 255, 255))
|
|
|
|
img_cache = io.BytesIO()
|
|
|
|
image.save(img_cache, format="JPEG")
|
|
|
|
raw_img = img_cache.getvalue()
|
|
|
|
img_cache.close()
|
|
|
|
reply = msg.reply_with("Here is an image")
|
|
|
|
reply.set_img(raw_img, "just_img.png")
|
|
|
|
client.send_message(reply)
|