mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
update alapi
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from configs.config import TL_KEY
|
||||
from configs.config import TL_KEY, ALAPI_TOKEN
|
||||
import aiohttp
|
||||
import random
|
||||
import os
|
||||
from configs.path_config import IMAGE_PATH, DATA_PATH
|
||||
from services.log import logger
|
||||
from util.init_result import image
|
||||
from util.utils import get_bot
|
||||
|
||||
@@ -13,6 +14,8 @@ except ModuleNotFoundError:
|
||||
|
||||
url = "http://openapi.tuling123.com/openapi/api/v2"
|
||||
|
||||
check_url = "https://v2.alapi.cn/api/censor/text"
|
||||
|
||||
index = 0
|
||||
|
||||
anime_data = json.load(open(DATA_PATH + 'anime.json', 'r', encoding='utf8'))
|
||||
@@ -97,6 +100,7 @@ async def get_qqbot_chat_result(text: str, img_url: str, user_id: int, user_name
|
||||
content = content.replace('{br}', '\n')
|
||||
if content.find('提示') != -1:
|
||||
content = content[:content.find('提示')]
|
||||
|
||||
return content
|
||||
if resp_payload['results']:
|
||||
for result in resp_payload['results']:
|
||||
@@ -140,3 +144,22 @@ def no_result() -> str:
|
||||
]) + image(
|
||||
random.choice(os.listdir(IMAGE_PATH + "noresult/")
|
||||
), "noresult")
|
||||
|
||||
|
||||
async def check_text(text: str):
|
||||
if not ALAPI_TOKEN:
|
||||
return text
|
||||
params = {
|
||||
'token': ALAPI_TOKEN,
|
||||
'text': text
|
||||
}
|
||||
async with aiohttp.ClientSession() as session:
|
||||
try:
|
||||
async with session.get(url, timeout=2, params=params) as response:
|
||||
data = await response.json()
|
||||
if data['code'] == 200:
|
||||
if data['conclusion_type'] == 2:
|
||||
return no_result()
|
||||
except Exception as e:
|
||||
logger.error(f'检测违规文本错误...e:{e}')
|
||||
return text
|
||||
|
||||
Reference in New Issue
Block a user