|
from .Extension import Extension |
|
import requests |
|
|
|
|
|
ext_config:dict = { |
|
"name": "LoliconPic", |
|
"arguments": { |
|
"tag": "str", |
|
}, |
|
"description": "send 1 specified tag anime picture. (usage in response: /#LoliconPic&萝莉#/)", |
|
|
|
"refer_word": ["图", "pic", "Pic", "再", "还", "涩", "色"], |
|
|
|
"max_call_times_per_msg": 3, |
|
|
|
"author": "CCYellowStar", |
|
|
|
"version": "0.0.1", |
|
|
|
"intro": "发送指定tag二次元图片", |
|
} |
|
|
|
class CustomExtension(Extension): |
|
async def call(self, arg_dict: dict, ctx_data: dict) -> dict: |
|
""" 当拓展被调用时执行的函数 *由拓展自行实现* |
|
|
|
参数: |
|
arg_dict: dict, 由ai解析的参数字典 {参数名: 参数值(类型为str)} |
|
""" |
|
custom_config:dict = self.get_custom_config() |
|
r18 = 0 |
|
tag = arg_dict.get('tag', None) |
|
|
|
url = f"https://api.lolicon.app/setu/v2?tag={tag}&r18={r18}" |
|
res = requests.get(url, verify=False, timeout=10) |
|
data=res.json() |
|
if not data["error"]: |
|
if data["data"]: |
|
data = data["data"][0] |
|
img_src = data["urls"]["original"] |
|
else: |
|
return { |
|
'text': f"[来自拓展] 没有这个tag的图片...", |
|
'image': None, |
|
'voice': None, |
|
} |
|
if img_src is None: |
|
return { |
|
'text': f"[来自拓展] 发送图片错误或超时...", |
|
'image': None, |
|
'voice': None, |
|
} |
|
else: |
|
|
|
return { |
|
'text': None, |
|
'image': img_src, |
|
'voice': None, |
|
} |
|
|
|
def __init__(self, custom_config: dict): |
|
super().__init__(ext_config.copy(), custom_config) |