From da888ff020805a38a17e5f83705aeb42ffa992ba Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Sun, 7 Mar 2021 15:24:17 +0800 Subject: =?UTF-8?q?=E2=99=BB=EF=B8=8F=E2=9A=A1=EF=B8=8F=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=20Service=EF=BC=8C=E4=BC=98=E5=8C=96=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/github.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 ATRI/plugins/github.py (limited to 'ATRI/plugins/github.py') diff --git a/ATRI/plugins/github.py b/ATRI/plugins/github.py new file mode 100644 index 0000000..118d6f5 --- /dev/null +++ b/ATRI/plugins/github.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +# -*- coding:utf-8 -*- +''' +File: github.py +Created Date: 2021-02-26 23:22:34 +Author: Kyomotoi +Email: Kyomotoiowo@gmail.com +License: GPLv3 +Project: https://github.com/Kyomotoi/ATRI +-------- +Last Modified: Sunday, 7th March 2021 3:11:56 pm +Modified By: Kyomotoi (kyomotoiowo@gmail.com) +-------- +Copyright (c) 2021 Kyomotoi +''' + +import re +import json + +from nonebot.plugin import on_message +from nonebot.adapters.cqhttp import Bot, MessageEvent + +from ATRI.rule import is_in_banlist, is_in_dormant +from ATRI.utils.request import get_bytes +from ATRI.exceptions import RequestTimeOut + + +URL = "https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}" + + +github_issues = on_message(rule=is_in_banlist() & is_in_dormant()) + +@github_issues.handle() +async def _github_issues(bot: Bot, event: MessageEvent) -> None: + msg = str(event.message) + patt = r"https://github.com/(.*)/(.*)/issues/(.*)" + need_info = re.findall(patt, msg) + if not need_info: + return + + for i in need_info: + need_info = list(i) + owner = need_info[0] + repo = need_info[1] + issue_number = need_info[2] + url = URL.format(owner=owner, + repo=repo, + issue_number=issue_number) + + try: + data = await get_bytes(url) + except RequestTimeOut: + return + + data = json.loads(data) + msg0 = ( + f"{repo}: #{issue_number} {data['state']}\n" + f"comments: {data['comments']}\n" + f"update: {data['updated_at']}\n" + f"{data['body']}" + ) + await github_issues.finish(msg0) -- cgit v1.2.3