From b3d09b505f016bc092b5619832cb95eb05979a4c Mon Sep 17 00:00:00 2001 From: Tdxdxoz Date: Tue, 18 Aug 2020 12:15:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=88=E6=9D=83=E7=99=BB?= =?UTF-8?q?=E9=99=86=E6=96=B9=E5=BC=8F=E5=88=9B=E5=BB=BA=E6=8F=90=E9=97=AE?= =?UTF-8?q?=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ask.py | 39 ++++++++++++++++++++++++++++++++++++++- static/ask.html | 17 ++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/ask.py b/ask.py index 6979ebe..baaa7ea 100644 --- a/ask.py +++ b/ask.py @@ -7,11 +7,17 @@ import re, random, string, datetime import html2text BOT_NAME = '@ask_me_bot' +CLIENT_ID = 'WQHzKKvfahkkcFm_iErT6ZdYvczi8L6Uunsoa88bCKA' +CLIENT_SEC = open('client.secret', 'r').read().strip() + DOMAIN = 'thu.closed.social' WORK_URL = 'https://closed.social' +#WORK_URL = 'http://127.0.0.1:5000' + +REDIRECT_URI = WORK_URL + '/askMe/auth' -token = open('token.secret','r').read().strip('\n') +token = open('token.secret','r').read().strip() th = Mastodon( access_token = token, api_base_url = 'https://' + DOMAIN @@ -79,6 +85,37 @@ def root(): def root_footer(): return app.send_static_file('footer.html') + +@app.route('/askMe/auth') +@limiter.limit("10 / minute") +def set_inbox_auth(): + code = request.args.get('code') + + client = Mastodon( + client_id = CLIENT_ID, + client_secret = CLIENT_SEC, + api_base_url = 'https://' + DOMAIN + ) + token = client.log_in(code=code, redirect_uri=REDIRECT_URI, scopes=['read', 'write']) + + info = client.account_verify_credentials() + + acct = info.acct + u = User.query.filter_by(acct=acct).first() + if not u: + u = User(acct) + u.secr = ''.join(random.choice(string.ascii_lowercase) for i in range(16)) + db.session.add(u) + + u.disp = info.display_name + u.url = info.url + u.avat = info.avatar + db.session.commit() + + client.status_post(f"[自动发送] 我创建了一个匿名提问箱,欢迎提问~\n{WORK_URL}/askMe/{acct}/{u.secr}", visibility='public') + + return redirect(f"/askMe/{acct}/{u.secr}") + @app.route('/askMe/inbox', methods=['POST']) @limiter.limit("10 / minute") def set_inbox(): diff --git a/static/ask.html b/static/ask.html index e150b0b..020f3f7 100644 --- a/static/ask.html +++ b/static/ask.html @@ -71,7 +71,9 @@
-
+

选择任意一种方式创建提问箱

+
+
私信bot认证

输入闭社id并前往闭社私信 @ask_me_bot “新建”,然后点击下方按钮,即可新建或重置提问箱。 @@ -92,6 +94,19 @@

+ +
+
授权登陆认证
+

不会重置已有的链接 自动发布一条公开嘟文

+
授权登陆 + +