From 30092fde01827c3d1ad470f4e8347c37693f38fe Mon Sep 17 00:00:00 2001
From: Jeremy Zhang
Date: Fri, 9 Jun 2017 04:22:33 +0000
Subject: [PATCH 001/135] Implemented Visitor View -- kinda betaish still
---
discordbot/titanembeds/database/guilds.py | 2 +
...2e_added_visitor_view_column_to_guilds_.py | 28 +++++
webapp/titanembeds/blueprints/api/api.py | 60 +++++++--
webapp/titanembeds/blueprints/embed/embed.py | 3 +-
webapp/titanembeds/blueprints/user/user.py | 2 +
webapp/titanembeds/database/guilds.py | 2 +
webapp/titanembeds/static/css/embedstyle.css | 114 ++++++++++++------
.../static/js/administrate_guild.js | 9 ++
webapp/titanembeds/static/js/embed.js | 62 +++++++++-
.../templates/administrate_guild.html.j2 | 13 ++
webapp/titanembeds/templates/embed.html.j2 | 6 +-
webapp/titanembeds/utils.py | 4 +
12 files changed, 245 insertions(+), 60 deletions(-)
create mode 100644 webapp/alembic/versions/b1124468bb2e_added_visitor_view_column_to_guilds_.py
diff --git a/discordbot/titanembeds/database/guilds.py b/discordbot/titanembeds/database/guilds.py
index a73ccb0..54dfe69 100644
--- a/discordbot/titanembeds/database/guilds.py
+++ b/discordbot/titanembeds/database/guilds.py
@@ -6,6 +6,7 @@ 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
+ visitor_view = db.Column(db.Boolean()) # If users are automatically "signed in" and can view chat
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
@@ -20,6 +21,7 @@ class Guilds(Base):
self.guild_id = guild_id
self.name = name
self.unauth_users = True # defaults to true
+ self.visitor_view = False
self.chat_links = True
self.bracket_links = True
self.mentions_limit = -1 # -1 = unlimited mentions
diff --git a/webapp/alembic/versions/b1124468bb2e_added_visitor_view_column_to_guilds_.py b/webapp/alembic/versions/b1124468bb2e_added_visitor_view_column_to_guilds_.py
new file mode 100644
index 0000000..f0f4d69
--- /dev/null
+++ b/webapp/alembic/versions/b1124468bb2e_added_visitor_view_column_to_guilds_.py
@@ -0,0 +1,28 @@
+"""Added visitor view column to guilds table
+
+Revision ID: b1124468bb2e
+Revises: 95ab6a63135d
+Create Date: 2017-06-08 06:31:28.953304
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'b1124468bb2e'
+down_revision = '95ab6a63135d'
+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('visitor_view', sa.Boolean(), nullable=False))
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.drop_column('guilds', 'visitor_view')
+ # ### end Alembic commands ###
diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py
index 847a613..4ba5aba 100644
--- a/webapp/titanembeds/blueprints/api/api.py
+++ b/webapp/titanembeds/blueprints/api/api.py
@@ -1,6 +1,6 @@
from titanembeds.database import db, Guilds, UnauthenticatedUsers, UnauthenticatedBans, AuthenticatedUsers, KeyValueProperties, GuildMembers, Messages, get_channel_messages, list_all_guild_members
from titanembeds.decorators import valid_session_required, discord_users_only
-from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key
+from titanembeds.utils import check_guild_existance, guild_accepts_visitors, guild_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key
from titanembeds.oauth import user_has_permission, generate_avatar_url, check_user_can_administrate_guild
from flask import Blueprint, abort, jsonify, session, request
from sqlalchemy import and_
@@ -162,8 +162,8 @@ def get_dbguild_channels(guild_id):
q = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
return json.loads(q.channels)
-def get_guild_channels(guild_id):
- if user_unauthenticated():
+def get_guild_channels(guild_id, force_everyone=False):
+ if user_unauthenticated() or force_everyone:
member_roles = [guild_id] #equivilant to @everyone role
else:
member_roles = get_member_roles(guild_id, session['user_id'])
@@ -177,7 +177,7 @@ def get_guild_channels(guild_id):
for channel in guild_channels:
if channel['type'] == "text":
result = {"channel": channel, "read": False, "write": False, "mention_everyone": False}
- if guild_owner == session['user_id']:
+ if guild_owner == session.get("user_id"):
result["read"] = True
result["write"] = True
result["mention_everyone"] = True
@@ -219,7 +219,7 @@ def get_guild_channels(guild_id):
# member specific
for overwrite in channel["permission_overwrites"]:
- if overwrite["type"] == "member" and overwrite["id"] == session["user_id"]:
+ if overwrite["type"] == "member" and overwrite["id"] == session.get("user_id"):
channel_perm = (channel_perm & ~overwrite['deny']) | overwrite['allow']
break
@@ -240,8 +240,8 @@ def get_guild_channels(guild_id):
result_channels.append(result)
return sorted(result_channels, key=lambda k: k['channel']['position'])
-def filter_guild_channel(guild_id, channel_id):
- channels = get_guild_channels(guild_id)
+def filter_guild_channel(guild_id, channel_id, force_everyone=False):
+ channels = get_guild_channels(guild_id, force_everyone)
for chan in channels:
if chan["channel"]["id"] == channel_id:
return chan
@@ -327,6 +327,25 @@ def fetch():
response.status_code = status_code
return response
+@api.route("/fetch_visitor", methods=["GET"])
+@rate_limiter.limit("2 per 2 second", key_func = channel_ratelimit_key)
+def fetch_visitor():
+ guild_id = request.args.get("guild_id")
+ channel_id = request.args.get('channel_id')
+ after_snowflake = request.args.get('after', None, type=int)
+ if not guild_accepts_visitors(guild_id):
+ abort(403)
+ messages = {}
+ chan = filter_guild_channel(guild_id, channel_id, True)
+ if not chan.get("read"):
+ status_code = 401
+ else:
+ messages = get_channel_messages(channel_id, after_snowflake)
+ status_code = 200
+ response = jsonify(messages=messages)
+ response.status_code = status_code
+ return response
+
@api.route("/post", methods=["POST"])
@valid_session_required(api=True)
@rate_limiter.limit("1 per 10 second", key_func = channel_ratelimit_key)
@@ -393,21 +412,36 @@ def create_unauthenticated_user():
response.status_code = 403
return response
+def process_query_guild(guild_id, visitor=False):
+ widget = discord_api.get_widget(guild_id)
+ channels = get_guild_channels(guild_id, visitor)
+ discordmembers = get_online_discord_users(guild_id, widget)
+ embedmembers = get_online_embed_users(guild_id)
+ emojis = get_guild_emojis(guild_id)
+ if visitor:
+ for channel in channels:
+ channel["write"] = False
+ return jsonify(channels=channels, discordmembers=discordmembers, embedmembers=embedmembers, emojis=emojis, instant_invite=widget.get("instant_invite"))
+
@api.route("/query_guild", methods=["GET"])
@valid_session_required(api=True)
def query_guild():
guild_id = request.args.get('guild_id')
if check_guild_existance(guild_id):
if check_user_in_guild(guild_id):
- widget = discord_api.get_widget(guild_id)
- channels = get_guild_channels(guild_id)
- discordmembers = get_online_discord_users(guild_id, widget)
- embedmembers = get_online_embed_users(guild_id)
- emojis = get_guild_emojis(guild_id)
- return jsonify(channels=channels, discordmembers=discordmembers, embedmembers=embedmembers, emojis=emojis, instant_invite=widget.get("instant_invite"))
+ return process_query_guild(guild_id)
abort(403)
abort(404)
+@api.route("/query_guild_visitor", methods=["GET"])
+def query_guild_visitor():
+ guild_id = request.args.get('guild_id')
+ if check_guild_existance(guild_id):
+ if not guild_accepts_visitors(guild_id):
+ abort(403)
+ return process_query_guild(guild_id, True)
+ abort(404)
+
@api.route("/create_authenticated_user", methods=["POST"])
@discord_users_only(api=True)
def create_authenticated_user():
diff --git a/webapp/titanembeds/blueprints/embed/embed.py b/webapp/titanembeds/blueprints/embed/embed.py
index 8d3f2dd..12560d2 100644
--- a/webapp/titanembeds/blueprints/embed/embed.py
+++ b/webapp/titanembeds/blueprints/embed/embed.py
@@ -1,5 +1,5 @@
from flask import Blueprint, render_template, abort, redirect, url_for, session, request
-from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool
+from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool, guild_accepts_visitors
from titanembeds.oauth import generate_guild_icon_url, generate_avatar_url
from titanembeds.database import db, Guilds, UserCSS
from config import config
@@ -42,6 +42,7 @@ def guild_embed(guild_id):
guild_id=guild_id, guild=guild_dict,
generate_guild_icon=generate_guild_icon_url,
unauth_enabled=guild_query_unauth_users_bool(guild_id),
+ visitors_enabled=guild_accepts_visitors(guild_id),
client_id=config['client-id'],
css=get_custom_css()
)
diff --git a/webapp/titanembeds/blueprints/user/user.py b/webapp/titanembeds/blueprints/user/user.py
index 558a3bb..21ed408 100644
--- a/webapp/titanembeds/blueprints/user/user.py
+++ b/webapp/titanembeds/blueprints/user/user.py
@@ -175,6 +175,7 @@ def administrate_guild(guild_id):
"id": db_guild.guild_id,
"name": db_guild.name,
"unauth_users": db_guild.unauth_users,
+ "visitor_view": db_guild.visitor_view,
"chat_links": db_guild.chat_links,
"bracket_links": db_guild.bracket_links,
"mentions_limit": db_guild.mentions_limit,
@@ -192,6 +193,7 @@ 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.visitor_view = request.form.get("visitor_view", db_guild.visitor_view) 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)
diff --git a/webapp/titanembeds/database/guilds.py b/webapp/titanembeds/database/guilds.py
index 934bf6a..db086e9 100644
--- a/webapp/titanembeds/database/guilds.py
+++ b/webapp/titanembeds/database/guilds.py
@@ -6,6 +6,7 @@ class Guilds(db.Model):
guild_id = db.Column(db.String(255), nullable=False) # Discord guild id
name = db.Column(db.String(255), nullable=False) # Name
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
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
mentions_limit = db.Column(db.Integer, nullable=False, default=11) # If there is a limit on the number of mentions in a msg
@@ -20,6 +21,7 @@ class Guilds(db.Model):
self.guild_id = guild_id
self.name = name
self.unauth_users = True # defaults to true
+ self.visitor_view = False
self.chat_links = True
self.bracket_links = True
self.mentions_limit = -1 # -1 = unlimited mentions
diff --git a/webapp/titanembeds/static/css/embedstyle.css b/webapp/titanembeds/static/css/embedstyle.css
index 85d2382..21ede8a 100644
--- a/webapp/titanembeds/static/css/embedstyle.css
+++ b/webapp/titanembeds/static/css/embedstyle.css
@@ -233,6 +233,14 @@ a {
#nameplate {
cursor: pointer;
}
+
+#visitor_mode_message {
+ margin-right: auto;
+ margin-left: auto;
+ display: block;
+ width: 305px;
+}
+
@font-face {
font-family: Whitney;
font-style: light;
@@ -261,53 +269,79 @@ a {
src: url("../fonts/whitney_bold.woff") format("woff")
}
* {
-font-family: Whitney, Helvetica Neue, Helvetica, Arial, sans-serif;
+ font-family: Whitney, Helvetica Neue, Helvetica, Arial, sans-serif;
}
#footercontainer {
-border-radius:20px;
-border: 1px solid rgb(99,99,99);
-margin-left:-0px!important;
-padding-left:-4px!important;
+ border-radius: 20px;
+ border: 1px solid rgb(99, 99, 99);
+ margin-left: -0px!important;
+ padding-left: -4px!important;
}
#nameplate {
-background:transparent!important;
-margin-left:10px
+ background: transparent!important;
+ margin-left: 10px
}
#chatcontent > p > span.chatusername,
#curuser_discrim,
#curuser_name {
-display:block
+ display: block
}
#curuser_discrim {
-font-size:50%;
+ font-size: 50%;
}
#curuser_discrim,
#curuser_name {
-margin-top:-2px
+ margin-top: -2px
}
#currentuserimage {
-margin-top:4px;
-margin-right:4px
+ margin-top: 4px;
+ margin-right: 4px
+}
+#chatcontent > p {
+ display: table;
+}
+#chatcontent > p > span {
+ display: table-row
+}
+#chatcontent > p > span.chatusername {
+ display: table-header-group
+}
+#chatcontent > p > span.chatmessage {
+ display: table-footer-group;
+ display: inline-block!important;
+ color: rgb(195, 196, 197)
+}
+::-webkit-input-placeholder {
+ color: rgb(99, 99, 99)
+}
+:-moz-placeholder {
+ color: rgb(99, 99, 99)
+}
+::-moz-placeholder {
+ color: rgb(99, 99, 99)
+}
+:-ms-input-placeholder {
+ color: rgb(99, 99, 99)
+}
+::-ms-input-placeholder {
+ color: rgb(99, 99, 99)
}
-#chatcontent > p { display: table; }
-#chatcontent > p > span { display: table-row }
-#chatcontent > p > span.chatusername { display: table-header-group }
-#chatcontent > p > span.chatmessage { display: table-footer-group;display:inline-block!important;color:rgb(195,196,197) }
-::-webkit-input-placeholder { color:rgb(99,99,99) }
-:-moz-placeholder { color:rgb(99,99,99) }
-::-moz-placeholder { color:rgb(99,99,99) }
-:-ms-input-placeholder { color:rgb(99,99,99) }
-::-ms-input-placeholder { color:rgb(99,99,99) }
body > div.navbar-fixed > nav > div {
-background:#263238
- background: -webkit-linear-gradient(#263238, #37474f, #455a64); /* For Safari 5.1 to 6.0 */
- background: -o-linear-gradient(#263238, #37474f, #455a64); /* For Opera 11.1 to 12.0 */
- background: -moz-linear-gradient(#263238, #37474f, #455a64); /* For Firefox 3.6 to 15 */
- background: linear-gradient(#263238, #37474f, #455a64); /* Standard syntax */
+ background: #263238 background: -webkit-linear-gradient(#263238, #37474f, #455a64);
+ /* For Safari 5.1 to 6.0 */
+
+ background: -o-linear-gradient(#263238, #37474f, #455a64);
+ /* For Opera 11.1 to 12.0 */
+
+ background: -moz-linear-gradient(#263238, #37474f, #455a64);
+ /* For Firefox 3.6 to 15 */
+
+ background: linear-gradient(#263238, #37474f, #455a64);
+ /* Standard syntax */
}
div.divider {
-margin-left:10px;
-margin-right:10px;
+ margin-left: 10px;
+ margin-right: 10px;
}
#discord-members > li > a.subheader,
#members-nav > li:nth-child(1) > a,
@@ -316,21 +350,21 @@ margin-right:10px;
#members-nav > li:nth-child(4) > a,
#guest-members-count,
#members-nav > li:nth-child(6) > a {
-text-transform: uppercase;
+ text-transform: uppercase;
+}
+#members-btn > i {
+ visibility: hidden
}
-#members-btn > i { visibility:hidden }
#members-btn {
-visibility:visible;
-background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNiIgaGVpZ2h0PSIyNiI+CiAgPGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj4KICAgIDxwYXRoIGQ9Ik0xIDFoMjR2MjRIMVYxeiIvPgogICAgPHBhdGggZmlsbD0iI0ZGRiIgZD0iTTE2Ljc3MjA3NTQgMTQuNjc5MTc3OGMtLjIyNDkwOTctLjIyNTY4ODYtLjQ3NDE1NzMtLjQzNTE2ODEtLjc0MjA3NTQtLjYyOTE3NzguMzUtLjAzLjY4LS4wNS45Ny0uMDUgMi4zMyAwIDcgMS4xNyA3IDMuNVYyMGgtNHYtMWMwLTEuODgxNjkxNC0xLjQwNzcwNTYtMy4zMjMwMTQzLTMuMjI3OTI0Ni00LjMyMDgyMjJ6bS0xLjQzODU3MzUtOC4xNzU4NTM0QzE1LjgwOTgwODIgNi4xODUyNTE3MyAxNi4zODI3ODQ1IDYgMTcgNmMxLjY2IDAgMi45OSAxLjM0IDIuOTkgM3MtMS4zMyAzLTIuOTkgM2MtLjYxNzE5MTQgMC0xLjE5MDE0NzEtLjE4NTIzNzMtMS42NjY0NDIzLS41MDMyODcyQzE1Ljc1NzQ4MzIgMTAuNzYyMTQwOTUgMTYgOS45MDk1NTYgMTYgOS4wMDAwNjY5M2MwLS45MDk1Mjg5Ni0uMjQyNTM4MS0xLjc2MjE0ODgtLjY2NjQ5ODEtMi40OTY3NDI1M3pNMTAgMTNjMi4yMSAwIDQtMS43OSA0LTRzLTEuNzktNC00LTQtNCAxLjc5LTQgNCAxLjc5IDQgNCA0em0wIDJjLTIuNjcgMC04IDEuMzQtOCA0djJoMTZ2LTJjMC0yLjY2LTUuMzMtNC04LTR6Ii8+CiAgPC9nPgo8L3N2Zz4=);
-background-repeat:no-repeat;
-margin-top:18px
+ visibility: visible;
+ background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNiIgaGVpZ2h0PSIyNiI+CiAgPGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj4KICAgIDxwYXRoIGQ9Ik0xIDFoMjR2MjRIMVYxeiIvPgogICAgPHBhdGggZmlsbD0iI0ZGRiIgZD0iTTE2Ljc3MjA3NTQgMTQuNjc5MTc3OGMtLjIyNDkwOTctLjIyNTY4ODYtLjQ3NDE1NzMtLjQzNTE2ODEtLjc0MjA3NTQtLjYyOTE3NzguMzUtLjAzLjY4LS4wNS45Ny0uMDUgMi4zMyAwIDcgMS4xNyA3IDMuNVYyMGgtNHYtMWMwLTEuODgxNjkxNC0xLjQwNzcwNTYtMy4zMjMwMTQzLTMuMjI3OTI0Ni00LjMyMDgyMjJ6bS0xLjQzODU3MzUtOC4xNzU4NTM0QzE1LjgwOTgwODIgNi4xODUyNTE3MyAxNi4zODI3ODQ1IDYgMTcgNmMxLjY2IDAgMi45OSAxLjM0IDIuOTkgM3MtMS4zMyAzLTIuOTkgM2MtLjYxNzE5MTQgMC0xLjE5MDE0NzEtLjE4NTIzNzMtMS42NjY0NDIzLS41MDMyODcyQzE1Ljc1NzQ4MzIgMTAuNzYyMTQwOTUgMTYgOS45MDk1NTYgMTYgOS4wMDAwNjY5M2MwLS45MDk1Mjg5Ni0uMjQyNTM4MS0xLjc2MjE0ODgtLjY2NjQ5ODEtMi40OTY3NDI1M3pNMTAgMTNjMi4yMSAwIDQtMS43OSA0LTRzLTEuNzktNC00LTQtNCAxLjc5LTQgNCAxLjc5IDQgNCA0em0wIDJjLTIuNjcgMC04IDEuMzQtOCA0djJoMTZ2LTJjMC0yLjY2LTUuMzMtNC04LTR6Ii8+CiAgPC9nPgo8L3N2Zz4=);
+ background-repeat: no-repeat;
+ margin-top: 18px
}
.circle:hover {
-border-radius:20px;
-background: linear-gradient(to right, #f9f9f9 90%, #fff);
+ border-radius: 20px;
+ background: linear-gradient(to right, #f9f9f9 90%, #fff);
}
#channels-list > li:hover {
--webkit-filter: brightness(150%);
-}
-#loginmodal {
-}
+ -webkit-filter: brightness(150%);
+}
\ No newline at end of file
diff --git a/webapp/titanembeds/static/js/administrate_guild.js b/webapp/titanembeds/static/js/administrate_guild.js
index d689ceb..78c3b1b 100644
--- a/webapp/titanembeds/static/js/administrate_guild.js
+++ b/webapp/titanembeds/static/js/administrate_guild.js
@@ -7,6 +7,15 @@ $('#unauth_users').change(function() {
});
});
+$('#visitor_view').change(function() {
+ var pathname = window.location.pathname;
+ var checked = $(this).is(':checked')
+ var payload = {"visitor_view": checked}
+ $.post(pathname, payload, function(data) {
+ Materialize.toast('Updated visitor mode setting!', 2000)
+ });
+});
+
$('#chat_links').change(function() {
var pathname = window.location.pathname;
var checked = $(this).is(':checked')
diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js
index 47cf570..8b07f20 100644
--- a/webapp/titanembeds/static/js/embed.js
+++ b/webapp/titanembeds/static/js/embed.js
@@ -5,6 +5,7 @@
/* global bot_client_id */
/* global moment */
/* global localStorage */
+/* global visitors_enabled */
(function () {
const theme_options = ["DiscordDark", "BetterTitan"]; // All the avaliable theming names
@@ -21,6 +22,7 @@
var fetch_error_count = 0; // Number of errors fetch has encountered
var priority_query_guild = false; // So you have selected a channel? Let's populate it.
var current_username_discrim; // Current username/discrim pair, eg EndenDraogn#4151
+ var visitor_mode = false; // Keep track of if using the visitor mode or authenticate mode
function element_in_view(element, fullyInView) {
var pageTop = $(window).scrollTop();
@@ -36,9 +38,13 @@
}
function query_guild() {
+ var url = "/api/query_guild";
+ if (visitor_mode) {
+ url = url += "_visitor";
+ }
var funct = $.ajax({
dataType: "json",
- url: "/api/query_guild",
+ url: url,
data: {"guild_id": guild_id}
});
return funct.promise();
@@ -65,10 +71,14 @@
}
function fetch(channel_id, after=null) {
+ var url = "/api/fetch";
+ if (visitor_mode) {
+ url += "_visitor";
+ }
var funct = $.ajax({
method: "GET",
dataType: "json",
- url: "/api/fetch",
+ url: url,
data: {"guild_id": guild_id,"channel_id": channel_id, "after": after}
});
return funct.promise();
@@ -118,6 +128,10 @@
$("#userembedmodal").modal("open");
});
+ $("#visitor_login_btn").click(function () {
+ $("#loginmodal").modal("open");
+ });
+
$( "#theme-selector" ).change(function() {
var theme = $("#theme-selector option:selected").val();
changeTheme(theme);
@@ -171,6 +185,20 @@
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
+
+ function setVisitorMode(enabled) {
+ if (!visitors_enabled) {
+ return;
+ }
+ visitor_mode = enabled;
+ if (visitor_mode) {
+ $("#visitor_mode_message").show();
+ $("#messagebox").hide();
+ } else {
+ $("#visitor_mode_message").hide();
+ $("#messagebox").show();
+ }
+ }
function primeEmbed() {
$("#focusmodal").modal("close");
@@ -181,8 +209,10 @@
$("#modal_invite_btn").attr("href", data.instant_invite);
});
+ var login_modal_dismissible = visitors_enabled;
+
$("#loginmodal").modal({
- dismissible: false, // Modal can be dismissed by clicking outside of the modal
+ dismissible: login_modal_dismissible, // Modal can be dismissed by clicking outside of the modal
opacity: .5, // Opacity of modal background
inDuration: 300, // Transition in duration
outDuration: 200, // Transition out duration
@@ -196,6 +226,16 @@
var guild = query_guild();
guild.fail(function() {
unlock_login_fields();
+ if (visitors_enabled) {
+ setVisitorMode(true);
+ var guild2 = query_guild();
+ guild2.done(function(data) {
+ initialize_embed(data);
+ });
+ guild2.fail(function() {
+ setVisitorMode(false);
+ });
+ }
});
guild.done(function(data) {
@@ -375,12 +415,14 @@
setTimeout(function() {
var usr = create_authenticated_user();
usr.done(function(data) {
+ setVisitorMode(false);
initialize_embed();
return;
});
usr.fail(function(data) {
if (data.status == 403) {
Materialize.toast('Authentication error! You have been banned.', 10000);
+ setVisitorMode(true);
} else if (index < 10) {
_wait_for_discord_login(index + 1);
}
@@ -524,9 +566,13 @@
}
fet.done(function(data) {
var status = data.status;
- update_embed_userchip(status.authenticated, status.avatar, status.username, status.user_id, status.discriminator);
+ if (visitor_mode) {
+ update_embed_userchip(false, null, "Titan", "0001", null);
+ } else {
+ update_embed_userchip(status.authenticated, status.avatar, status.username, status.user_id, status.discriminator);
+ }
last_message_id = fill_discord_messages(data.messages, jumpscroll);
- if (status.manage_embed) {
+ if (!visitor_mode && status.manage_embed) {
$("#administrate_link").show();
} else {
$("#administrate_link").hide();
@@ -554,6 +600,10 @@
$('#loginmodal').modal('open');
Materialize.toast('Session expired! You have been logged out.', 10000);
}
+ setVisitorMode(true);
+ if (visitor_mode) {
+ fetchtimeout = setTimeout(run_fetch_routine, 5000);
+ }
});
fet.catch(function(data) {
if (500 <= data.status && data.status < 600) {
@@ -600,6 +650,7 @@
lock_login_fields();
var usr = create_unauthenticated_user($(this).val());
usr.done(function(data) {
+ setVisitorMode(false);
initialize_embed();
});
usr.fail(function(data) {
@@ -611,6 +662,7 @@
Materialize.toast('Illegal username provided! Only alphanumeric, spaces, dashes, and underscores allowed in usernames.', 10000);
}
unlock_login_fields();
+ setVisitorMode(true);
});
}
}
diff --git a/webapp/titanembeds/templates/administrate_guild.html.j2 b/webapp/titanembeds/templates/administrate_guild.html.j2
index 438a08d..bdc2868 100644
--- a/webapp/titanembeds/templates/administrate_guild.html.j2
+++ b/webapp/titanembeds/templates/administrate_guild.html.j2
@@ -48,6 +48,19 @@
Enable
+
+
+
+
Toggle Visitor Mode
+
Visitors are able to view the channels that @everyone has access to. However, they are not able to send messages until they login using the usual methods.
{% endblock %}
From c7abae4b7abac7636584b2dd1124858fa47e6378 Mon Sep 17 00:00:00 2001
From: Jeremy Zhang
Date: Sat, 22 Jul 2017 22:09:35 +0000
Subject: [PATCH 035/135] List of all query params card and show the cards in
guild administration page
---
webapp/titanembeds/templates/about.html.j2 | 21 ++------
.../templates/administrate_guild.html.j2 | 5 ++
.../templates/card_commands.html.j2 | 18 +++++++
.../templates/card_queryparams.html.j2 | 50 +++++++++++++++++++
4 files changed, 76 insertions(+), 18 deletions(-)
create mode 100644 webapp/titanembeds/templates/card_commands.html.j2
create mode 100644 webapp/titanembeds/templates/card_queryparams.html.j2
diff --git a/webapp/titanembeds/templates/about.html.j2 b/webapp/titanembeds/templates/about.html.j2
index baeaf0e..f34d2aa 100644
--- a/webapp/titanembeds/templates/about.html.j2
+++ b/webapp/titanembeds/templates/about.html.j2
@@ -40,24 +40,9 @@ used to replace Discord itself. (that's what the mobile apps are for!)
It is used in conjunction for a quick and dirty Discord embed for websites. Some uses include forum shoutboxes,
etc.
-
Commands
-
-
-
-
-
-
All commands start by mentioning the bot user, @Titan.
-
Guest User Moderation
-
All guest users are denoted by square brackets around their username in the Discord channel, when sending messages.
-
-
ban <username-query>[#<discriminator>] Bans the user by the username. The username does not need to be the full string. The discriminator is optional. Eg: ban Titan#0001
-
kick <username-query>[#<discriminator>] Kicks the user by the username. The username does not need to be the full string. The discriminator is optional. Eg: kick Titan#0001
-
-
-
-
-
-
+{% include 'card_commands.html.j2' %}
+
+{% include 'card_queryparams.html.j2' %}
+
+{% include 'card_commands.html.j2' %}
+
+{% include 'card_queryparams.html.j2' %}
+
{% endblock %}
{% block script %}
diff --git a/webapp/titanembeds/templates/card_commands.html.j2 b/webapp/titanembeds/templates/card_commands.html.j2
new file mode 100644
index 0000000..30e4af9
--- /dev/null
+++ b/webapp/titanembeds/templates/card_commands.html.j2
@@ -0,0 +1,18 @@
+
Commands
+
+
+
+
+
+
All commands start by mentioning the bot user, @Titan.
+
Guest User Moderation
+
All guest users are denoted by square brackets around their username in the Discord channel, when sending messages.
+
+
ban <username-query>[#<discriminator>] Bans the user by the username. The username does not need to be the full string. The discriminator is optional. Eg: ban Titan#0001
+
kick <username-query>[#<discriminator>] Kicks the user by the username. The username does not need to be the full string. The discriminator is optional. Eg: kick Titan#0001
+
+
+
+
+
+
\ No newline at end of file
diff --git a/webapp/titanembeds/templates/card_queryparams.html.j2 b/webapp/titanembeds/templates/card_queryparams.html.j2
new file mode 100644
index 0000000..d4e7bbd
--- /dev/null
+++ b/webapp/titanembeds/templates/card_queryparams.html.j2
@@ -0,0 +1,50 @@
+
Query Parameters
+
+
+
+
+
+
Use query parameters to customize your individual embeds out of this world!
+
Query parameters are in the format of key-value pairs. They are appended after your embed url such that it would look like so: https://titanembeds.tk/embed/1234567890?css=1&theme=DiscordDark&forcefocus=1
+
Below is the reference of all the avaliable query parameters that may be used.
+
+
+ css=<integer>
+ Styles the embed's theme according to the unique custom CSS ID. Custom CSS may be managed from the user dashboard page.
+ Eg: css=1
+
+
+ defaultchannel=<snowflake>
+ Instead of having your #general channel as the first channel your users see, you may change it. Enable Discord's Developer mode in the Appearances tab of the User Settings and copy the channel ID.
+ Eg: defaultchannel=1234567890
+
+
+ forcefocus=<integer>
+ Embeds are activated once the frame is loaded. However, if you have more than one embeds on the page, the rate limits might bite your user's toes. Having this setting set means that the embed will not be loaded until the user mouseovers the frame.
+
+ Avaliable Options:
+
+
0 = disabled (default)
+
1 = enabled
+
+
+ Eg: forcefocus=1
+
+
+ theme=<string>
+ Want your embed to use one of our premade themes? Look no further!
+
+ Avaliable Options:
+
+
BetterTitan
+
DiscordDark
+
+
+ Eg: theme=DiscordDark
+
+
+
+
+
+
+
\ No newline at end of file
From b6525bc00efec7b968b73cc0904187ce31d674af Mon Sep 17 00:00:00 2001
From: Jori van Ee
Date: Thu, 27 Jul 2017 17:59:53 +0200
Subject: [PATCH 036/135] Update admin_cosmetics.html.j2
Added placeholder for user id field
---
webapp/titanembeds/templates/admin_cosmetics.html.j2 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/webapp/titanembeds/templates/admin_cosmetics.html.j2 b/webapp/titanembeds/templates/admin_cosmetics.html.j2
index 897ea62..96a68bd 100644
--- a/webapp/titanembeds/templates/admin_cosmetics.html.j2
+++ b/webapp/titanembeds/templates/admin_cosmetics.html.j2
@@ -20,7 +20,7 @@
{% endblock %}
+{% block script %}
+
+{% endblock %}
\ No newline at end of file
From 3b5707cd15157f33e31a460b5ad04241ac23c298 Mon Sep 17 00:00:00 2001
From: Jeremy Zhang
Date: Thu, 3 Aug 2017 22:26:45 +0000
Subject: [PATCH 048/135] Hotfix for webhooks not showing up in the embeds.
Message author object sometimes gives User for webhooks. User objects does
not have nicknames. Check if the user/author object has nick attribute.
---
discordbot/titanembeds/database/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/discordbot/titanembeds/database/__init__.py b/discordbot/titanembeds/database/__init__.py
index bca6b8b..8b3b2c0 100644
--- a/discordbot/titanembeds/database/__init__.py
+++ b/discordbot/titanembeds/database/__init__.py
@@ -69,7 +69,7 @@ class DatabaseInterface(object):
def get_message_author(self, message):
author = message.author
- if author.nick is not None:
+ if hasattr(author, 'nick') and author.nick:
author.name = author.nick
obj = {
"username": author.name,
From f3a1efb049e5fd5db7457ca34418b58755d27337 Mon Sep 17 00:00:00 2001
From: "Jeremy \"EndenDragon\" Zhang"
Date: Thu, 3 Aug 2017 21:09:14 -0700
Subject: [PATCH 049/135] Set manage guilds page title
It was left as Admin for some reason
---
webapp/titanembeds/templates/admin_guilds.html.j2 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/webapp/titanembeds/templates/admin_guilds.html.j2 b/webapp/titanembeds/templates/admin_guilds.html.j2
index af4c2c7..3434d13 100644
--- a/webapp/titanembeds/templates/admin_guilds.html.j2
+++ b/webapp/titanembeds/templates/admin_guilds.html.j2
@@ -1,5 +1,5 @@
{% extends 'site_layout.html.j2' %}
-{% set title="Admin" %}
+{% set title="Manage Guilds as Administrator" %}
{% block content %}