diff options
author | Kyomotoi <[email protected]> | 2022-11-04 10:20:01 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2022-11-04 10:20:01 +0800 |
commit | b2507f8d4dd051490e49bf9a0d235ab930b63ddd (patch) | |
tree | f1c00581aa3cf7ba5382d21415adbe6ab42db1f8 /ATRI/plugins/essential/data_source.py | |
parent | 24342060a99979e6c51390cfe8d86b177136d5c5 (diff) | |
download | ATRI-b2507f8d4dd051490e49bf9a0d235ab930b63ddd.tar.gz ATRI-b2507f8d4dd051490e49bf9a0d235ab930b63ddd.tar.bz2 ATRI-b2507f8d4dd051490e49bf9a0d235ab930b63ddd.zip |
♻️ 重构插件: 基础部件
Diffstat (limited to 'ATRI/plugins/essential/data_source.py')
-rw-r--r-- | ATRI/plugins/essential/data_source.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ATRI/plugins/essential/data_source.py b/ATRI/plugins/essential/data_source.py new file mode 100644 index 0000000..8274db0 --- /dev/null +++ b/ATRI/plugins/essential/data_source.py @@ -0,0 +1,29 @@ +from typing import Union + +from ATRI.utils import MessageChecker +from ATRI.message import MessageSegment + + +def recall_msg_dealer(message: Union[dict, str]) -> str: + if isinstance(message, str): + return message + + cache_list = list() + for i in message: + _type = i.get("type") + _data = i.get("data") + if _type == "text": + cache_list.append(_data["text"]) + elif _type == "image": + url = _data["url"] + check = MessageChecker(url).check_image_url + if check: + cache_list.append(MessageSegment.image(url)) + else: + cache_list.append(f"[该图片可能包含危险内容, 源url: {url}]") + elif _type == "face": + cache_list.append(MessageSegment.face(_data["id"])) + else: + cache_list.append(f"[未知类型信息: {_data}]") + + return str().join(map(str, cache_list))
\ No newline at end of file |