mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-25 16:48:58 +00:00
Compare commits
3 commits
382ef00f85
...
ea8e46c07c
Author | SHA1 | Date | |
---|---|---|---|
ea8e46c07c | |||
129a7a78f8 | |||
30ccd37505 |
2 changed files with 15 additions and 7 deletions
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
{% elif session['step'] == 2 %}
|
{% elif session['step'] == 2 %}
|
||||||
<h2 class="thin centred">Detected instance type: {{ session['instance_type'] }}</h2>
|
<h2 class="thin centred">Detected instance type: {{ session['instance_type'] }}</h2>
|
||||||
<p>{{ session['instance'] }} is a {{ session['instance_type'] }} instance. {% if session['instance_type'] == 'Pleroma' %}Unfortunately, bots on Pleroma instances cannot listen for replies yet. This means that your bot will have its reply functionality disabled.{% else %}{{ session['instance_type'] }} instances are fully supported, and your bot will have all functionality available.{% endif %}</p>
|
<p>{{ session['instance'] }} is a {{ session['instance_type'] }} instance. {% if session['instance_type'] == 'Pleroma' %}Pleroma's support for the Mastodon API is incomplete, and some functions may not work correctly. Additionally, FediBooks will need to request full read and write access to your account, as Pleroma does not support fine-grained app permissions.{% else %}{{ session['instance_type'] }} instances are fully supported, and your bot will have all functionality available.{% endif %}</p>
|
||||||
|
|
||||||
{% elif session['step'] == 3 %}
|
{% elif session['step'] == 3 %}
|
||||||
<p>You now need to give your bot access to the {{ session['instance'] }} account you have created for it. If you have not yet created an account on {{ session['instance'] }} for your bot to use, please do so now.</p>
|
<p>You now need to give your bot access to the {{ session['instance'] }} account you have created for it. If you have not yet created an account on {{ session['instance'] }} for your bot to use, please do so now.</p>
|
||||||
|
|
20
webui.py
20
webui.py
|
@ -20,6 +20,7 @@ app.config['MYSQL_PASSWORD'] = cfg['db_pass']
|
||||||
mysql = MySQL(app)
|
mysql = MySQL(app)
|
||||||
|
|
||||||
scopes = ['write:statuses', 'write:accounts', 'read:accounts', 'read:notifications', 'read:statuses', 'push']
|
scopes = ['write:statuses', 'write:accounts', 'read:accounts', 'read:notifications', 'read:statuses', 'push']
|
||||||
|
scopes_pleroma = ['read', 'write', 'push']
|
||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def login_check():
|
def login_check():
|
||||||
|
@ -36,7 +37,8 @@ def home():
|
||||||
bot_count = c.fetchone()[0]
|
bot_count = c.fetchone()[0]
|
||||||
active_count = None
|
active_count = None
|
||||||
bots = {}
|
bots = {}
|
||||||
bot_users = None
|
bot_users = {}
|
||||||
|
next_posts = {}
|
||||||
|
|
||||||
if bot_count > 0:
|
if bot_count > 0:
|
||||||
c.execute("SELECT COUNT(*) FROM `bots` WHERE user_id = %s AND enabled = TRUE", (session['user_id'],))
|
c.execute("SELECT COUNT(*) FROM `bots` WHERE user_id = %s AND enabled = TRUE", (session['user_id'],))
|
||||||
|
@ -45,8 +47,6 @@ def home():
|
||||||
dc.execute("SELECT `handle`, `enabled`, `last_post`, `post_frequency` FROM `bots` WHERE user_id = %s", (session['user_id'],))
|
dc.execute("SELECT `handle`, `enabled`, `last_post`, `post_frequency` FROM `bots` WHERE user_id = %s", (session['user_id'],))
|
||||||
bots = dc.fetchall()
|
bots = dc.fetchall()
|
||||||
dc.close()
|
dc.close()
|
||||||
bot_users = {}
|
|
||||||
next_posts = {}
|
|
||||||
|
|
||||||
for bot in bots:
|
for bot in bots:
|
||||||
# multiple SELECTS is slow, maybe SELECT all at once and filter with python?
|
# multiple SELECTS is slow, maybe SELECT all at once and filter with python?
|
||||||
|
@ -422,7 +422,7 @@ def bot_create():
|
||||||
session['client_id'], session['client_secret'] = Mastodon.create_app(
|
session['client_id'], session['client_secret'] = Mastodon.create_app(
|
||||||
"FediBooks",
|
"FediBooks",
|
||||||
api_base_url="https://{}".format(session['instance']),
|
api_base_url="https://{}".format(session['instance']),
|
||||||
scopes=scopes,
|
scopes=scopes if session['instance_type'] == 'Mastodon' else scopes_pleroma,
|
||||||
redirect_uris=[redirect_uri],
|
redirect_uris=[redirect_uri],
|
||||||
website=cfg['base_uri']
|
website=cfg['base_uri']
|
||||||
)
|
)
|
||||||
|
@ -433,7 +433,11 @@ def bot_create():
|
||||||
api_base_url="https://{}".format(session['instance'])
|
api_base_url="https://{}".format(session['instance'])
|
||||||
)
|
)
|
||||||
|
|
||||||
url = client.auth_request_url(client_id=session['client_id'], redirect_uris=redirect_uri, scopes=scopes)
|
url = client.auth_request_url(
|
||||||
|
client_id=session['client_id'],
|
||||||
|
redirect_uris=redirect_uri,
|
||||||
|
scopes=scopes if session['instance_type'] == 'Mastodon' else scopes_pleroma
|
||||||
|
)
|
||||||
return redirect(url, code=303)
|
return redirect(url, code=303)
|
||||||
|
|
||||||
elif session['instance_type'] == 'Misskey':
|
elif session['instance_type'] == 'Misskey':
|
||||||
|
@ -453,7 +457,11 @@ def bot_create():
|
||||||
try:
|
try:
|
||||||
# test authentication
|
# test authentication
|
||||||
client = Mastodon(client_id=session['client_id'], client_secret=session['client_secret'], api_base_url=session['instance'])
|
client = Mastodon(client_id=session['client_id'], client_secret=session['client_secret'], api_base_url=session['instance'])
|
||||||
session['secret'] = client.log_in(code = session['code'], scopes=scopes, redirect_uri='{}/do/authenticate_bot'.format(cfg['base_uri']))
|
session['secret'] = client.log_in(
|
||||||
|
code = session['code'],
|
||||||
|
scopes=scopes if session['instance_type'] == 'Mastodon' else scopes_pleroma,
|
||||||
|
redirect_uri='{}/do/authenticate_bot'.format(cfg['base_uri'])
|
||||||
|
)
|
||||||
username = client.account_verify_credentials()['username']
|
username = client.account_verify_credentials()['username']
|
||||||
handle = "@{}@{}".format(username, session['instance'])
|
handle = "@{}@{}".format(username, session['instance'])
|
||||||
except:
|
except:
|
||||||
|
|
Loading…
Reference in a new issue