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

Compare commits

..

7 commits

5 changed files with 22 additions and 10 deletions

View file

@ -29,8 +29,8 @@ def extract_post(post):
link.decompose()
text = soup.get_text()
text = re.sub("https://([^/]+)/(@[^ ]+)", 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://([^/]+)/(@[^\s]+)", r"\2@\1", text) # put mastodon-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)
return text

View file

@ -15,7 +15,7 @@ def home(mysql):
c.execute("SELECT COUNT(*) FROM `bots` WHERE user_id = %s AND enabled = TRUE", (session['user_id'],))
active_count = c.fetchone()[0]
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()
dc.close()

View file

@ -13,10 +13,10 @@
<div class="container centred">
<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">
<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>
<button class="button btn-dangerous"><i class="fas fa-trash"></i> Delete bot</button>
</div>

View file

@ -19,7 +19,7 @@
<div class="container" style="min-height: 300px;">
{% for bot in bots %}
<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">
{% set handle_list = bot['handle'].split('@') %}
<div class="panel-name">@{{ handle_list[1] }}<span class="subtle tiny">@{{ handle_list[2] }}</span></div>

View file

@ -70,18 +70,30 @@ def bot_delete(id):
if bot_check(id):
if request.method == 'GET':
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:
# delete bot by deleting its credentials
# FK constraint will delete bot
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]
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.close()
mysql.connection.commit()
return redirect(url_for("home"), 303)
return redirect(url_for("render_home"), 303)
@app.route("/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,))
mysql.connection.commit()
c.close()
return redirect(url_for("home"), 303)
return redirect(url_for("render_home"), 303)
@app.route("/bot/chat/<id>")
def bot_chat(id):