diff --git a/templates/bot_create.html b/templates/bot_create.html index aa4cd57..f213c2e 100644 --- a/templates/bot_create.html +++ b/templates/bot_create.html @@ -21,7 +21,7 @@ {% elif session['step'] == 2 %}
{{ 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 %}
+{{ 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 %}
{% elif session['step'] == 3 %}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.
diff --git a/webui.py b/webui.py index bc8607f..7eaf6d3 100644 --- a/webui.py +++ b/webui.py @@ -3,7 +3,7 @@ from flask_mysqldb import MySQL import requests import MySQLdb import bcrypt -import json, hashlib +import json, hashlib, re cfg = json.load(open("config.json")) @@ -70,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'])