mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-25 08:38:59 +00:00
send status to users when they are added to a bot's learning list
This commit is contained in:
parent
d835604b16
commit
ded8fac097
3 changed files with 74 additions and 2 deletions
|
@ -2,7 +2,7 @@ from flask import session, render_template, request, redirect
|
|||
import requests
|
||||
from mastodon import Mastodon
|
||||
|
||||
def bot_accounts_add(mysql):
|
||||
def bot_accounts_add(mysql, cfg):
|
||||
if request.method == 'POST':
|
||||
if session['step'] == 1:
|
||||
if request.form['account'] == session['bot']:
|
||||
|
@ -79,6 +79,27 @@ def bot_accounts_add(mysql):
|
|||
c.execute("INSERT INTO `bot_learned_accounts` (`bot_id`, `fedi_id`) VALUES (%s, %s)", (session['bot'], request.form['account']))
|
||||
c.close()
|
||||
mysql.connection.commit()
|
||||
|
||||
if 'account' in cfg:
|
||||
client = Mastodon(
|
||||
cfg['account']['client_id'],
|
||||
cfg['account']['client_secret'],
|
||||
cfg['account']['secret'],
|
||||
"https://{}".format(cfg['account']['instance'])
|
||||
)
|
||||
status = """
|
||||
Hi, {user}. Someone has created a FediBooks bot that learns from your posts. The bot's username is {bot}. Your public posts are now being downloaded and stored for use by this bot.
|
||||
If you do not want {bot} to learn from your posts, click here: {overview}
|
||||
If you want to ensure that nobody can use {home} to create bots that use your post history, click here: {blacklist}
|
||||
""".format(
|
||||
user = request.form['account'],
|
||||
bot = session['bot'].replace("@", "@\u200B"),
|
||||
overview = "{}/overview/{}".format(cfg['base_uri'], request.form['account']),
|
||||
blacklist = "{}/blacklist".format(cfg['base_uri']),
|
||||
home = cfg['base_uri']
|
||||
)
|
||||
|
||||
client.status_post(status)
|
||||
return redirect("/bot/accounts/{}".format(session['bot']), 303)
|
||||
else:
|
||||
error = "Couldn't access ActivityPub outbox. {} may require authenticated fetches, which FediBooks doesn't support yet.".format(instance)
|
||||
|
|
51
app/setup.py
Executable file
51
app/setup.py
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from mastodon import Mastodon
|
||||
import json
|
||||
|
||||
cfg = json.load(open("config.json"))
|
||||
|
||||
scopes = ["write:statuses"]
|
||||
|
||||
print("FediBooks needs access to an account to notify users when they've been added to bots.")
|
||||
print("What instance would you like FediBooks' account to be on?")
|
||||
instance = input("https://")
|
||||
client_id, client_secret = Mastodon.create_app(
|
||||
"FediBooks",
|
||||
api_base_url="https://{}".format(instance),
|
||||
scopes=scopes,
|
||||
website=cfg['base_uri']
|
||||
)
|
||||
|
||||
client = Mastodon(
|
||||
client_id=client_id,
|
||||
client_secret=client_secret,
|
||||
api_base_url="https://{}".format(instance)
|
||||
)
|
||||
|
||||
url = client.auth_request_url(
|
||||
client_id=client_id,
|
||||
scopes=scopes
|
||||
)
|
||||
print("Create an account on {}, then click this link to give FediBooks access to the account: {}".format(instance, url))
|
||||
print("Authorise FediBooks to access the account, then paste the code below.")
|
||||
code = input("Code: ")
|
||||
|
||||
print("Authenticating...")
|
||||
|
||||
secret = client.log_in(
|
||||
code = code,
|
||||
scopes=scopes
|
||||
)
|
||||
client.status_post("FediBooks has successfully been set up to use this account.")
|
||||
|
||||
cfg['account'] = {
|
||||
'client_id': client_id,
|
||||
'client_secret': client_secret,
|
||||
'secret': secret,
|
||||
'instance': instance
|
||||
}
|
||||
|
||||
json.dump(cfg, open('config.json', 'w'))
|
||||
|
||||
print("Done! Thanks for using FediBooks!")
|
|
@ -127,7 +127,7 @@ def bot_accounts(id):
|
|||
|
||||
@app.route("/bot/accounts/add", methods = ['GET', 'POST'])
|
||||
def render_bot_accounts_add():
|
||||
return bot_accounts_add(mysql)
|
||||
return bot_accounts_add(mysql, cfg)
|
||||
|
||||
@app.route("/bot/accounts/toggle/<id>")
|
||||
def bot_accounts_toggle(id):
|
||||
|
|
Loading…
Reference in a new issue