Renamed webhook icon to guest icon for preperation of avatars in the client

This commit is contained in:
Jeremy Zhang 2017-09-24 01:22:07 +00:00
parent cb10c35ec9
commit ad833434dd
13 changed files with 90 additions and 60 deletions

View File

@ -8,7 +8,7 @@ class Guilds(Base):
unauth_users = db.Column(db.Boolean()) # If allowed unauth users unauth_users = db.Column(db.Boolean()) # If allowed unauth users
visitor_view = db.Column(db.Boolean()) # If users are automatically "signed in" and can view chat visitor_view = db.Column(db.Boolean()) # If users are automatically "signed in" and can view chat
webhook_messages = db.Column(db.Boolean()) # Use webhooks to send messages instead of the bot webhook_messages = db.Column(db.Boolean()) # Use webhooks to send messages instead of the bot
webhook_icon = db.Column(db.String(255), default=None) # Webhook icon url, None if unset guest_icon = db.Column(db.String(255), default=None) # Guest icon url, None if unset
chat_links = db.Column(db.Boolean()) # If users can post links 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 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 mentions_limit = db.Column(db.Integer) # If there is a limit on the number of mentions in a msg
@ -26,7 +26,7 @@ class Guilds(Base):
self.unauth_users = True # defaults to true self.unauth_users = True # defaults to true
self.visitor_view = False self.visitor_view = False
self.webhook_messages = False self.webhook_messages = False
self.webhook_icon = None self.guest_icon = None
self.chat_links = True self.chat_links = True
self.bracket_links = True self.bracket_links = True
self.mentions_limit = -1 # -1 = unlimited mentions self.mentions_limit = -1 # -1 = unlimited mentions

View File

@ -0,0 +1,30 @@
"""Renamed webhook icon to guest icon
Revision ID: 109a6025e9ec
Revises: 39815dfbcccb
Create Date: 2017-09-24 00:52:44.038589
"""
# revision identifiers, used by Alembic.
revision = '109a6025e9ec'
down_revision = '39815dfbcccb'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('guilds', 'webhook_icon', new_column_name='guest_icon')
op.alter_column('cosmetics', 'webhook_icon', new_column_name='guest_icon')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('guilds', 'guest_icon', new_column_name='webhook_icon')
op.alter_column('cosmetics', 'guest_icon', new_column_name='webhook_icon')
# ### end Alembic commands ###

View File

@ -37,7 +37,7 @@ def cosmetics_post():
abort(400) abort(400)
css = request.form.get("css", None) css = request.form.get("css", None)
css_limit = int(request.form.get("css_limit", 0)) css_limit = int(request.form.get("css_limit", 0))
webhook_icon = request.form.get("webhook_icon", None) guest_icon = request.form.get("guest_icon", None)
entry = db.session.query(Cosmetics).filter(Cosmetics.user_id == user_id).first() entry = db.session.query(Cosmetics).filter(Cosmetics.user_id == user_id).first()
if entry: if entry:
abort(409) abort(409)
@ -47,9 +47,9 @@ def cosmetics_post():
user.css = css user.css = css
if css_limit is not None: if css_limit is not None:
user.css_limit = css_limit user.css_limit = css_limit
if webhook_icon is not None: if guest_icon is not None:
webhook_icon = webhook_icon.lower() == "true" guest_icon = guest_icon.lower() == "true"
user.webhook_icon = webhook_icon user.guest_icon = guest_icon
db.session.add(user) db.session.add(user)
db.session.commit() db.session.commit()
return ('', 204) return ('', 204)
@ -75,7 +75,7 @@ def cosmetics_patch():
abort(400) abort(400)
css = request.form.get("css", None) css = request.form.get("css", None)
css_limit = request.form.get("css_limit", None) css_limit = request.form.get("css_limit", None)
webhook_icon = request.form.get("webhook_icon", None) guest_icon = request.form.get("guest_icon", None)
entry = db.session.query(Cosmetics).filter(Cosmetics.user_id == user_id).first() entry = db.session.query(Cosmetics).filter(Cosmetics.user_id == user_id).first()
if not entry: if not entry:
abort(409) abort(409)
@ -84,9 +84,9 @@ def cosmetics_patch():
entry.css = css entry.css = css
if css_limit is not None: if css_limit is not None:
entry.css_limit = css_limit entry.css_limit = css_limit
if webhook_icon: if guest_icon:
webhook_icon = webhook_icon.lower() == "true" guest_icon = guest_icon.lower() == "true"
entry.webhook_icon = webhook_icon entry.guest_icon = guest_icon
db.session.commit() db.session.commit()
return ('', 204) return ('', 204)
def prepare_guild_members_list(members, bans): def prepare_guild_members_list(members, bans):
@ -156,7 +156,7 @@ def administrate_guild(guild_id):
"mentions_limit": db_guild.mentions_limit, "mentions_limit": db_guild.mentions_limit,
"icon": db_guild.icon, "icon": db_guild.icon,
"discordio": db_guild.discordio if db_guild.discordio != None else "", "discordio": db_guild.discordio if db_guild.discordio != None else "",
"webhook_icon": db_guild.webhook_icon if db_guild.webhook_icon != None else "", "guest_icon": db_guild.guest_icon if db_guild.guest_icon != None else "",
} }
return render_template("administrate_guild.html.j2", guild=dbguild_dict, members=users, permissions=permissions, cosmetics=cosmetics) return render_template("administrate_guild.html.j2", guild=dbguild_dict, members=users, permissions=permissions, cosmetics=cosmetics)
@ -174,10 +174,10 @@ def update_administrate_guild(guild_id):
if discordio != None and discordio.strip() == "": if discordio != None and discordio.strip() == "":
discordio = None discordio = None
db_guild.discordio = discordio db_guild.discordio = discordio
webhook_icon = request.form.get("webhook_icon", db_guild.webhook_icon) guest_icon = request.form.get("guest_icon", db_guild.guest_icon)
if webhook_icon != None and webhook_icon.strip() == "": if guest_icon != None and guest_icon.strip() == "":
webhook_icon = None guest_icon = None
db_guild.webhook_icon = webhook_icon db_guild.guest_icon = guest_icon
db.session.commit() db.session.commit()
return jsonify( return jsonify(
id=db_guild.id, id=db_guild.id,
@ -189,7 +189,7 @@ def update_administrate_guild(guild_id):
bracket_links=db_guild.bracket_links, bracket_links=db_guild.bracket_links,
mentions_limit=db_guild.mentions_limit, mentions_limit=db_guild.mentions_limit,
discordio=db_guild.discordio, discordio=db_guild.discordio,
webhook_icon=db_guild.webhook_icon, guest_icon=db_guild.guest_icon,
) )
@admin.route("/guilds") @admin.route("/guilds")

View File

@ -251,7 +251,7 @@ def post():
avatar = url_for('static', filename='img/titanembeds_square.png', _external=True) avatar = url_for('static', filename='img/titanembeds_square.png', _external=True)
dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first() dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
if dbguild: if dbguild:
icon = dbguild.webhook_icon icon = dbguild.guest_icon
if icon: if icon:
avatar = icon avatar = icon
else: else:

View File

@ -210,7 +210,7 @@ def administrate_guild(guild_id):
"mentions_limit": db_guild.mentions_limit, "mentions_limit": db_guild.mentions_limit,
"icon": db_guild.icon, "icon": db_guild.icon,
"discordio": db_guild.discordio if db_guild.discordio != None else "", "discordio": db_guild.discordio if db_guild.discordio != None else "",
"webhook_icon": db_guild.webhook_icon if db_guild.webhook_icon != None else "", "guest_icon": db_guild.guest_icon if db_guild.guest_icon != None else "",
} }
return render_template("administrate_guild.html.j2", guild=dbguild_dict, members=users, permissions=permissions, cosmetics=cosmetics) return render_template("administrate_guild.html.j2", guild=dbguild_dict, members=users, permissions=permissions, cosmetics=cosmetics)
@ -236,10 +236,10 @@ def update_administrate_guild(guild_id):
discordio = None discordio = None
db_guild.discordio = discordio db_guild.discordio = discordio
webhook_icon = request.form.get("webhook_icon", db_guild.webhook_icon) guest_icon = request.form.get("guest_icon", db_guild.guest_icon)
if webhook_icon != None and webhook_icon.strip() == "": if guest_icon != None and guest_icon.strip() == "":
webhook_icon = None guest_icon = None
db_guild.webhook_icon = webhook_icon db_guild.guest_icon = guest_icon
db.session.commit() db.session.commit()
return jsonify( return jsonify(
@ -252,7 +252,7 @@ def update_administrate_guild(guild_id):
bracket_links=db_guild.bracket_links, bracket_links=db_guild.bracket_links,
mentions_limit=db_guild.mentions_limit, mentions_limit=db_guild.mentions_limit,
discordio=db_guild.discordio, discordio=db_guild.discordio,
webhook_icon=webhook_icon, guest_icon=guest_icon,
) )
@user.route("/add-bot/<guild_id>") @user.route("/add-bot/<guild_id>")
@ -444,9 +444,9 @@ def donate_patch():
entry = db.session.query(Cosmetics).filter(Cosmetics.user_id == session["user_id"]).first() entry = db.session.query(Cosmetics).filter(Cosmetics.user_id == session["user_id"]).first()
if item == "custom_css_slots": if item == "custom_css_slots":
subtract_amt = 100 subtract_amt = 100
if item == "webhook_icon": if item == "guest_icon":
subtract_amt = 300 subtract_amt = 300
if entry is not None and entry.webhook_icon: if entry is not None and entry.guest_icon:
abort(400) abort(400)
amt_change = -1 * subtract_amt * amount amt_change = -1 * subtract_amt * amount
subtract = set_titan_token(session["user_id"], amt_change, "BUY " + item + " x" + str(amount)) subtract = set_titan_token(session["user_id"], amt_change, "BUY " + item + " x" + str(amount))
@ -459,10 +459,10 @@ def donate_patch():
entry.css = True entry.css = True
entry.css_limit = 0 entry.css_limit = 0
entry.css_limit += amount entry.css_limit += amount
if item == "webhook_icon": if item == "guest_icon":
if not entry: if not entry:
entry = Cosmetics(session["user_id"]) entry = Cosmetics(session["user_id"])
entry.webhook_icon = True entry.guest_icon = True
db.session.add(entry) db.session.add(entry)
db.session.commit() db.session.commit()
return ('', 204) return ('', 204)

View File

@ -6,7 +6,7 @@ class Cosmetics(db.Model):
user_id = db.Column(db.String(255), nullable=False) # Discord user id of user of cosmetics user_id = db.Column(db.String(255), nullable=False) # Discord user id of user of cosmetics
css = db.Column(db.Boolean(), nullable=False) # If they can create/edit custom CSS css = db.Column(db.Boolean(), nullable=False) # If they can create/edit custom CSS
css_limit = db.Column(db.Integer, nullable=False, server_default="0") # Custom CSS Limit css_limit = db.Column(db.Integer, nullable=False, server_default="0") # Custom CSS Limit
webhook_icon = db.Column(db.Boolean(), nullable=False, server_default=db.false()) # If they can set the webhook icon for all guilds guest_icon = db.Column(db.Boolean(), nullable=False, server_default=db.false()) # If they can set the guest icon for all guilds
def __init__(self, user_id, **kwargs): def __init__(self, user_id, **kwargs):
self.user_id = user_id self.user_id = user_id
@ -21,7 +21,7 @@ class Cosmetics(db.Model):
else: else:
self.css_limit = 0 self.css_limit = 0
if "webhook_icon" in kwargs: if "guest_icon" in kwargs:
self.webhook_icon = kwargs["webhook_icon"] self.guest_icon = kwargs["guest_icon"]
else: else:
self.webhook_icon = False self.guest_icon = False

View File

@ -8,7 +8,7 @@ class Guilds(db.Model):
unauth_users = db.Column(db.Boolean(), nullable=False, default=1) # If allowed unauth users unauth_users = db.Column(db.Boolean(), nullable=False, default=1) # If allowed unauth users
visitor_view = db.Column(db.Boolean(), nullable=False, default=0) # If users are automatically "signed in" and can view chat visitor_view = db.Column(db.Boolean(), nullable=False, default=0) # If users are automatically "signed in" and can view chat
webhook_messages = db.Column(db.Boolean(), nullable=False, default=0) # Use webhooks to send messages instead of the bot webhook_messages = db.Column(db.Boolean(), nullable=False, default=0) # Use webhooks to send messages instead of the bot
webhook_icon = db.Column(db.String(255), default=None) # Webhook icon url, None if unset guest_icon = db.Column(db.String(255), default=None) # Guest icon url, None if unset
chat_links = db.Column(db.Boolean(), nullable=False, default=1) # If users can post links chat_links = db.Column(db.Boolean(), nullable=False, default=1) # If users can post links
bracket_links = db.Column(db.Boolean(), nullable=False, default=1) # If appending brackets to links to prevent embed bracket_links = db.Column(db.Boolean(), nullable=False, default=1) # If appending brackets to links to prevent embed
mentions_limit = db.Column(db.Integer, nullable=False, default=11) # If there is a limit on the number of mentions in a msg mentions_limit = db.Column(db.Integer, nullable=False, default=11) # If there is a limit on the number of mentions in a msg
@ -26,7 +26,7 @@ class Guilds(db.Model):
self.unauth_users = True # defaults to true self.unauth_users = True # defaults to true
self.visitor_view = False self.visitor_view = False
self.webhook_messages = False self.webhook_messages = False
self.webhook_icon = None self.guest_icon = None
self.chat_links = True self.chat_links = True
self.bracket_links = True self.bracket_links = True
self.mentions_limit = -1 # -1 = unlimited mentions self.mentions_limit = -1 # -1 = unlimited mentions

View File

@ -1,13 +1,13 @@
/* global $, Materialize, location */ /* global $, Materialize, location */
function postForm(user_id, css, css_limit, webhook_icon) { function postForm(user_id, css, css_limit, guest_icon) {
if (css_limit == "") { if (css_limit == "") {
css_limit = 0; css_limit = 0;
} }
var funct = $.ajax({ var funct = $.ajax({
dataType: "json", dataType: "json",
method: "POST", method: "POST",
data: {"user_id": user_id, "css": css, "css_limit": css_limit, "webhook_icon": webhook_icon} data: {"user_id": user_id, "css": css, "css_limit": css_limit, "guest_icon": guest_icon}
}); });
return funct.promise(); return funct.promise();
} }
@ -40,8 +40,8 @@ $(function() {
} }
var css_checked = $("#new_css_switch").is(':checked'); var css_checked = $("#new_css_switch").is(':checked');
var css_limit = $("#new_css_limit").val(); var css_limit = $("#new_css_limit").val();
var webhook_icon_checked = $("#new_webhook_icon_switch").is(':checked'); var guest_icon_checked = $("#new_guest_icon_switch").is(':checked');
var formPost = postForm(user_id, css_checked, css_limit, webhook_icon_checked); var formPost = postForm(user_id, css_checked, css_limit, guest_icon_checked);
formPost.done(function (data) { formPost.done(function (data) {
location.reload(); location.reload();
}); });
@ -101,9 +101,9 @@ function update_css_limit(user_id, value) {
}); });
} }
function update_webhook_icon_switch(user_id, element) { function update_guest_icon_switch(user_id, element) {
var webhook_checked = $(element).is(':checked'); var webhook_checked = $(element).is(':checked');
var formPatch = patchForm(user_id, {"webhook_icon": webhook_checked}); var formPatch = patchForm(user_id, {"guest_icon": webhook_checked});
formPatch.done(function (data) { formPatch.done(function (data) {
Materialize.toast('Webhook Icon updated!', 10000); Materialize.toast('Webhook Icon updated!', 10000);
}); });

View File

@ -65,13 +65,13 @@ $("#discordio").keyup(function(event){
} }
}); });
$("#webhook_icon").keyup(function(event){ $("#guest_icon").keyup(function(event){
if(event.keyCode == 13){ if(event.keyCode == 13){
var pathname = window.location.pathname; var pathname = window.location.pathname;
var value = $("#webhook_icon").val() var value = $("#guest_icon").val()
var payload = {"webhook_icon": value} var payload = {"guest_icon": value}
$.post(pathname, payload, function(data) { $.post(pathname, payload, function(data) {
Materialize.toast('Updated Webhook Icon setting!', 2000) Materialize.toast('Updated Guest Icon setting!', 2000)
}); });
} }
}); });

View File

@ -47,10 +47,10 @@
}); });
}); });
$("#buy-webhook-guest-user-avatar-btn").click(function () { $("#buy-guest-user-avatar-btn").click(function () {
var formPatch = patchForm("webhook_icon", 1); var formPatch = patchForm("guest_icon", 1);
formPatch.done(function (data) { formPatch.done(function (data) {
alert("Successfully bought webhook guest user avatar perk!"); alert("Successfully bought guest user avatar perk!");
location.reload(); location.reload();
}); });
formPatch.fail(function (data) { formPatch.fail(function (data) {
@ -59,7 +59,7 @@
} else if (data.status == 402) { } else if (data.status == 402) {
Materialize.toast('Insufficient token funds!', 10000); Materialize.toast('Insufficient token funds!', 10000);
} else { } else {
Materialize.toast('Purchasing webhook guest user avatar perk failed!', 10000); Materialize.toast('Purchasing guest user avatar perk failed!', 10000);
} }
}); });
}); });

View File

@ -14,7 +14,7 @@
<th>User ID</th> <th>User ID</th>
<th>CSS</th> <th>CSS</th>
<th>CSS Limit</th> <th>CSS Limit</th>
<th>Webhook Icon</th> <th>Guest Icon</th>
<th>Submit</th> <th>Submit</th>
</tr> </tr>
</thead> </thead>
@ -44,7 +44,7 @@
<div class="switch"> <div class="switch">
<label> <label>
Off Off
<input type="checkbox" id="new_webhook_icon_switch"> <input type="checkbox" id="new_guest_icon_switch">
<span class="lever"></span> <span class="lever"></span>
On On
</label> </label>
@ -68,7 +68,7 @@
<th>User ID</th> <th>User ID</th>
<th>CSS</th> <th>CSS</th>
<th>CSS Limit</th> <th>CSS Limit</th>
<th>Webhook Icon</th> <th>Guest Icon</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -95,7 +95,7 @@
<div class="switch"> <div class="switch">
<label> <label>
Off Off
<input type="checkbox" {% if cosmetic.webhook_icon %}checked{% endif %} onchange="update_webhook_icon_switch('{{ cosmetic.user_id }}', this)"> <input type="checkbox" {% if cosmetic.guest_icon %}checked{% endif %} onchange="update_guest_icon_switch('{{ cosmetic.user_id }}', this)">
<span class="lever"></span> <span class="lever"></span>
On On
</label> </label>

View File

@ -115,13 +115,13 @@
<br> <br>
<p class="flow-text">Webhook Guest User Avatar URL</p> <p class="flow-text">Guest User Avatar URL</p>
<p>If enabled Webhook Messages, you may set it so that the guest users may have a custom avatar instead of the Titan logo. Source must be the permanent URL location to the image file (try imgur and get direct link to image).</p> <p>Guest users may have a custom avatar instead of the Titan logo. Source must be the permanent URL location to the image file (try imgur and get direct link to image).</p>
<p>(Leave blank if none - enter to submit)</p> <p>(Leave blank if none - enter to submit)</p>
{% if not cosmetics.webhook_icon %} {% if not cosmetics.guest_icon %}
<p class="red lighten-4"><strong>Your user account does not have access to change webhook avatar url. Please visit the Titan Tokens shop to activate this cosmetic item.</strong></p> <p class="red lighten-4"><strong>Your user account does not have access to change guest avatar url. Please visit the Titan Tokens shop to activate this cosmetic item.</strong></p>
{% endif %} {% endif %}
<input id="webhook_icon" value="{{ guild['webhook_icon'] }}" {% if not cosmetics.webhook_icon %}disabled{% endif %}> <input id="guest_icon" value="{{ guild['guest_icon'] }}" {% if not cosmetics.guest_icon %}disabled{% endif %}>
</div> </div>
</div> </div>
</div> </div>

View File

@ -47,10 +47,10 @@
</div> </div>
<div class="col s12"> <div class="col s12">
<div class="card-panel indigo lighten-5 z-depth-3 hoverable black-text"> <div class="card-panel indigo lighten-5 z-depth-3 hoverable black-text">
<h4>Webhook Guest User Avatar <strong>[300 tokens]</strong></h4> <h4>Guest User Avatar <strong>[300 tokens]</strong></h4>
<p class="flow-text">Tired of the bland Titan logo for your guests avatars in your servers? Enables your account to be able to set webhook icons for guests for all servers you can manage.</p> <p class="flow-text">Tired of the bland Titan logo for your guests avatars in your servers? Enables your account to be able to set icons for guests on all servers you can manage.</p>
<p>(Note: Webhook Messages has to be enabled & Titan needs server permissions to create webhooks)</p> <p>(Note: Webhook Messages has to be enabled to be displayed in Discord; Titan needs server permissions to create webhooks)</p>
<a class="waves-effect waves-light btn" id="buy-webhook-guest-user-avatar-btn" {% if cosmetics.webhook_icon %}disabled{% endif %}>{% if cosmetics.webhook_icon %}Already Purchased{% else %}Buy{% endif %}</a> <a class="waves-effect waves-light btn" id="buy-guest-user-avatar-btn" {% if cosmetics.guest_icon %}disabled{% endif %}>{% if cosmetics.guest_icon %}Already Purchased{% else %}Buy{% endif %}</a>
</div> </div>
</div> </div>
</div> </div>