mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-25 16:48:58 +00:00
bot settings page is now fully functional!
This commit is contained in:
parent
6838e16b03
commit
787851b13a
2 changed files with 62 additions and 8 deletions
|
@ -9,14 +9,14 @@
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="thin centred">Configure bot</h1>
|
<h1 class="thin centred">Configure bot</h1>
|
||||||
<p class="large centred">@botname@example.com</p>
|
<p class="large centred">{{ bot['handle'] }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% include 'error.html' %}
|
{% include 'error.html' %}
|
||||||
{% include 'success.html' %}
|
{% include 'success.html' %}
|
||||||
|
|
||||||
<div class="container centred">
|
<div class="container centred">
|
||||||
<form action="/do/bot/edit" method="post" class="full-width">
|
<form method="POST" class="full-width">
|
||||||
<!-- <div class="row">
|
<!-- <div class="row">
|
||||||
<label for="username" class="large">Username</label>
|
<label for="username" class="large">Username</label>
|
||||||
<input type="text" name="username" value="Bot Name">
|
<input type="text" name="username" value="Bot Name">
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label for="cw" class="large">Content warning (subject)</label>
|
<label for="cw" class="large">Content warning (subject)</label>
|
||||||
<input type="text" placeholder="None" name="cw" value = "{{ bot['content_warning'] if bot['content_warning'] != None else '' }}">
|
<input type="text" placeholder="None" name="cw" pattern=".{0,128}" title="Content warning cannot exceed 128 characters." value = "{{ bot['content_warning'] if bot['content_warning'] != None else '' }}">
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label for="length" class="large">Maximum post length (characters)</label>
|
<label for="length" class="large">Maximum post length (characters)</label>
|
||||||
|
|
58
webui.py
58
webui.py
|
@ -135,11 +135,65 @@ def settings():
|
||||||
session['success'] = True
|
session['success'] = True
|
||||||
return redirect(url_for('settings'), 303)
|
return redirect(url_for('settings'), 303)
|
||||||
|
|
||||||
@app.route("/bot/edit/<id>")
|
@app.route("/bot/edit/<id>", methods = ['GET', 'POST'])
|
||||||
def bot_edit(id):
|
def bot_edit(id):
|
||||||
|
if request.method == "GET":
|
||||||
dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
|
dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
|
||||||
dc.execute("SELECT * FROM bots WHERE handle = %s", (id,))
|
dc.execute("SELECT * FROM bots WHERE handle = %s", (id,))
|
||||||
return render_template("bot_edit.html", bot = dc.fetchone())
|
return render_template("bot_edit.html", bot = dc.fetchone(), error = session.pop('error', None), success = session.pop('success', None))
|
||||||
|
else:
|
||||||
|
# update stored settings
|
||||||
|
replies_enabled = 'replies' in request.form
|
||||||
|
learn_from_cw = 'cw-learning' in request.form
|
||||||
|
|
||||||
|
if request.form['fake-mention-style'] not in ['full', 'brief']:
|
||||||
|
session['error'] = "Invalid setting for fake mention style."
|
||||||
|
return redirect("/bot/edit/{}".format(id), 303)
|
||||||
|
|
||||||
|
if request.form['fake-mentions'] not in ['always', 'middle', 'never']:
|
||||||
|
session['error'] = "Invalid setting for fake mentions."
|
||||||
|
return redirect("/bot/edit/{}".format(id), 303)
|
||||||
|
|
||||||
|
if request.form['privacy'] not in ['public', 'unlisted', 'private']:
|
||||||
|
session['error'] = "Invalid setting for post privacy."
|
||||||
|
return redirect("/bot/edit/{}".format(id), 303)
|
||||||
|
|
||||||
|
if int(request.form['length']) < 100 or int(request.form['length']) > 5000:
|
||||||
|
session['error'] = "Invalid setting for maximum post length."
|
||||||
|
return redirect("/bot/edit/{}".format(id), 303)
|
||||||
|
|
||||||
|
if int(request.form['freq']) < 15 or int(request.form['freq']) > 240 or int(request.form['freq']) % 5:
|
||||||
|
session['error'] = "Invalid setting for post frequency."
|
||||||
|
return redirect("/bot/edit/{}".format(id), 303)
|
||||||
|
|
||||||
|
if len(request.form['cw']) > 128:
|
||||||
|
session['error'] = "Content warning cannot exceed 128 characters."
|
||||||
|
return redirect("/bot/edit/{}".format(id), 303)
|
||||||
|
|
||||||
|
c = mysql.connection.cursor()
|
||||||
|
try:
|
||||||
|
c.execute("UPDATE bots SET replies_enabled = %s, post_frequency = %s, content_warning = %s, length = %s, fake_mentions = %s, fake_mentions_full = %s, post_privacy = %s, learn_from_cw = %s WHERE handle = %s", (
|
||||||
|
replies_enabled,
|
||||||
|
request.form['freq'],
|
||||||
|
request.form['cw'] if request.form['cw'] != "" else None,
|
||||||
|
request.form['length'],
|
||||||
|
request.form['fake-mentions'],
|
||||||
|
request.form['fake-mention-style'] == 'full',
|
||||||
|
request.form['privacy'],
|
||||||
|
learn_from_cw,
|
||||||
|
id
|
||||||
|
))
|
||||||
|
mysql.connection.commit()
|
||||||
|
c.close()
|
||||||
|
except:
|
||||||
|
session['error'] = "Couldn't save your settings."
|
||||||
|
return redirect("/bot/edit/{}".format(id), 303)
|
||||||
|
|
||||||
|
session['success'] = True
|
||||||
|
return redirect("/bot/edit/{}".format(id), 303)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/bot/delete/<id>", methods=['GET', 'POST'])
|
@app.route("/bot/delete/<id>", methods=['GET', 'POST'])
|
||||||
def bot_delete(id):
|
def bot_delete(id):
|
||||||
|
|
Loading…
Reference in a new issue