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

73 lines
2.5 KiB
Python
Raw Normal View History

2022-08-31 04:06:01 +00:00
import asyncio
2021-07-30 08:06:10 +00:00
import traceback
2023-02-05 14:33:33 +00:00
from core.builtins import Bot
from core.builtins import Image, Plain, Url, ErrorMessage
from core.utils.http import get_url, download_to_cache
2023-07-14 07:59:01 +00:00
from core.dirty_check import rickroll
2021-11-20 01:35:38 +00:00
from modules.github.utils import time_diff, dirty_check, darkCheck
2021-07-30 08:06:10 +00:00
2021-08-07 07:56:48 +00:00
2023-02-05 14:33:33 +00:00
async def repo(msg: Bot.MessageSession):
2021-07-30 08:06:10 +00:00
try:
2022-08-10 13:22:44 +00:00
result = await get_url('https://api.github.com/repos/' + msg.parsed_msg['<name>'], 200, fmt='json')
2021-07-30 08:06:10 +00:00
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:
2022-01-17 13:28:49 +00:00
website = 'Website: ' + str(Url(result['homepage'])) + '\n'
2021-07-30 08:06:10 +00:00
else:
website = ''
if result['mirror_url'] is not None:
2022-01-17 13:28:49 +00:00
mirror = f' (This is a mirror of {str(Url(result["mirror_url"]))} )'
2021-07-30 08:06:10 +00:00
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
2022-01-17 13:28:49 +00:00
{website}{str(Url(result['html_url']))}'''
2021-07-30 08:06:10 +00:00
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:
2023-07-27 19:31:53 +00:00
rickroll(msg)
2021-07-30 08:06:10 +00:00
else:
2022-08-18 18:22:00 +00:00
await msg.sendMessage([Plain(message)])
2022-08-31 04:06:01 +00:00
async def download():
2023-01-28 05:53:11 +00:00
download_pic = await download_to_cache(
f'https://opengraph.githubassets.com/c9f4179f4d560950b2355c82aa2b7750bffd945744f9b8ea3f93cc24779745a0/{result["full_name"]}')
2022-08-31 04:06:01 +00:00
if download_pic:
await msg.finish([Image(download_pic)])
asyncio.create_task(download())
except ValueError as e:
if str(e).startswith('404'):
await msg.finish(msg.locale.t("github.message.repo.not_found"))
2022-08-10 13:22:44 +00:00
traceback.print_exc()