Skip to content

Commit

Permalink
dashboard: add nonce filter, display abbreviated ID, bump to 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
0vf committed Jul 6, 2024
1 parent 6351300 commit aaba2a1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
19 changes: 15 additions & 4 deletions dashboard/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from utils import utils, db, info
from ast import literal_eval

dashboard_version = "1.1.2"
dashboard_version = "1.2.0"

app = Flask(__name__)

Expand Down Expand Up @@ -70,7 +70,7 @@ def inject_global_vars():

@app.route("/login/")
def login():
return OAuth2.create_session()
return OAuth2.create_session(scope=["identify", "guilds"])

@app.route("/logout/")
def logout():
Expand Down Expand Up @@ -133,19 +133,28 @@ def server_view(guild_id):
if request.method == 'POST':
log_channel = request.form["log_channel"]
event_log_channel = request.form["event_log_channel"]
nonce_filter = request.form["nonce_filter"]
if nonce_filter == "0":
nonce_filter = 0
else:
nonce_filter = 1
if log_channel == 0 or log_channel in guild_channels.response:
db.set_log_channel(guild_id, log_channel, conn, c)
if event_log_channel == 0 or event_log_channel in guild_channels.response:
db.set_event_log_channel(guild_id, event_log_channel, conn, c)
if nonce_filter == 0 or nonce_filter == 1:
db.set_nonce_filter_status(guild_id, nonce_filter, conn, c)
db_log_channel = db.get_log_channel(guild_id, c)
db_event_log_channel = db.get_event_log_channel(guild_id, c)
db_nonce_filter = db.get_nonce_filter_status(guild_id, c)
conn.close()
return render_template("server.html", guild=guild_obj, user=user, guild_channels=guild_channels.response, saved=True, log_channel=db_log_channel, event_log_channel=db_event_log_channel, title=f"{guild_name}", description=f"{guild_name} configuration panel", url=f"{config_data['dashboard']['url']}{url_for('server_view', guild_id=guild_id)}")
return render_template("server.html", guild=guild_obj, user=user, guild_channels=guild_channels.response, saved=True, log_channel=db_log_channel, event_log_channel=db_event_log_channel, nonce_filter=db_nonce_filter, title=f"{guild_name}", description=f"{guild_name} configuration panel", url=f"{config_data['dashboard']['url']}{url_for('server_view', guild_id=guild_id)}")
else:
db_log_channel = db.get_log_channel(guild_id, c)
db_event_log_channel = db.get_event_log_channel(guild_id, c)
db_nonce_filter = db.get_nonce_filter_status(guild_id, c)
conn.close()
return render_template("server.html", guild=guild_obj, user=user, guild_channels=guild_channels.response, saved=False, log_channel=db_log_channel, event_log_channel=db_event_log_channel, title=f"{guild_name}", description=f"{guild_name} configuration panel", url=f"{config_data['dashboard']['url']}{url_for('server_view', guild_id=guild_id)}")
return render_template("server.html", guild=guild_obj, user=user, guild_channels=guild_channels.response, saved=False, log_channel=db_log_channel, event_log_channel=db_event_log_channel, nonce_filter=db_nonce_filter, title=f"{guild_name}", description=f"{guild_name} configuration panel", url=f"{config_data['dashboard']['url']}{url_for('server_view', guild_id=guild_id)}")

@app.route("/dashboard/server/<int:guild_id>/moderations/")
async def moderations_redirect(guild_id):
Expand Down Expand Up @@ -183,6 +192,8 @@ async def moderations(guild_id, page_number):
mutable_moderation[9] = "No"
else:
mutable_moderation[9] = "Yes"
mutable_moderation.append(moderation[2])
mutable_moderation.append(moderation[3])
hero_chunk.append(tuple(mutable_moderation))
elif lock:
pass
Expand Down
3 changes: 2 additions & 1 deletion dashboard/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<link href="https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap" rel="stylesheet">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@creativebulma/bulma-tooltip@1.2.0/dist/bulma-tooltip.min.css">
</head>

<div class="container">
Expand Down Expand Up @@ -80,7 +81,7 @@
<div class="modal-content">
<span class="close">&times;</span>
<p>{{ user.name }}</p>
<p>{{ user.email }}</p>
<p>{{ user.id }}</p>
<br>
<a class="button is-danger" href="/logout">Log out</a>
</div>
Expand Down
4 changes: 2 additions & 2 deletions dashboard/templates/moderations.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
{% elif moderation[4] == "Ban" and moderation[6] == "S4" %}
<th><span class="tag is-danger" style="background-color: #C01D3C; color: #1A0006;">Ban - {{ moderation[6] }}</span></th>
{% endif %}
<th>{{ moderation[2] }}</th>
<th>{{ moderation[3] }}</th>
<th><abbr title="{{ moderation[11] }}">{{ moderation[2] }}</abbr></th>
<th><abbr title="{{ moderation[12] }}">{{ moderation[3] }}</abbr></th>
<th>{{ moderation[5] }}</th>
<th>{{ moderation[8] }}</th>
<th>{{ moderation[7] }}</th>
Expand Down
42 changes: 31 additions & 11 deletions dashboard/templates/server.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
</div>
<br><br>
<div class="container hero">
<form method="POST" class="field">
<div class="panel is-primary">
<p class="panel-heading">Channel configuration</p>
<form method="POST" class="field">

<div class="panel-block">
<div class="field">
<label class="label">Moderation log channel</label>
<div class="control">
<div class="select">
<select id="log_channel" name="log_channel">>
<select id="log_channel" name="log_channel">
<option value="0">None</option>
{% for id, name in guild_channels.items() %}
<option value="{{ id }}">{{ name }}</option>
Expand All @@ -53,7 +54,7 @@
<label class="label">Event log channel</label>
<div class="control">
<div class="select">
<select id="event_log_channel" name="event_log_channel">>
<select id="event_log_channel" name="event_log_channel">
<option value="0">None</option>
{% for id, name in guild_channels.items() %}
<option value="{{ id }}">{{ name }}</option>
Expand All @@ -63,25 +64,44 @@
</div>
</div>
</div>
</div>
<div class="panel is-link">
<p class="panel-heading">Moderation configuration</p>
<div class="panel-block">
<div class="field is-grouped">
<div class="field">
<label class="label" data-tooltip="Filter & log messages hidden in message nonces.">Nonce filtering <i class="fas fa-info-circle"></i></label>
<div class="control">
<input type="hidden" id="db_log_channel" name="db_log_channel" value="{{ log_channel }}">
<input type="hidden" id="db_event_log_channel" name="db_event_log_channel" value="{{ event_log_channel }}">
<button type="submit" class="button is-primary">Save</button><br>
{% if saved == True %}
<span class="has-text-success is-vcentered" style="vertical-align: bottom;"><i class="icon fa-solid fa-square-check"></i>Successfully saved!</span>
{% endif %}
<div class="select">
<select id="nonce_filter" name="nonce_filter">
<option value="0">False</option>
<option value="1">True</option>
</select>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="panel is-success">
<div class="panel-block">
<div class="control">
<input type="hidden" id="db_log_channel" name="db_log_channel" value="{{ log_channel }}">
<input type="hidden" id="db_event_log_channel" name="db_event_log_channel" value="{{ event_log_channel }}">
<input type="hidden" id="db_nonce_filter" name="db_nonce_filter" value="{{ nonce_filter }}">
<button type="submit" class="button is-primary">Save</button><br>
{% if saved == True %}
<span class="has-text-success is-vcentered" style="vertical-align: bottom;"><i class="icon fa-solid fa-square-check"></i>Successfully saved!</span>
{% endif %}
</div>
</div>
</div>
</form>
</div>
</section>
<script>
$(document).ready(function() {
$("#log_channel").val(document.getElementById("db_log_channel").value)
$("#event_log_channel").val(document.getElementById("db_event_log_channel").value)
$("#nonce_filter").val(document.getElementById("db_nonce_filter").value)
});
</script>
{% endblock %}

0 comments on commit aaba2a1

Please sign in to comment.