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

Compare commits

...

5 commits

6 changed files with 109 additions and 7 deletions

17
app/blacklist.json Normal file
View file

@ -0,0 +1,17 @@
[
"freespeechextremist.com",
"kiwifarms.cc",
"neckbeard.xyz",
"gameliberty.club",
"freespeech.firedragonstudios.com",
"shitposter.club",
"pawoo.net",
"the.hedgehoghunter.club",
"honey.church",
"anime.website",
"aria.company",
"pl.765racing.com",
"yorishiro.space",
"pl.smuglo.li",
"albin.social"
]

View file

@ -1,7 +1,7 @@
from flask import session, render_template, request, redirect from flask import session, render_template, request, redirect, url_for
import requests import requests
from mastodon import Mastodon from mastodon import Mastodon
import re import re, json
def bot_accounts_add(mysql, cfg): def bot_accounts_add(mysql, cfg):
if request.method == 'POST': if request.method == 'POST':
@ -21,6 +21,10 @@ def bot_accounts_add(mysql, cfg):
session['instance'] = handle_list[2] session['instance'] = handle_list[2]
session['handle'] = request.form['account'] session['handle'] = request.form['account']
if session['instance'] in json.load(open("blacklist.json")):
session['error'] = "Learning from accounts on this instance is not allowed."
return redirect(url_for("render_bot_accounts_add"))
try: try:
r = requests.get("https://{}/api/v1/instance".format(session['instance']), timeout=10) r = requests.get("https://{}/api/v1/instance".format(session['instance']), timeout=10)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
@ -51,7 +55,7 @@ def bot_accounts_add(mysql, cfg):
session['client_id'], session['client_secret'] = Mastodon.create_app( session['client_id'], session['client_secret'] = Mastodon.create_app(
"FediBooks User Authenticator", "FediBooks User Authenticator",
api_base_url="https://{}".format(session['instance']), api_base_url="https://{}".format(session['instance']),
scopes=["read:statuses"] if session['instance_type'] == 'Mastodon' else ["read"], scopes=["read:statuses", "read:accounts"] if session['instance_type'] == 'Mastodon' else ["read"],
website=cfg['base_uri'] website=cfg['base_uri']
) )
@ -63,7 +67,7 @@ def bot_accounts_add(mysql, cfg):
session['url'] = client.auth_request_url( session['url'] = client.auth_request_url(
client_id=session['client_id'], client_id=session['client_id'],
scopes=["read:statuses"] if session['instance_type'] == 'Mastodon' else ["read"] scopes=["read:statuses", "read:accounts"] if session['instance_type'] == 'Mastodon' else ["read"]
) )
elif session['step'] == 2: elif session['step'] == 2:
@ -72,11 +76,11 @@ def bot_accounts_add(mysql, cfg):
client = Mastodon(client_id=session['client_id'], client_secret=session['client_secret'], api_base_url=session['instance']) client = Mastodon(client_id=session['client_id'], client_secret=session['client_secret'], api_base_url=session['instance'])
session['secret'] = client.log_in( session['secret'] = client.log_in(
code = request.form['code'], code = request.form['code'],
scopes=["read:statuses"] if session['instance_type'] == 'Mastodon' else ["read"], scopes=["read:statuses", "read:accounts"] if session['instance_type'] == 'Mastodon' else ["read"],
) )
username = client.account_verify_credentials()['username'] username = client.account_verify_credentials()['username']
if username != session['username']: if username != session['username']:
error = "Incorrect username." error = "Please authenticate as {}.".format(session['username'])
return render_template("bot/accounts_add.html", error = error) return render_template("bot/accounts_add.html", error = error)
except: except:
session['step'] = 1 session['step'] = 1

View file

@ -1,7 +1,7 @@
from flask import request, session, render_template, redirect, url_for from flask import request, session, render_template, redirect, url_for
import requests import requests
from mastodon import Mastodon from mastodon import Mastodon
import re import re, json
def bot_create(mysql, cfg, scopes, scopes_pleroma): def bot_create(mysql, cfg, scopes, scopes_pleroma):
if request.method == 'POST': if request.method == 'POST':
@ -9,6 +9,10 @@ def bot_create(mysql, cfg, scopes, scopes_pleroma):
# strip leading https://, if provided # strip leading https://, if provided
session['instance'] = re.match(r"^(?:https?:\/\/)?(.*)", request.form['instance']).group(1) session['instance'] = re.match(r"^(?:https?:\/\/)?(.*)", request.form['instance']).group(1)
if session['instance'] in json.load(open("blacklist.json")):
session['error'] = "Creating a bot on this instance is not allowed."
return redirect(url_for("render_bot_create"))
# check for mastodon/pleroma # check for mastodon/pleroma
try: try:
r = requests.get("https://{}/api/v1/instance".format(session['instance']), timeout=10) r = requests.get("https://{}/api/v1/instance".format(session['instance']), timeout=10)

View file

@ -212,3 +212,37 @@ form .row {
.success { .success {
background-color: #6e6; background-color: #6e6;
} }
#chatbox {
height: 90vh;
background-color: #3d4353;
padding: 10px;
}
#chatbox-input, #chatbox-input input{
width: 100%;
}
.message {
display: inline-block;
padding: 5px;
min-height: 30px;
max-width: 60%;
}
.message-container.user {
text-align: right;
}
.message-container .bot-icon {
background: center / contain url("https://lynnesbian.space/img/bune.png") no-repeat;
height: 30px;
width: 30px;
display: inline-block;
padding: 5px;
}
.message.bot {
background-color: mediumpurple;
color: white;
vertical-align: top;
}
.message.user {
background-color: #ddd;
color: #333;
}

View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FediBooks</title>
{% include 'imports.html' %}
</head>
<body>
<div class="container centred">
<h1 class="thin centred">Chat</h1>
<p class="centred">Talking to {{ bot }}</p>
<p class="centred" style="margin: 20px 0;">
<a class="button btn-primary" href="/bot/accounts/add" role="button"><i class="fas fa-home"></i> Home</a>
</p>
</div>
<noscript>
<div class="container centred">
<h2>This feature requires JavaScript.</h2>
</div>
</noscript>
<div class="container">
<div id="chatbox">
<div class="message-container user">
<div class="message user">Henlo</div>
</div>
<div class="message-container bot">
<div class="bot-icon"></div>
<div class="message bot">Henlo human uwu<br>How are you</div>
</div>
</div>
<form id="chatbox-input">
<input name="message" placeholder="Press enter to send">
</form>
</div>
{% include 'footer.html' %}
</body>
</html>

View file

@ -107,6 +107,7 @@ def bot_toggle(id):
@app.route("/bot/chat/<id>") @app.route("/bot/chat/<id>")
def bot_chat(id): def bot_chat(id):
return render_template("coming_soon.html") return render_template("coming_soon.html")
# return render_template("/bot/chat.html", bot = id)
@app.route("/bot/blacklist/<id>") @app.route("/bot/blacklist/<id>")
def bot_blacklist(id): def bot_blacklist(id):