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/bug/bugtracker.py
2020-08-27 20:52:41 +08:00

87 lines
4.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.

# -*- coding:utf-8 -*-
import aiohttp
import json
from xml.etree import ElementTree
async def bug(pagename):
try:
url_str = 'https://bugs.mojang.com/si/jira.issueviews:issue-xml/' + str.upper(pagename) + '/' + str.upper(
pagename) + '.xml'
async with aiohttp.ClientSession() as session:
async with session.get(url_str, timeout=aiohttp.ClientTimeout(total=20)) as req:
if req.status != 200:
return f"请求时发生错误:{req.status}"
else:
respose_str = await req.text()
try:
root = ElementTree.XML(respose_str)
for node in root.iter("channel"):
for node in root.iter("item"):
Title = node.find("title").text
Type = "Type: " + node.find("type").text
Project = "Project: " + node.find("project").text
TStatus = "Status: " + node.find("status").text
Resolution = "Resolution: " + node.find("resolution").text
Link = node.find("link").text
url_json = 'https://bugs.mojang.com/rest/api/2/issue/' + str.upper(pagename)
async with aiohttp.ClientSession() as session2:
async with session2.get(url_json, timeout=aiohttp.ClientTimeout(total=5)) as reqjson:
if reqjson.status != 200:
return f"请求时发生错误:{reqjson.status}"
else:
json_text = await reqjson.text()
file = json.loads(json_text)
Versions = file['fields']['versions']
name = []
for item in Versions[:]:
name.append(item['name'])
if name[0] == name[-1]:
Version = "Version: " + name[0]
else:
Version = "Versions: " + name[0] + " ~ " + name[-1]
try:
Priority = "Mojang Priority: " + file['fields']['customfield_12200']['value']
if TStatus == 'Status: Open':
Type = "Type: " + node.find("type").text + ' | Status: ' + node.find("status").text
return (
Title + '\n' + Type + '\n' + Project + '\n' + Priority + '\n' + Resolution + '\n' + Version + '\n' + Link)
elif TStatus == 'Status: Resolved':
Resolution = "Resolution: " + node.find("resolution").text + ' | Fixed Version: ' + node.find(
"fixVersion").text
Type = Type + ' | ' + TStatus
return (
Title + '\n' + Type + '\n' + Project + '\n' + Resolution + '\n' + Priority + '\n' + Version + '\n' + Link)
else:
return (
Title + '\n' + Type + '\n' + Project + '\n' + TStatus + '\n' + Priority + '\n' + Resolution + '\n' + Version + '\n' + Link)
except Exception:
try:
if TStatus == 'Status: Open':
Type = "Type: " + node.find("type").text + ' | Status: ' + node.find("status").text
return (Title + '\n' + Type + '\n' + Project + '\n' + Resolution + '\n' + Version + '\n' + Link)
elif TStatus == 'Status: Resolved':
Resolution = "Resolution: " + node.find("resolution").text + ' | Fixed Version: ' + node.find(
"fixVersion").text
Type = Type + ' | ' + TStatus
return (Title + '\n' + Type + '\n' + Project + '\n' + Resolution + '\n' + Version + '\n' + Link)
else:
return (
Title + '\n' + Type + '\n' + Project + '\n' + TStatus + '\n' + Resolution + '\n' + Version + '\n' + Link)
except Exception:
return (
Title + '\n' + Type + '\n' + Project + '\n' + TStatus + '\n' + Resolution + '\n' + Version + '\n' + Link)
except Exception:
try:
return (
Title + '\n' + Type + '\n' + Project + '\n' + TStatus + '\n' + Priority + '\n' + Resolution + '\n' + Link)
except Exception:
try:
return (Title + '\n' + Type + '\n' + Project + '\n' + TStatus + '\n' + Resolution + '\n' + Link)
except Exception:
try:
return (Link)
except Exception as e:
return ("发生错误此漏洞可能不存在以下为traceback\n" + str(e) + ".")
except Exception as e:
return ("发生错误:" + str(e) + ".")