lintonxue00
commited on
Commit
•
0b1aeae
1
Parent(s):
ef22ec8
Upload ext_lolicon_pic.py
Browse files- 不知道/回收站/ext_lolicon_pic.py +62 -0
不知道/回收站/ext_lolicon_pic.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from .Extension import Extension
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# 拓展的配置信息,用于ai理解拓展的功能 *必填*
|
5 |
+
ext_config:dict = {
|
6 |
+
"name": "LoliconPic", # 拓展名称,用于标识拓展
|
7 |
+
"arguments": {
|
8 |
+
"tag": "str", # 关键字
|
9 |
+
},
|
10 |
+
"description": "send 1 specified tag anime picture. (usage in response: /#LoliconPic&萝莉#/)",
|
11 |
+
# 参考词,用于上下文参考使用,为空则每次都会被参考(消耗token)
|
12 |
+
"refer_word": ["图", "pic", "Pic", "再", "还", "涩", "色"],
|
13 |
+
# 每次消息回复中最大调用次数,不填则默认为99
|
14 |
+
"max_call_times_per_msg": 3,
|
15 |
+
# 作者信息
|
16 |
+
"author": "CCYellowStar",
|
17 |
+
# 版本
|
18 |
+
"version": "0.0.1",
|
19 |
+
# 拓展简介
|
20 |
+
"intro": "发送指定tag二次元图片",
|
21 |
+
}
|
22 |
+
|
23 |
+
class CustomExtension(Extension):
|
24 |
+
async def call(self, arg_dict: dict, ctx_data: dict) -> dict:
|
25 |
+
""" 当拓展被调用时执行的函数 *由拓展自行实现*
|
26 |
+
|
27 |
+
参数:
|
28 |
+
arg_dict: dict, 由ai解析的参数字典 {参数名: 参数值(类型为str)}
|
29 |
+
"""
|
30 |
+
custom_config:dict = self.get_custom_config() # 获取yaml中的配置信息
|
31 |
+
r18 = 0 #添加r18参数 0为否,1为是,2为混合
|
32 |
+
tag = arg_dict.get('tag', None)
|
33 |
+
|
34 |
+
url = f"https://api.lolicon.app/setu/v2?tag={tag}&r18={r18}"
|
35 |
+
res = requests.get(url, verify=False, timeout=10)
|
36 |
+
data=res.json()
|
37 |
+
if not data["error"]:
|
38 |
+
if data["data"]:
|
39 |
+
data = data["data"][0]
|
40 |
+
img_src = data["urls"]["original"]
|
41 |
+
else:
|
42 |
+
return {
|
43 |
+
'text': f"[来自拓展] 没有这个tag的图片...",
|
44 |
+
'image': None, # 图片url
|
45 |
+
'voice': None, # 语音url
|
46 |
+
}
|
47 |
+
if img_src is None:
|
48 |
+
return {
|
49 |
+
'text': f"[来自拓展] 发送图片错误或超时...",
|
50 |
+
'image': None, # 图片url
|
51 |
+
'voice': None, # 语音url
|
52 |
+
}
|
53 |
+
else:
|
54 |
+
# 返回的信息将会被发送到会话中
|
55 |
+
return {
|
56 |
+
'text': None, # 文本信息
|
57 |
+
'image': img_src, # 图片url
|
58 |
+
'voice': None, # 语音url
|
59 |
+
}
|
60 |
+
|
61 |
+
def __init__(self, custom_config: dict):
|
62 |
+
super().__init__(ext_config.copy(), custom_config)
|