mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-26 00:58:59 +00:00
Compare commits
No commits in common. "8f6dbfeaf4aa29cfca63a1f6c948be972da63ad9" and "c474f988bb89ee43152ca20f721487a1f463e38b" have entirely different histories.
8f6dbfeaf4
...
c474f988bb
5 changed files with 10 additions and 22 deletions
|
@ -29,8 +29,8 @@ def extract_post(post):
|
||||||
link.decompose()
|
link.decompose()
|
||||||
|
|
||||||
text = soup.get_text()
|
text = soup.get_text()
|
||||||
text = re.sub(r"https://([^/]+)/(@[^\s]+)", r"\2@\1", text) # put mastodon-style mentions back in
|
text = re.sub("https://([^/]+)/(@[^ ]+)", 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 = re.sub("https://([^/]+)/users/([^ ]+)", 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" style="{{ 'background-image: url(\'' + icon + '\')' if icon else '' }}"></div>
|
<div class="panel-icon large"></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 FediBooks will stop posting from it.</p>
|
<p>The account on {{ instance }} will remain open, but your bot 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,30 +70,18 @@ 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]
|
||||||
c = mysql.connection.cursor()
|
return render_template("bot/delete.html", instance = instance)
|
||||||
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("render_home"), 303)
|
return redirect(url_for("home"), 303)
|
||||||
|
|
||||||
@app.route("/bot/toggle/<id>")
|
@app.route("/bot/toggle/<id>")
|
||||||
def bot_toggle(id):
|
def bot_toggle(id):
|
||||||
|
@ -102,7 +90,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("render_home"), 303)
|
return redirect(url_for("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