Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/cytoid/__init__.py

75 lines
2.5 KiB
Python
Raw Normal View History

2023-02-05 14:33:33 +00:00
from core.builtins import Bot
from core.builtins import Image
2023-03-04 08:51:56 +00:00
from core.component import module
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
from .utils import get_profile_name
2021-07-27 17:42:47 +00:00
2023-03-04 08:51:56 +00:00
cytoid = module('cytoid',
2023-04-30 03:30:59 +00:00
developers=['OasisAkari'], alias='ctd')
2021-07-27 17:42:47 +00:00
2021-10-24 10:55:45 +00:00
2023-05-19 04:46:29 +00:00
@cytoid.handle('profile [<UserID>] {{cytoid.help.profile}}')
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
2023-05-19 04:46:29 +00:00
@cytoid.handle('(b30|r30) [<UserID>] {{cytoid.help.b30}}')
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)
if pat:
query_id = pat
else:
query_id = CytoidBindInfoManager(msg).get_bind_username()
if query_id is None:
2023-05-22 13:44:16 +00:00
await msg.finish(msg.locale.t('cytoid.message.user.unbound', prefix=msg.prefixes[0]))
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:
2023-05-21 09:44:07 +00:00
img = await get_rating(query_id, query, msg)
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-05-19 04:46:29 +00:00
await msg.sendMessage(msg.locale.t('cytoid.message.b30.cooldown', time=int(c)))
2023-05-19 04:46:29 +00:00
@cytoid.handle('bind <username> {{cytoid.help.bind}}')
2023-02-05 14:33:33 +00:00
async def _(msg: Bot.MessageSession):
2023-05-21 13:43:00 +00:00
code: str = msg.parsed_msg['<username>'].lower()
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]
2023-05-19 04:46:29 +00:00
await msg.finish(msg.locale.t('cytoid.message.bind.success') + m)
else:
2023-05-19 04:46:29 +00:00
await msg.finish(msg.locale.t('cytoid.message.bind.failed'))
2023-05-19 04:46:29 +00:00
@cytoid.handle('unbind {{cytoid.help.unbind}}')
2023-02-05 14:33:33 +00:00
async def _(msg: Bot.MessageSession):
unbind = CytoidBindInfoManager(msg).remove_bind_info()
if unbind:
2023-05-19 04:46:29 +00:00
await msg.finish(msg.locale.t('cytoid.message.unbind.success'))