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/bugtracker/__init__.py

41 lines
1.3 KiB
Python
Raw Normal View History

2022-09-03 16:37:20 +00:00
import asyncio
2021-07-27 16:03:48 +00:00
import re
2022-06-28 06:11:03 +00:00
from core.builtins.message import MessageSession
2021-10-24 10:55:45 +00:00
from core.component import on_command, on_regex
2021-08-02 03:00:18 +00:00
from .bugtracker import bugtracker_get
2021-07-27 16:03:48 +00:00
2021-10-24 10:55:45 +00:00
bug = on_command('bug', alias='b', developers=['OasisAkari'])
2021-07-27 16:03:48 +00:00
2021-10-24 10:55:45 +00:00
@bug.handle('<MojiraID> {查询Mojira上的漏洞编号内容}')
2021-07-27 16:03:48 +00:00
async def bugtracker(msg: MessageSession):
mojira_id = msg.parsed_msg['<MojiraID>']
if mojira_id:
q = re.match(r'(.*-.*)', mojira_id)
if q:
result = await bugtracker_get(q.group(1))
2022-05-21 16:04:29 +00:00
await msg.finish(result)
2021-07-27 16:03:48 +00:00
2021-10-24 10:55:45 +00:00
rbug = on_regex('bug_regex',
2022-01-20 10:37:27 +00:00
desc='开启后发送 !<mojiraid> 将会查询Mojira并发送该bug的梗概内容。',
2021-10-24 10:55:45 +00:00
developers=['OasisAkari'])
@rbug.handle(pattern=r'^\!(?:bug |)(.*)-(.*)', mode='M')
2021-07-27 16:03:48 +00:00
async def regex_bugtracker(msg: MessageSession):
2021-11-20 16:03:32 +00:00
matched_msg = msg.matched_msg
if len(matched_msg.group(1)) < 10 and len(matched_msg.group(2)) < 10:
result = await bugtracker_get(matched_msg.group(1) + '-' + matched_msg.group(2))
2022-05-21 16:04:29 +00:00
await msg.finish(result)
2022-09-03 16:37:20 +00:00
@rbug.handle(re.compile(r'https://bugs\.mojang\.com/browse/(.*?-\d*)'), mode='A')
async def _(msg: MessageSession):
async def bgtask(msg: MessageSession):
for title in msg.matched_msg:
await msg.sendMessage(await bugtracker_get(title, nolink=True))
2023-01-28 05:53:11 +00:00
2022-09-03 16:37:20 +00:00
asyncio.create_task(bgtask(msg))