1
0
Fork 0
mirror of https://github.com/Lynnesbian/FediBooks/ synced 2024-11-25 16:48:58 +00:00

Compare commits

..

No commits in common. "798b5a484b56714eea71c50a3c368eaf29817e87" and "d835604b16c07eebadf5e8a5a741e752c5334a93" have entirely different histories.

4 changed files with 11 additions and 84 deletions

View file

@ -95,14 +95,14 @@ def make_post(args):
print("No posts to learn from.")
return
if bot['fake_mentions'] == 'never':
# remove all mentions from the training data before the markov model sees it
posts = re.sub(r"(?<!\S)@\w+(@[\w.]+)?\s?", "", posts)
model = nlt_fixed(posts)
tries = 0
post = None
if bot['fake_mentions'] == 'never':
# remove all mentions from the training data before the markov model sees it
posts = re.sub(r"(?<!\S)@\w+(@[\w.]+)?\s?", "", posts)
# even with such a high tries value for markovify, it still sometimes returns none.
# so we implement our own tries function as well, and try ten times.
while post is None and tries < 10:

View file

@ -1,9 +1,8 @@
from flask import session, render_template, request, redirect
import requests
from mastodon import Mastodon
import re
def bot_accounts_add(mysql, cfg):
def bot_accounts_add(mysql):
if request.method == 'POST':
if session['step'] == 1:
if request.form['account'] == session['bot']:
@ -80,27 +79,6 @@ def bot_accounts_add(mysql, cfg):
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)

View file

@ -1,51 +0,0 @@
#!/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!")

View file

@ -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, cfg)
return bot_accounts_add(mysql)
@app.route("/bot/accounts/toggle/<id>")
def bot_accounts_toggle(id):
@ -163,13 +163,13 @@ def render_bot_create():
@app.route("/bot/create/back")
def bot_create_back():
session['step'] -= 1
return redirect(url_for("render_bot_create"), 303)
return redirect(url_for("bot_create"), 303)
@app.route("/do/authenticate_bot")
def do_authenticate_bot():
session['code'] = request.args.get('code')
session['step'] = 4
return redirect(url_for("render_bot_create"), 303)
return redirect(url_for("bot_create"), 303)
@app.route("/push/<id>", methods = ['POST'])
def push(id):
@ -246,12 +246,12 @@ def do_signup():
# success!
session['user_id'] = user_id
return redirect(url_for('render_home'))
return redirect(url_for('home'))
@app.route("/do/signout")
def do_signout():
session.clear()
return redirect(url_for("render_home"))
return redirect(url_for("home"))
@app.route("/do/login", methods=['POST'])
def do_login():
@ -266,7 +266,7 @@ def do_login():
if bcrypt.checkpw(pw_hashed, data['password']):
session['user_id'] = data['id']
return redirect(url_for("render_home"))
return redirect(url_for("home"))
else:
session['error'] = "Incorrect login information."