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/github/repo.py

64 lines
2.3 KiB
Python
Raw Normal View History

2021-07-30 08:06:10 +00:00
import traceback
from core.elements import MessageSession, Image, Plain
from modules.github.utils import query, time_diff, dirty_check, darkCheck
async def repo(msg: MessageSession):
try:
2021-08-01 14:26:55 +00:00
result = await query('https://api.github.com/repos/' + msg.parsed_msg['<name>'], 'json')
2021-07-30 08:06:10 +00:00
if 'message' in result and result['message'] == 'Not Found':
raise RuntimeError('此仓库不存在。')
elif 'message' in result and result['message']:
raise RuntimeError(result['message'])
rlicense = 'Unknown'
if 'license' in result and result['license'] is not None:
if 'spdx_id' in result['license']:
rlicense = result['license']['spdx_id']
is_fork = result['fork']
parent = False
if result['homepage'] is not None:
website = 'Website: ' + result['homepage'] + '\n'
else:
website = ''
if result['mirror_url'] is not None:
mirror = f' (This is a mirror of {result["mirror_url"]} )'
else:
mirror = ''
if is_fork:
parent_name = result['parent']['name']
parent = f' (This is a fork of {parent_name} )'
desc = result['description']
if desc is None:
desc = ''
else:
desc = '\n' + result['description']
2021-08-01 14:26:55 +00:00
message = f'''{result['full_name']} ({result['id']}){desc}
2021-07-30 08:06:10 +00:00
Language · {result['language']} | Fork · {result['forks_count']} | Star · {result['stargazers_count']} | Watch · {result['watchers_count']}
License: {rlicense}
Created {time_diff(result['created_at'])} ago | Updated {time_diff(result['updated_at'])} ago
{website}{result['html_url']}'''
if mirror:
2021-08-01 14:26:55 +00:00
message += '\n' + mirror
2021-07-30 08:06:10 +00:00
if parent:
2021-08-01 14:26:55 +00:00
message += '\n' + parent
2021-07-30 08:06:10 +00:00
2021-08-01 14:26:55 +00:00
is_dirty = await dirty_check(message, result['owner']['login']) or darkCheck(message)
2021-07-30 08:06:10 +00:00
if is_dirty:
2021-08-01 14:26:55 +00:00
message = 'https://wdf.ink/6OUp'
await msg.sendMessage([Plain(message)])
2021-07-30 08:06:10 +00:00
else:
2021-08-01 14:26:55 +00:00
await msg.sendMessage([Plain(message), Image(path=f'https://opengraph.githubassets.com/c9f4179f4d560950b2355c82aa2b7750bffd945744f9b8ea3f93cc24779745a0/{result["full_name"]}')])
2021-07-30 08:06:10 +00:00
except Exception as e:
await msg.sendMessage('发生错误:' + str(e))
traceback.print_exc()