mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-25 16:48:58 +00:00
Compare commits
7 commits
c474f988bb
...
8f6dbfeaf4
Author | SHA1 | Date | |
---|---|---|---|
8f6dbfeaf4 | |||
11d6d06695 | |||
39d2be53ad | |||
53c44ec8ac | |||
7ad540777a | |||
eb5e8977c2 | |||
ec087b5136 |
5 changed files with 22 additions and 10 deletions
|
@ -29,8 +29,8 @@ def extract_post(post):
|
||||||
link.decompose()
|
link.decompose()
|
||||||
|
|
||||||
text = soup.get_text()
|
text = soup.get_text()
|
||||||
text = re.sub("https://([^/]+)/(@[^ ]+)", r"\2@\1", text) # put mastodon-style mentions back in
|
text = re.sub(r"https://([^/]+)/(@[^\s]+)", r"\2@\1", text) # put mastodon-style mentions back in
|
||||||
text = re.sub("https://([^/]+)/users/([^ ]+)", r"@\2@\1", text) # put pleroma-style mentions back in
|
text = re.sub(r"https://([^/]+)/users/([^\s/]+)", r"@\2@\1", text) # put pleroma-style mentions back in
|
||||||
text = text.rstrip("\n") # remove trailing newline(s)
|
text = text.rstrip("\n") # remove trailing newline(s)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ def home(mysql):
|
||||||
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'],))
|
||||||
active_count = c.fetchone()[0]
|
active_count = c.fetchone()[0]
|
||||||
dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
|
dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
|
||||||
dc.execute("SELECT `handle`, `enabled`, `last_post`, `post_frequency`, `icon` FROM `bots` WHERE user_id = %s", (session['user_id'],))
|
dc.execute("SELECT handle, enabled, last_post, post_frequency, icon FROM `bots` WHERE user_id = %s", (session['user_id'],))
|
||||||
bots = dc.fetchall()
|
bots = dc.fetchall()
|
||||||
dc.close()
|
dc.close()
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
|
|
||||||
<div class="container centred">
|
<div class="container centred">
|
||||||
<form method='POST'>
|
<form method='POST'>
|
||||||
<div class="panel-icon large"></div>
|
<div class="panel-icon large" style="{{ 'background-image: url(\'' + icon + '\')' if icon else '' }}"></div>
|
||||||
<div class="container centred">
|
<div class="container centred">
|
||||||
<p>Are you sure you want to <strong>permanently</strong> delete this bot?</p>
|
<p>Are you sure you want to <strong>permanently</strong> delete this bot?</p>
|
||||||
<p>The account on {{ instance }} will remain open, but your bot will stop posting from it.</p>
|
<p>The account on {{ instance }} will remain open, but FediBooks will stop posting from it.</p>
|
||||||
<a class="button btn-secondary" href="/"><i class="fas fa-times"></i> Cancel</a>
|
<a class="button btn-secondary" href="/"><i class="fas fa-times"></i> Cancel</a>
|
||||||
<button class="button btn-dangerous"><i class="fas fa-trash"></i> Delete bot</button>
|
<button class="button btn-dangerous"><i class="fas fa-trash"></i> Delete bot</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<div class="container" style="min-height: 300px;">
|
<div class="container" style="min-height: 300px;">
|
||||||
{% for bot in bots %}
|
{% for bot in bots %}
|
||||||
<div class="row light">
|
<div class="row light">
|
||||||
<div class="panel-icon {{ "online" if bot['enabled'] else "offline"}}" style="{{ "background-image: url('" + bot['icon'] + "')" if bot['icon'] else "" }}"></div>
|
<div class="panel-icon {{ 'online' if bot['enabled'] else 'offline'}}" style="{{ 'background-image: url(\'' + bot['icon'] + '\')' if bot['icon'] else '' }}"></div>
|
||||||
<div class="panel-text">
|
<div class="panel-text">
|
||||||
{% set handle_list = bot['handle'].split('@') %}
|
{% set handle_list = bot['handle'].split('@') %}
|
||||||
<div class="panel-name">@{{ handle_list[1] }}<span class="subtle tiny">@{{ handle_list[2] }}</span></div>
|
<div class="panel-name">@{{ handle_list[1] }}<span class="subtle tiny">@{{ handle_list[2] }}</span></div>
|
||||||
|
|
20
app/webui.py
20
app/webui.py
|
@ -70,18 +70,30 @@ def bot_delete(id):
|
||||||
if bot_check(id):
|
if bot_check(id):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
instance = id.split("@")[2]
|
instance = id.split("@")[2]
|
||||||
return render_template("bot/delete.html", instance = instance)
|
c = mysql.connection.cursor()
|
||||||
|
c.execute("SELECT icon FROM bots WHERE handle = %s", (id,))
|
||||||
|
icon = c.fetchone()[0]
|
||||||
|
return render_template("bot/delete.html", instance = instance, icon = icon)
|
||||||
else:
|
else:
|
||||||
# delete bot by deleting its credentials
|
# delete bot by deleting its credentials
|
||||||
# FK constraint will delete bot
|
# FK constraint will delete bot
|
||||||
c = mysql.connection.cursor()
|
c = mysql.connection.cursor()
|
||||||
c.execute("SELECT `credentials_id` FROM `bots` WHERE `handle` = %s", (id,))
|
c.execute("SELECT credentials_id FROM bots WHERE handle = %s", (id,))
|
||||||
credentials_id = c.fetchone()[0]
|
credentials_id = c.fetchone()[0]
|
||||||
|
c.execute("SELECT client_id, client_secret, secret FROM credentials WHERE id = %s", (credentials_id,))
|
||||||
|
credentials = c.fetchone()
|
||||||
|
client = Mastodon(
|
||||||
|
credentials[0],
|
||||||
|
credentials[1],
|
||||||
|
credentials[2],
|
||||||
|
"https://{}".format(id.split("@")[2])
|
||||||
|
)
|
||||||
|
client.push_subscription_delete()
|
||||||
c.execute("DELETE FROM `credentials` WHERE `id` = %s", (credentials_id,))
|
c.execute("DELETE FROM `credentials` WHERE `id` = %s", (credentials_id,))
|
||||||
c.close()
|
c.close()
|
||||||
mysql.connection.commit()
|
mysql.connection.commit()
|
||||||
|
|
||||||
return redirect(url_for("home"), 303)
|
return redirect(url_for("render_home"), 303)
|
||||||
|
|
||||||
@app.route("/bot/toggle/<id>")
|
@app.route("/bot/toggle/<id>")
|
||||||
def bot_toggle(id):
|
def bot_toggle(id):
|
||||||
|
@ -90,7 +102,7 @@ def bot_toggle(id):
|
||||||
c.execute("UPDATE `bots` SET `enabled` = NOT `enabled` WHERE `handle` = %s", (id,))
|
c.execute("UPDATE `bots` SET `enabled` = NOT `enabled` WHERE `handle` = %s", (id,))
|
||||||
mysql.connection.commit()
|
mysql.connection.commit()
|
||||||
c.close()
|
c.close()
|
||||||
return redirect(url_for("home"), 303)
|
return redirect(url_for("render_home"), 303)
|
||||||
|
|
||||||
@app.route("/bot/chat/<id>")
|
@app.route("/bot/chat/<id>")
|
||||||
def bot_chat(id):
|
def bot_chat(id):
|
||||||
|
|
Loading…
Reference in a new issue