Backend support for discordio links and able to edit in admin panel

This commit is contained in:
Jeremy Zhang 2017-06-04 05:31:45 +00:00
parent c76e0a4993
commit 0b96794120
6 changed files with 56 additions and 1 deletions

View File

@ -14,6 +14,7 @@ class Guilds(Base):
emojis = db.Column(db.Text()) # Guild Emojis
owner_id = db.Column(db.String(255)) # Snowflake of the owner
icon = db.Column(db.String(255)) # The icon string, null if none
discordio = db.Column(db.String(255)) # Custom Discord.io Invite Link
def __init__(self, guild_id, name, roles, channels, emojis, owner_id, icon):
self.guild_id = guild_id

View File

@ -0,0 +1,28 @@
"""Modified guilds table for discordio capability
Revision ID: 95ab6a63135d
Revises: 32a4d2d7b85f
Create Date: 2017-06-04 05:06:13.118878
"""
# revision identifiers, used by Alembic.
revision = '95ab6a63135d'
down_revision = '32a4d2d7b85f'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('guilds', sa.Column('discordio', sa.String(length=255), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('guilds', 'discordio')
# ### end Alembic commands ###

View File

@ -178,7 +178,8 @@ def administrate_guild(guild_id):
"chat_links": db_guild.chat_links,
"bracket_links": db_guild.bracket_links,
"mentions_limit": db_guild.mentions_limit,
"icon": db_guild.icon
"icon": db_guild.icon,
"discordio": db_guild.discordio if db_guild.discordio != None else ""
}
return render_template("administrate_guild.html.j2", guild=dbguild_dict, members=users, permissions=permissions)
@ -194,6 +195,11 @@ def update_administrate_guild(guild_id):
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)
discordio = request.form.get("discordio", db_guild.discordio)
if discordio.strip() == "":
discordio = None
db_guild.discordio = discordio
db.session.commit()
return jsonify(
id=db_guild.id,
@ -202,6 +208,7 @@ def update_administrate_guild(guild_id):
chat_links=db_guild.chat_links,
bracket_links=db_guild.bracket_links,
mentions_limit=db_guild.mentions_limit,
discordio=db_guild.discordio,
)
@user.route("/add-bot/<guild_id>")

View File

@ -14,6 +14,7 @@ class Guilds(db.Model):
emojis = db.Column(db.Text(), nullable=False) # Guild Emojis
owner_id = db.Column(db.String(255), nullable=False) # Snowflake of the owner
icon = db.Column(db.String(255)) # The icon string, null if none
discordio = db.Column(db.String(255)) # Custom Discord.io Invite Link
def __init__(self, guild_id, name, roles, channels, emojis, owner_id, icon):
self.guild_id = guild_id

View File

@ -36,6 +36,17 @@ $("#mentions_limit").keyup(function(event){
}
});
$("#discordio").keyup(function(event){
if(event.keyCode == 13){
var pathname = window.location.pathname;
var value = $("#discordio").val()
var payload = {"discordio": value}
$.post(pathname, payload, function(data) {
Materialize.toast('Updated Discord.io setting!', 2000)
});
}
});
function initiate_ban(guild_id, user_id) {
var reason = prompt("Please enter your reason for ban");
var payload = {

View File

@ -79,6 +79,13 @@
<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'] }}">
<br>
<p class="flow-text">Custom Discord.io Link</p>
<p>Because we are a partner with <a href="https://discord.io" target="_blank">Discord.io</a>, we enable you to enter your custom discord.io link and replace the discord.gg link on the embed!</p>
<p>(Leave blank if none - enter to submit)</p>
<input id="discordio" value="{{ guild['discordio'] }}">
</div>
</div>
</div>