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
2021-02-02 21:43:01 +08:00

44 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
from graia.application import MessageChain
from graia.application.message.elements.internal import Plain
from core.template import sendMessage
from .bugtracker import bug
async def bugtracker(kwargs: dict):
msg = kwargs['trigger_msg']
msg = re.sub('bug ', '', msg)
q = re.match(r'(.*)\-(.*)', msg)
if q:
result = await bug(q.group(1) + '-' + q.group(2))
msgchain = MessageChain.create([Plain(result)])
await sendMessage(kwargs, msgchain)
async def regex_bugtracker(kwargs: dict):
msg = kwargs[MessageChain].asDisplay()
if msg.find('[Webhook]') != -1:
return
if msg[0] == '!':
msg = re.sub('!', '', msg)
msg = re.sub('bug ', '', msg)
q = re.match(r'(.*)\-(.*)', msg)
if q:
result = await bug(q.group(1) + '-' + q.group(2))
msgchain = MessageChain.create([Plain(result)])
await sendMessage(kwargs, msgchain)
findlink = re.findall(r'(https://bugs.mojang.com/browse/.*?-\d*)', msg)
for link in findlink:
print(link)
matchbug = re.match(r'https://bugs.mojang.com/browse/(.*?-\d*)', link)
if matchbug:
await sendMessage(kwargs, await bug(matchbug.group(1)))
command = {'bug': bugtracker}
regex = {'bug_regex': regex_bugtracker}
help = {'bug': {'module': '查询Mojira上的漏洞编号。', 'help': '~bug <mojiraid> 查询Mojira上的漏洞编号。'},
'bug_regex': {'module': '正则自动查询Mojira上的漏洞编号。',
'help': '提示正则自动查询Mojira漏洞已开启所有消息开头为!<mojiraid>和来自Mojira的链接将会被自动查询并发送梗概内容。'}}