mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-25 16:48:58 +00:00
Compare commits
4 commits
a9fcda794c
...
6b8931ec3d
Author | SHA1 | Date | |
---|---|---|---|
6b8931ec3d | |||
ad1b59a401 | |||
ac9ea67edb | |||
7ee4042592 |
4 changed files with 47 additions and 13 deletions
16
functions.py
16
functions.py
|
@ -64,12 +64,8 @@ def make_post(args):
|
||||||
FROM
|
FROM
|
||||||
bots, credentials
|
bots, credentials
|
||||||
WHERE
|
WHERE
|
||||||
bots.credentials_id = (SELECT
|
bots.handle = %s
|
||||||
credentials_id
|
AND bots.credentials_id = credentials.id
|
||||||
FROM
|
|
||||||
bots
|
|
||||||
WHERE
|
|
||||||
handle = %s)
|
|
||||||
""", (handle,))
|
""", (handle,))
|
||||||
|
|
||||||
bot = dc.fetchone()
|
bot = dc.fetchone()
|
||||||
|
@ -105,7 +101,7 @@ def make_post(args):
|
||||||
|
|
||||||
if bot['fake_mentions'] == 'never':
|
if bot['fake_mentions'] == 'never':
|
||||||
# remove all mentions from the training data before the markov model sees it
|
# remove all mentions from the training data before the markov model sees it
|
||||||
posts = re.sub(r"@(\w+)@([\w.]+)\s?", "", posts)
|
posts = re.sub(r"(?<!\S)@\w+(@[\w.]+)?\s?", "", posts)
|
||||||
|
|
||||||
# even with such a high tries value for markovify, it still sometimes returns none.
|
# 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.
|
# so we implement our own tries function as well, and try ten times.
|
||||||
|
@ -123,12 +119,14 @@ def make_post(args):
|
||||||
zws = "\u200B"
|
zws = "\u200B"
|
||||||
if bot['fake_mentions'] == 'middle':
|
if bot['fake_mentions'] == 'middle':
|
||||||
# remove mentions at the start of a post
|
# remove mentions at the start of a post
|
||||||
post = re.sub(r"^(@\w+@[\w.]+\s*)+", "", post)
|
post = re.sub(r"^(@\w+(@[\w.]+)?\s*)+", "", post)
|
||||||
# TODO: does this regex catch all valid handles?
|
# TODO: does this regex catch all valid handles?
|
||||||
if bot['fake_mentions_full']:
|
if bot['fake_mentions_full']:
|
||||||
post = re.sub(r"@(\w+)@([\w.]+)", r"@{}\1@{}\2".format(zws, zws), post)
|
post = re.sub(r"@(\w+)@([\w.]+)", r"@{}\1@{}\2".format(zws, zws), post)
|
||||||
else:
|
else:
|
||||||
post = re.sub(r"@(\w+)@([\w.]+)", r"@{}\1".format(zws), post)
|
post = re.sub(r"@(\w+)@([\w.]+)", r"@{}\1".format(zws), post)
|
||||||
|
# also format handles without instances, e.g. @user instead of @user@instan.ce
|
||||||
|
post = re.sub(r"(?<!\S)@(\w+)", r"@{}\1".format(zws), post)
|
||||||
|
|
||||||
print(post)
|
print(post)
|
||||||
visibility = bot['post_privacy'] if len(args) == 1 else args[2]
|
visibility = bot['post_privacy'] if len(args) == 1 else args[2]
|
||||||
|
|
32
templates/help_settings.html
Normal file
32
templates/help_settings.html
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>FediBooks</title>
|
||||||
|
{% include 'imports.html' %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container light">
|
||||||
|
<h1 class='thin centred'>About the Settings menu</h1>
|
||||||
|
<p class="centred">
|
||||||
|
<a class="button btn-primary" href="/" role="button"><i class="fas fa-home"></i> Home</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<p>The settings menu allows you to change your account's email or password, as well as updating your contact information.</p>
|
||||||
|
<p>The email and password inputs allow you to change your account's email address or password respectively. If you don't edit these inputs, your login info will not be changed.</p>
|
||||||
|
<p>The contact settings menu allows you to specify when FediBooks should send you automated emails. There are four options for you to configure.</p>
|
||||||
|
<p>You can specify whether you'd like to be contacted <em>always</em>, <em>once</em>, or <em>never</em>. <em>Always</em> means you will be emailed every time this error occurs. <em>Once</em> means you will be emailed once if this occurs, and you won't be emailed again until you check FediBooks by viewing the home page. <em>Never</em> means you will never be emailed if this error occurs.</p>
|
||||||
|
<h2>When my bot(s) can't get new posts</h2>
|
||||||
|
<p>This error happens when your bot fails to download new posts from its followed accounts. This might happen because the instance is down, or when the admin changes authentication settings for the instance.</p>
|
||||||
|
<h2>When my bot(s) can't submit new posts</h2>
|
||||||
|
<p>This means that your bot was unable to post something. This might happen because the instance is down, or because you have revoked FediBooks' access to your bot from the Apps menu on your instance.</p>
|
||||||
|
<h2>When my bot(s) encounter an error generating new posts</h2>
|
||||||
|
<p>This happens when your bot is unable to generate a new post. This can happen when the database doesn't contain enough unique information for your bot to synthesise a new post. For example, if your bot only has one post to learn from, this will happen.</p>
|
||||||
|
<h2>When my bot(s) can't send replies</h2>
|
||||||
|
<p>This error occurs when your bot is unable to send a new reply. This generally happens for the same reason as submission errors.</p>
|
||||||
|
</div>
|
||||||
|
{% include 'footer.html' %}
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -75,7 +75,7 @@
|
||||||
<div class="container centred">
|
<div class="container centred">
|
||||||
<button class="button btn-primary"><i class="fas fa-save"></i> Save</button>
|
<button class="button btn-primary"><i class="fas fa-save"></i> Save</button>
|
||||||
<a href="/" class="button btn-secondary"><i class="fas fa-times"></i> Cancel</a>
|
<a href="/" class="button btn-secondary"><i class="fas fa-times"></i> Cancel</a>
|
||||||
<a href="#" class="button btn-secondary"><i class="fas fa-question"></i> Help</a>
|
<a href="/help/settings" target="_blank" class="button btn-secondary"><i class="fas fa-question"></i> Help</a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
10
webui.py
10
webui.py
|
@ -107,7 +107,7 @@ def settings():
|
||||||
session['error'] = "Password too short."
|
session['error'] = "Password too short."
|
||||||
return redirect(url_for("settings"), 303)
|
return redirect(url_for("settings"), 303)
|
||||||
|
|
||||||
pw_hashed = hashlib.sha256(request.form['password'].encode('utf-8')).digest()
|
pw_hashed = hashlib.sha256(request.form['password'].encode('utf-8')).digest().replace(b"\0", b"\1")
|
||||||
pw = bcrypt.hashpw(pw_hashed, bcrypt.gensalt(12))
|
pw = bcrypt.hashpw(pw_hashed, bcrypt.gensalt(12))
|
||||||
c.execute("UPDATE users SET password = %s WHERE id = %s", (pw, session['user_id']))
|
c.execute("UPDATE users SET password = %s WHERE id = %s", (pw, session['user_id']))
|
||||||
|
|
||||||
|
@ -575,7 +575,7 @@ def do_signup():
|
||||||
session['error'] = "Email address already in use."
|
session['error'] = "Email address already in use."
|
||||||
return redirect(url_for("show_signup_page"), 303)
|
return redirect(url_for("show_signup_page"), 303)
|
||||||
|
|
||||||
pw_hashed = hashlib.sha256(request.form['password'].encode('utf-8')).digest()
|
pw_hashed = hashlib.sha256(request.form['password'].encode('utf-8')).digest().replace(b"\0", b"\1")
|
||||||
pw = bcrypt.hashpw(pw_hashed, bcrypt.gensalt(12))
|
pw = bcrypt.hashpw(pw_hashed, bcrypt.gensalt(12))
|
||||||
|
|
||||||
# try to sign up
|
# try to sign up
|
||||||
|
@ -595,7 +595,7 @@ def do_signout():
|
||||||
|
|
||||||
@app.route("/do/login", methods=['POST'])
|
@app.route("/do/login", methods=['POST'])
|
||||||
def do_login():
|
def do_login():
|
||||||
pw_hashed = hashlib.sha256(request.form['password'].encode('utf-8')).digest()
|
pw_hashed = hashlib.sha256(request.form['password'].encode('utf-8')).digest().replace(b"\0", b"\1")
|
||||||
c = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
|
c = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
|
||||||
c.execute("SELECT * FROM users WHERE email = %s", (request.form['email'],))
|
c.execute("SELECT * FROM users WHERE email = %s", (request.form['email'],))
|
||||||
data = c.fetchone()
|
data = c.fetchone()
|
||||||
|
@ -616,6 +616,10 @@ def do_login():
|
||||||
def report_bug():
|
def report_bug():
|
||||||
return render_template("report_bug.html")
|
return render_template("report_bug.html")
|
||||||
|
|
||||||
|
@app.route("/help/settings")
|
||||||
|
def help_settings():
|
||||||
|
return render_template("help_settings.html")
|
||||||
|
|
||||||
@app.route("/img/bot_generic.png")
|
@app.route("/img/bot_generic.png")
|
||||||
def img_bot_generic():
|
def img_bot_generic():
|
||||||
return send_file("static/bot_generic.png", mimetype="image/png")
|
return send_file("static/bot_generic.png", mimetype="image/png")
|
||||||
|
|
Loading…
Reference in a new issue