mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-25 08:38:59 +00:00
Compare commits
4 commits
86f68cfa37
...
7572536361
Author | SHA1 | Date | |
---|---|---|---|
7572536361 | |||
ef27eacb69 | |||
7eac3f6f11 | |||
6b24fb667b |
5 changed files with 50 additions and 7 deletions
|
@ -5,3 +5,4 @@ requests==2.22.0
|
|||
Flask==1.1.1
|
||||
flask-mysqldb==0.2.0
|
||||
bcrypt == 3.1.7
|
||||
requests==2.22.0
|
||||
|
|
|
@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS `bots` (
|
|||
FOREIGN KEY (`credentials_id`) REFERENCES credentials(id) ON DELETE CASCADE
|
||||
) ENGINE=INNODB;
|
||||
CREATE TABLE IF NOT EXISTS `fedi_account` (
|
||||
`handle` VARCHAR(128) NOT NULL PRIMARY KEY,
|
||||
`handle` VARCHAR(128) PRIMARY KEY,
|
||||
`outbox` VARCHAR(256),
|
||||
`credentials_id` INT NOT NULL,
|
||||
`icon` VARCHAR(512),
|
||||
|
@ -43,9 +43,11 @@ CREATE TABLE IF NOT EXISTS `fedi_account` (
|
|||
) ENGINE=INNODB;
|
||||
CREATE TABLE IF NOT EXISTS `posts` (
|
||||
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
`fedi_id` VARCHAR(128),
|
||||
`post_id` VARCHAR(64) NOT NULL,
|
||||
`content` TEXT NOT NULL,
|
||||
`cw` BOOLEAN NOT NULL
|
||||
`cw` BOOLEAN NOT NULL,
|
||||
FOREIGN KEY (`fedi_id`) REFERENCES fedi_account(handle) ON DELETE CASCADE
|
||||
) ENGINE=INNODB;
|
||||
CREATE TABLE IF NOT EXISTS `word_blacklist` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
{% elif session['step'] == 2 %}
|
||||
<h2 class="thin centred">Detected instance type: {{ session['instance_type'] }}</h2>
|
||||
<p>{{ session['instance'] }} is a {{ session['instance_type'] }} instance. {% if session['instance_type'] == Pleroma %}Unfortunately, bots on Pleroma instances cannot listen for replies yet. This means that your bot will have its reply functionality disabled.{% else %}{{ session['instance_type'] }} instances are fully supported, and your bot will have all functionality available.{% endif %}</p>
|
||||
<p>{{ session['instance'] }} is a {{ session['instance_type'] }} instance. {% if session['instance_type'] == 'Pleroma' %}Unfortunately, bots on Pleroma instances cannot listen for replies yet. This means that your bot will have its reply functionality disabled.{% else %}{{ session['instance_type'] }} instances are fully supported, and your bot will have all functionality available.{% endif %}</p>
|
||||
|
||||
{% elif session['step'] == 3 %}
|
||||
<p>You now need to give your bot access to the {{ session['instance'] }} account you have created for it. If you have not yet created an account on {{ session['instance'] }} for your bot to use, please do so now.</p>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<body>
|
||||
<div class="container light">
|
||||
<h1 class='thin centred'>Home</h1>
|
||||
<p class="centred large">Hi there! You have 1 bots, all of which are currently active.</p>
|
||||
<p class="centred large">Hi there! You have {{ bot_count }} bot{% if bot_count != 1 %}s{% endif %}{% if bot_count != 0 %}, {{ active_count }} of which {% if active_count == 1 %}is{% else %}are{% endif %} currently active.{% else %}.{% endif %}</p>
|
||||
<p class="centred" style="margin: 50px 0;">
|
||||
<a class="button btn-primary btn-large" href="/bot/create" role="button"><i class="fas fa-robot"></i> New bot</a>
|
||||
<a class="button btn-secondary btn-large" href="/settings" role="button"><i class="fas fa-cog"></i> Account settings</a>
|
||||
|
|
46
webui.py
46
webui.py
|
@ -1,8 +1,9 @@
|
|||
from flask import Flask, render_template, session, request, redirect, url_for
|
||||
from flask_mysqldb import MySQL
|
||||
import requests
|
||||
import MySQLdb
|
||||
import bcrypt
|
||||
import json, hashlib
|
||||
import json, hashlib, re
|
||||
|
||||
cfg = json.load(open("config.json"))
|
||||
|
||||
|
@ -20,7 +21,15 @@ mysql = MySQL(app)
|
|||
def home():
|
||||
if 'userid' in session:
|
||||
session['step'] = 1
|
||||
return render_template("home.html")
|
||||
c = mysql.connection.cursor()
|
||||
c.execute("SELECT COUNT(*) FROM `bots` WHERE user_id = %s", (session['userid'],))
|
||||
bot_count = c.fetchone()[0]
|
||||
active_count = None
|
||||
if bot_count > 0:
|
||||
c.execute("SELECT COUNT(*) FROM `bots` WHERE user_id = %s AND enabled = TRUE", (session['userid'],))
|
||||
active_count = c.fetchone()[0]
|
||||
c.close()
|
||||
return render_template("home.html", bot_count = bot_count, active_count = active_count)
|
||||
else:
|
||||
return render_template("front_page.html")
|
||||
|
||||
|
@ -61,8 +70,39 @@ def bot_accounts(id):
|
|||
def bot_accounts_add():
|
||||
return render_template("bot_accounts_add.html")
|
||||
|
||||
@app.route("/bot/create/")
|
||||
@app.route("/bot/create/", methods=['GET', 'POST'])
|
||||
def bot_create():
|
||||
if request.method == 'POST':
|
||||
if session['step'] == 1:
|
||||
# strip leading https://, if provided
|
||||
session['instance'] = re.match(r"^(?:https?:\/\/)?(.*)", request.form['instance']).group(1)
|
||||
|
||||
# check for mastodon/pleroma
|
||||
r = requests.get("https://{}/api/v1/instance".format(session['instance']))
|
||||
if r.status_code == 200:
|
||||
j = r.json()
|
||||
if "Pleroma" in j['version']:
|
||||
session['instance_type'] = "Pleroma"
|
||||
session['step'] += 1
|
||||
else:
|
||||
if 'is_pro' in j['contact_account']:
|
||||
# gab instance
|
||||
session['error'] = "Eat shit and die, fascist scum."
|
||||
else:
|
||||
session['instance_type'] = "Mastodon"
|
||||
session['step'] += 1
|
||||
|
||||
else:
|
||||
# not a masto/pleroma instance
|
||||
# misskey is currently unsupported
|
||||
# all other instance types are also unsupported
|
||||
# return an error message
|
||||
#TODO: misskey
|
||||
session['error'] = "Unsupported instance type."
|
||||
|
||||
elif session['step'] == 2:
|
||||
pass
|
||||
|
||||
return render_template("bot_create.html")
|
||||
|
||||
@app.route("/do/signup", methods=['POST'])
|
||||
|
|
Loading…
Reference in a new issue