Dashboard setting to change chat links, embed render, and mentions limit

This commit is contained in:
Jeremy Zhang 2017-05-08 17:55:07 -07:00
parent b475cc4e64
commit 74e62c7f4c
5 changed files with 82 additions and 0 deletions

View File

@ -6,6 +6,9 @@ class Guilds(Base):
guild_id = db.Column(db.String(255)) # Discord guild id
name = db.Column(db.String(255)) # Name
unauth_users = db.Column(db.Boolean()) # If allowed unauth users
chat_links = db.Column(db.Boolean()) # If users can post links
bracket_links = db.Column(db.Boolean()) # If appending brackets to links to prevent embed
mentions_limit = db.Column(db.Integer) # If there is a limit on the number of mentions in a msg
roles = db.Column(db.Text()) # Guild Roles
channels = db.Column(db.Text()) # Guild channels
owner_id = db.Column(db.String(255)) # Snowflake of the owner
@ -15,6 +18,9 @@ class Guilds(Base):
self.guild_id = guild_id
self.name = name
self.unauth_users = True # defaults to true
self.chat_links = True
self.bracket_links = True
self.mentions_limit = -1 # -1 = unlimited mentions
self.roles = roles
self.channels = channels
self.owner_id = owner_id

View File

@ -92,6 +92,9 @@ def administrate_guild(guild_id):
"id": db_guild.guild_id,
"name": db_guild.name,
"unauth_users": db_guild.unauth_users,
"chat_links": db_guild.chat_links,
"bracket_links": db_guild.bracket_links,
"mentions_limit": db_guild.mentions_limit,
"icon": db_guild.icon
}
return render_template("administrate_guild.html.j2", guild=dbguild_dict, members=users, permissions=permissions)
@ -105,11 +108,17 @@ def update_administrate_guild(guild_id):
if not db_guild:
abort(400)
db_guild.unauth_users = request.form.get("unauth_users", db_guild.unauth_users) in ["true", True]
db_guild.chat_links = request.form.get("chat_links", db_guild.chat_links) in ["true", True]
db_guild.bracket_links = request.form.get("bracket_links", db_guild.bracket_links) in ["true", True]
db_guild.mentions_limit = request.form.get("mentions_limit", db_guild.mentions_limit)
db.session.commit()
return jsonify(
id=db_guild.id,
guild_id=db_guild.guild_id,
unauth_users=db_guild.unauth_users,
chat_links=db_guild.chat_links,
bracket_links=db_guild.bracket_links,
mentions_limit=db_guild.mentions_limit,
)
@user.route('/me')

View File

@ -6,6 +6,9 @@ class Guilds(db.Model):
guild_id = db.Column(db.String(255)) # Discord guild id
name = db.Column(db.String(255)) # Name
unauth_users = db.Column(db.Boolean()) # If allowed unauth users
chat_links = db.Column(db.Boolean()) # If users can post links
bracket_links = db.Column(db.Boolean()) # If appending brackets to links to prevent embed
mentions_limit = db.Column(db.Integer) # If there is a limit on the number of mentions in a msg
roles = db.Column(db.Text()) # Guild Roles
channels = db.Column(db.Text()) # Guild channels
owner_id = db.Column(db.String(255)) # Snowflake of the owner
@ -15,6 +18,9 @@ class Guilds(db.Model):
self.guild_id = guild_id
self.name = name
self.unauth_users = True # defaults to true
self.chat_links = True
self.bracket_links = True
self.mentions_limit = -1 # -1 = unlimited mentions
self.roles = roles
self.channels = channels
self.owner_id = owner_id

View File

@ -7,6 +7,35 @@ $('#unauth_users').change(function() {
});
});
$('#chat_links').change(function() {
var pathname = window.location.pathname;
var checked = $(this).is(':checked')
var payload = {"chat_links": checked}
$.post(pathname, payload, function(data) {
Materialize.toast('Updated chat links setting!', 2000)
});
});
$('#bracket_links').change(function() {
var pathname = window.location.pathname;
var checked = $(this).is(':checked')
var payload = {"bracket_links": checked}
$.post(pathname, payload, function(data) {
Materialize.toast('Updated embed links setting!', 2000)
});
});
$("#mentions_limit").keyup(function(event){
if(event.keyCode == 13){
var pathname = window.location.pathname;
var value = $("#mentions_limit").val()
var payload = {"mentions_limit": value}
$.post(pathname, payload, function(data) {
Materialize.toast('Updated mentions limit setting!', 2000)
});
}
});
function initiate_ban(guild_id, user_id) {
var reason = prompt("Please enter your reason for ban");
var payload = {

View File

@ -38,6 +38,7 @@
<div class="card horizontal black-text indigo lighten-5 z-depth-3 hoverable">
<div class="card-stacked">
<div class="card-content">
<p class="flow-text">Unauthenticated (Guest) Users</p>
<div class="switch">
<label>
@ -47,6 +48,37 @@
Enable
</label>
</div>
<br>
<p class="flow-text">Chat Links</p>
<div class="switch">
<label>
Disable
<input type="checkbox" id="chat_links" name="chat_links" {% if guild['chat_links'] %}checked{% endif %} >
<span class="lever"></span>
Enable
</label>
</div>
<br>
<p class="flow-text">Render Links as an Embed</p>
<p>(if possible)</p>
<div class="switch">
<label>
Disable
<input type="checkbox" id="bracket_links" name="bracket_links" {% if guild['bracket_links'] %}checked{% endif %} >
<span class="lever"></span>
Enable
</label>
</div>
<br>
<p class="flow-text">Message mentions limit</p>
<p>(-1 to have no limit - enter to submit)</p>
<input id="mentions_limit" type="number" value="{{ guild['mentions_limit'] }}">
</div>
</div>
</div>