2023-02-05 14:33:33 +00:00
|
|
|
|
from core.builtins import Bot
|
|
|
|
|
from core.builtins import Image
|
2021-10-24 10:55:45 +00:00
|
|
|
|
from core.component import on_command
|
2021-08-07 07:56:48 +00:00
|
|
|
|
from database import BotDBUtil
|
2022-01-20 12:13:03 +00:00
|
|
|
|
from .dbutils import CytoidBindInfoManager
|
2021-07-27 17:42:47 +00:00
|
|
|
|
from .profile import cytoid_profile
|
|
|
|
|
from .rating import get_rating
|
2022-01-19 17:02:23 +00:00
|
|
|
|
from .utils import get_profile_name
|
2021-07-27 17:42:47 +00:00
|
|
|
|
|
2021-10-24 10:55:45 +00:00
|
|
|
|
cytoid = on_command('cytoid',
|
2022-01-26 07:50:05 +00:00
|
|
|
|
developers=['OasisAkari'], alias='ctd')
|
2021-07-27 17:42:47 +00:00
|
|
|
|
|
2021-10-24 10:55:45 +00:00
|
|
|
|
|
2022-01-19 17:02:23 +00:00
|
|
|
|
@cytoid.handle('profile [<UserID>] {查询一个用户的基本信息}')
|
2023-02-05 14:33:33 +00:00
|
|
|
|
async def _(msg: Bot.MessageSession):
|
2021-07-27 17:42:47 +00:00
|
|
|
|
if msg.parsed_msg['profile']:
|
|
|
|
|
await cytoid_profile(msg)
|
2021-10-24 10:55:45 +00:00
|
|
|
|
|
|
|
|
|
|
2022-01-19 17:02:23 +00:00
|
|
|
|
@cytoid.handle('(b30|r30) [<UserID>] {查询一个用户的b30/r30记录}')
|
2023-02-05 14:33:33 +00:00
|
|
|
|
async def _(msg: Bot.MessageSession):
|
2022-08-09 17:02:50 +00:00
|
|
|
|
if 'b30' in msg.parsed_msg:
|
2021-07-27 17:42:47 +00:00
|
|
|
|
query = 'b30'
|
2022-08-09 17:02:50 +00:00
|
|
|
|
elif 'r30' in msg.parsed_msg:
|
2021-07-27 17:42:47 +00:00
|
|
|
|
query = 'r30'
|
|
|
|
|
else:
|
|
|
|
|
query = False
|
2022-08-09 17:02:50 +00:00
|
|
|
|
pat = msg.parsed_msg.get('<UserID>', False)
|
2022-01-19 17:02:23 +00:00
|
|
|
|
if pat:
|
|
|
|
|
query_id = pat
|
|
|
|
|
else:
|
|
|
|
|
query_id = CytoidBindInfoManager(msg).get_bind_username()
|
|
|
|
|
if query_id is None:
|
2022-08-18 15:24:46 +00:00
|
|
|
|
await msg.finish('未绑定用户,请使用~cytoid bind <username>绑定一个用户。')
|
2021-07-27 17:42:47 +00:00
|
|
|
|
if query:
|
2022-06-20 13:35:56 +00:00
|
|
|
|
if msg.target.targetFrom == 'TEST|Console':
|
|
|
|
|
c = 0
|
|
|
|
|
else:
|
|
|
|
|
qc = BotDBUtil.CoolDown(msg, 'cytoid_rank')
|
2022-08-15 17:42:40 +00:00
|
|
|
|
c = qc.check(150)
|
2021-07-27 17:42:47 +00:00
|
|
|
|
if c == 0:
|
2022-01-19 17:02:23 +00:00
|
|
|
|
img = await get_rating(query_id, query)
|
2021-07-27 17:42:47 +00:00
|
|
|
|
if 'path' in img:
|
2022-08-27 14:02:26 +00:00
|
|
|
|
await msg.sendMessage([Image(path=img['path'])], allow_split_image=False)
|
2021-07-27 17:42:47 +00:00
|
|
|
|
if 'text' in img:
|
|
|
|
|
await msg.sendMessage(img['text'])
|
2022-06-20 13:35:56 +00:00
|
|
|
|
if msg.target.targetFrom != 'TEST|Console':
|
|
|
|
|
if img['status']:
|
|
|
|
|
qc.reset()
|
2021-07-27 17:42:47 +00:00
|
|
|
|
else:
|
2023-01-28 05:53:11 +00:00
|
|
|
|
await msg.sendMessage(
|
|
|
|
|
f'距离上次执行已过去{int(c)}秒,本命令的冷却时间为150秒。(据官方人员所述,此API的调用十分昂贵,故手动做出这一限制,请谅解。)')
|
2022-01-19 17:02:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cytoid.handle('bind <username> {绑定一个Cytoid用户}')
|
2023-02-05 14:33:33 +00:00
|
|
|
|
async def _(msg: Bot.MessageSession):
|
2022-01-19 17:02:23 +00:00
|
|
|
|
code: str = msg.parsed_msg['<username>']
|
|
|
|
|
getcode = await get_profile_name(code)
|
|
|
|
|
if getcode:
|
|
|
|
|
bind = CytoidBindInfoManager(msg).set_bind_info(username=getcode[0])
|
|
|
|
|
if bind:
|
|
|
|
|
if getcode[1]:
|
|
|
|
|
m = f'{getcode[1]}({getcode[0]})'
|
|
|
|
|
else:
|
|
|
|
|
m = getcode[0]
|
2022-05-21 16:04:29 +00:00
|
|
|
|
await msg.finish(f'绑定成功:' + m)
|
2022-01-19 17:02:23 +00:00
|
|
|
|
else:
|
2022-05-21 16:04:29 +00:00
|
|
|
|
await msg.finish('绑定失败,请检查输入。')
|
2022-01-19 17:02:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cytoid.handle('unbind {取消绑定用户}')
|
2023-02-05 14:33:33 +00:00
|
|
|
|
async def _(msg: Bot.MessageSession):
|
2022-01-19 17:02:23 +00:00
|
|
|
|
unbind = CytoidBindInfoManager(msg).remove_bind_info()
|
|
|
|
|
if unbind:
|
2022-05-21 16:04:29 +00:00
|
|
|
|
await msg.finish('取消绑定成功。')
|
2022-08-17 08:21:59 +00:00
|
|
|
|
else:
|
|
|
|
|
await msg.finish('未绑定用户。')
|