summaryrefslogtreecommitdiff
path: root/ATRI/plugins/github.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-03-07 15:24:17 +0800
committerKyomotoi <[email protected]>2021-03-07 15:24:17 +0800
commitda888ff020805a38a17e5f83705aeb42ffa992ba (patch)
tree28fa5cc06c3b77970ced9136f12ed2bd94436926 /ATRI/plugins/github.py
parent51624483cb23e8922cbdf5f529e1dcb2342333a7 (diff)
downloadATRI-da888ff020805a38a17e5f83705aeb42ffa992ba.tar.gz
ATRI-da888ff020805a38a17e5f83705aeb42ffa992ba.tar.bz2
ATRI-da888ff020805a38a17e5f83705aeb42ffa992ba.zip
♻️⚡️ 重构 Service,优化部分代码
Diffstat (limited to 'ATRI/plugins/github.py')
-rw-r--r--ATRI/plugins/github.py62
1 files changed, 62 insertions, 0 deletions
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
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:11:56 pm
+Modified By: Kyomotoi ([email protected])
+--------
+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)