mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-25 16:48:58 +00:00
Compare commits
5 commits
168c5a0bb2
...
49d2d15493
Author | SHA1 | Date | |
---|---|---|---|
49d2d15493 | |||
b1aec4c8d5 | |||
8d99f46d1a | |||
a80f77d2bc | |||
07e559f7d9 |
6 changed files with 109 additions and 7 deletions
17
app/blacklist.json
Normal file
17
app/blacklist.json
Normal 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"
|
||||
]
|
|
@ -1,7 +1,7 @@
|
|||
from flask import session, render_template, request, redirect
|
||||
from flask import session, render_template, request, redirect, url_for
|
||||
import requests
|
||||
from mastodon import Mastodon
|
||||
import re
|
||||
import re, json
|
||||
|
||||
def bot_accounts_add(mysql, cfg):
|
||||
if request.method == 'POST':
|
||||
|
@ -21,6 +21,10 @@ def bot_accounts_add(mysql, cfg):
|
|||
session['instance'] = handle_list[2]
|
||||
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:
|
||||
r = requests.get("https://{}/api/v1/instance".format(session['instance']), timeout=10)
|
||||
except requests.exceptions.ConnectionError:
|
||||
|
@ -51,7 +55,7 @@ def bot_accounts_add(mysql, cfg):
|
|||
session['client_id'], session['client_secret'] = Mastodon.create_app(
|
||||
"FediBooks User Authenticator",
|
||||
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']
|
||||
)
|
||||
|
||||
|
@ -63,7 +67,7 @@ def bot_accounts_add(mysql, cfg):
|
|||
|
||||
session['url'] = client.auth_request_url(
|
||||
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:
|
||||
|
@ -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'])
|
||||
session['secret'] = client.log_in(
|
||||
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']
|
||||
if username != session['username']:
|
||||
error = "Incorrect username."
|
||||
error = "Please authenticate as {}.".format(session['username'])
|
||||
return render_template("bot/accounts_add.html", error = error)
|
||||
except:
|
||||
session['step'] = 1
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
from flask import request, session, render_template, redirect, url_for
|
||||
import requests
|
||||
from mastodon import Mastodon
|
||||
import re
|
||||
import re, json
|
||||
|
||||
def bot_create(mysql, cfg, scopes, scopes_pleroma):
|
||||
if request.method == 'POST':
|
||||
if session['step'] == 1:
|
||||
# strip leading https://, if provided
|
||||
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
|
||||
try:
|
||||
|
|
|
@ -212,3 +212,37 @@ form .row {
|
|||
.success {
|
||||
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;
|
||||
}
|
||||
|
|
42
app/templates/bot/chat.html
Normal file
42
app/templates/bot/chat.html
Normal 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>
|
|
@ -107,6 +107,7 @@ def bot_toggle(id):
|
|||
@app.route("/bot/chat/<id>")
|
||||
def bot_chat(id):
|
||||
return render_template("coming_soon.html")
|
||||
# return render_template("/bot/chat.html", bot = id)
|
||||
|
||||
@app.route("/bot/blacklist/<id>")
|
||||
def bot_blacklist(id):
|
||||
|
|
Loading…
Reference in a new issue