Switch github stargazer to voting on DBLorg

This commit is contained in:
Jeremy Zhang 2018-02-18 22:50:24 +00:00
parent cd0f97d153
commit 39dc966138
8 changed files with 75 additions and 58 deletions

View File

@ -23,4 +23,7 @@ config = {
'database-uri': "driver://username:password@host:port/database",
'redis-uri': "redis://",
'websockets-mode': "LITTERALLY None or eventlet or gevent",
# https://titanembeds.com/api/webhook/discordbotsorg/vote/<secret here>
'discordbotsorg-webhook-secret': "Secret appended to the discord bots hook url",
}

View File

@ -1,6 +1,6 @@
from titanembeds.database import db, Guilds, UnauthenticatedUsers, UnauthenticatedBans, AuthenticatedUsers, GuildMembers, Messages, get_channel_messages, list_all_guild_members, get_guild_member, get_administrators_list, get_badges
from titanembeds.decorators import valid_session_required, discord_users_only, abort_if_guild_disabled
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, user_unauthenticated, checkUserRevoke, checkUserBanned, update_user_status, check_user_in_guild, get_guild_channels, guild_webhooks_enabled, guild_unauthcaptcha_enabled, get_member_roles, get_online_embed_user_keys
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, user_unauthenticated, checkUserRevoke, checkUserBanned, update_user_status, check_user_in_guild, get_guild_channels, guild_webhooks_enabled, guild_unauthcaptcha_enabled, get_member_roles, get_online_embed_user_keys, redis_store
from titanembeds.oauth import user_has_permission, generate_avatar_url, check_user_can_administrate_guild
from flask import Blueprint, abort, jsonify, session, request, url_for
from flask import current_app as app
@ -462,4 +462,20 @@ def user_info(guild_id, user_id):
if gr["id"] == r:
usr["roles"].append(gr)
usr["badges"] = get_badges(user_id)
return jsonify(usr)
if redis_store.get("DiscordBotsOrgVoted/" + str(member.user_id)):
usr["badges"].append("discordbotsorgvoted")
return jsonify(usr)
@api.route("/webhook/discordbotsorg/vote/{}".format(config.get("discordbotsorg-webhook-secret", "")), methods=["POST"])
def webhook_discordbotsorg_vote():
incoming = request.get_json()
client_id = incoming.get('bot')
if config["client-id"] != client_id:
abort(401)
user_id = incoming.get("user")
vote_type = incoming.get("type")
if vote_type == "upvote":
redis_store.set("DiscordBotsOrgVoted/" + user_id, "voted", 86400)
else:
redis_store.delete("DiscordBotsOrgVoted/" + user_id)
return ('', 204)

View File

@ -1,5 +1,5 @@
from titanembeds.utils import socketio, guild_accepts_visitors, get_client_ipaddr, discord_api, check_user_in_guild, get_guild_channels, update_user_status, guild_webhooks_enabled
from titanembeds.database import db, GuildMembers, get_guild_member, Guilds, get_badges
from titanembeds.utils import socketio, guild_accepts_visitors, get_client_ipaddr, discord_api, check_user_in_guild, get_guild_channels, update_user_status, guild_webhooks_enabled, redis_store
from titanembeds.database import db, GuildMembers, get_guild_member, Guilds
from flask_socketio import Namespace, emit, disconnect, join_room, leave_room
import functools
from flask import request, session
@ -158,7 +158,7 @@ class Gateway(Namespace):
"avatar": None,
"color": None,
"avatar_url": None,
"stargazer": False,
"discordbotsorgvoted": False,
}
member = db.session.query(GuildMembers).filter(GuildMembers.guild_id == guild_id, GuildMembers.username == name, GuildMembers.discriminator == discriminator).first()
if member:
@ -170,7 +170,7 @@ class Gateway(Namespace):
if (usr["avatar"]):
usr["avatar_url"] = "https://cdn.discordapp.com/avatars/{}/{}.png".format(usr["id"], usr["avatar"])
usr["roles"] = json.loads(member.roles)
usr["stargazer"] = "star" in get_badges(member.user_id)
usr["discordbotsorgvoted"] = bool(redis_store.get("DiscordBotsOrgVoted/" + str(member.user_id)))
else:
member = db.session.query(GuildMembers).filter(GuildMembers.guild_id == guild_id, GuildMembers.nickname == name, GuildMembers.discriminator == discriminator).first()
if member:
@ -182,6 +182,6 @@ class Gateway(Namespace):
if (usr["avatar"]):
usr["avatar_url"] = "https://cdn.discordapp.com/avatars/{}/{}.png".format(usr["id"], usr["avatar"])
usr["roles"] = json.loads(member.roles)
usr["stargazer"] = "star" in get_badges(member.user_id)
usr["discordbotsorgvoted"] = bool(redis_store.get("DiscordBotsOrgVoted/" + str(member.user_id)))
emit("lookup_user_info", usr)
self.teardown_db_session()

View File

@ -213,7 +213,7 @@ nav .brand-logo {
cursor: pointer;
}
#chatcontent .chatusername.stargazer {
#chatcontent .chatusername.discordbotsorgvoted {
text-shadow: 2px 2px 10px yellow;
}
@ -883,7 +883,7 @@ p.mentioned span.chatmessage {
font-weight: normal;
}
#usercard .badges .star {
#usercard .badges .discordbotsorgvoted {
color: yellow;
}

View File

@ -20,7 +20,7 @@
(function () {
const theme_options = ["DiscordDark", "MetroEdge", "BetterTitan"]; // All the avaliable theming names
const badges_options = ["administrator", "partner", "supporter", "star"]; // All badges avaliable
const badges_options = ["administrator", "partner", "supporter", "discordbotsorgvoted"]; // All badges avaliable
var user_def_css; // Saves the user defined css
var has_already_been_initially_resized = false; // keep track if the embed initially been resized
@ -1249,8 +1249,8 @@
} else {
parent.find(".chatusername").css("color", null);
}
if (usr.stargazer) {
parent.find(".chatusername").addClass("stargazer");
if (usr.discordbotsorgvoted) {
parent.find(".chatusername").addClass("discordbotsorgvoted");
}
if (usr.avatar_url) {
parent.find(".authoravatar").prop("src", usr.avatar_url);

View File

@ -58,7 +58,6 @@
<option value="administrator">TitanEmbeds Administrators</option>
<option value="partner">TitanEmbeds Partner</option>
<option value="supporter">TitanEmbeds Supporter</option>
<option value="star">GitHub Stargazer</option>
</select>
</div>
</td>
@ -121,7 +120,6 @@
<option value="administrator" {% if "administrator" in cosmetic.badges %}selected{% endif %}>TitanEmbeds Administrators</option>
<option value="partner" {% if "partner" in cosmetic.badges %}selected{% endif %}>TitanEmbeds Partner</option>
<option value="supporter" {% if "supporter" in cosmetic.badges %}selected{% endif %}>TitanEmbeds Supporter</option>
<option value="star" {% if "star" in cosmetic.badges %}selected{% endif %}>GitHub Stargazer</option>
</select>
</div>
</td>

View File

@ -237,7 +237,7 @@
<a class="administrator tooltipped" data-tooltip="{{ _("TitanEmbeds Administrator") }}" data-position="top" href="https://titanembeds.com/" target="_blank"><i class="material-icons">gavel</i></a>
<a class="partner tooltipped" data-tooltip="{{ _("TitanEmbeds Partner") }}" data-position="top" href="https://titanembeds.com/about" target="_blank"><i class="material-icons">person_pin</i></a>
<a class="supporter tooltipped" data-tooltip="{{ _("TitanEmbeds Supporter") }}" data-position="top" href="https://titanembeds.com/user/donate" target="_blank"><i class="material-icons">attach_money</i></a>
<a class="star tooltipped" data-tooltip="{{ _("GitHub Stargazer") }}" data-position="top" href="https://github.com/TitanEmbeds/Titan" target="_blank"><i class="material-icons">star</i></a>
<a class="discordbotsorgvoted tooltipped" data-tooltip="{{ _("I have voted for Titan on Discord Bots today!") }}" data-position="top" href="https://discordbots.org/bot/Titan/vote" target="_blank"><i class="material-icons">check_box</i></a>
</div>
<p class="offline-text">{{ _("User is offline in Discord.") }}</p>
<p class="game">{{ _("Playing") }} <span class="text"></span></p>

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-01-28 00:45+0000\n"
"POT-Creation-Date: 2018-02-18 22:46+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -49,171 +49,171 @@ msgstr ""
msgid "Alright, here's the usual~"
msgstr ""
#: titanembeds/templates/embed.html.j2:71
#: titanembeds/templates/embed.html.j2:78
msgid "Actions"
msgstr ""
#: titanembeds/templates/embed.html.j2:72
#: titanembeds/templates/embed.html.j2:79
msgid "Manage Guild Embed"
msgstr ""
#: titanembeds/templates/embed.html.j2:73
#: titanembeds/templates/embed.html.j2:80
msgid "Open Server on Discordapp"
msgstr ""
#: titanembeds/templates/embed.html.j2:77
#: titanembeds/templates/embed.html.j2:84
msgid "Channel Topic"
msgstr ""
#: titanembeds/templates/embed.html.j2:82
#: titanembeds/templates/embed.html.j2:89
msgid "Channels"
msgstr ""
#: titanembeds/templates/embed.html.j2:87
#: titanembeds/templates/embed.html.j2:94
msgid "Online Server Members"
msgstr ""
#: titanembeds/templates/embed.html.j2:92
#: titanembeds/templates/embed.html.j2:99
msgid "Authenticated Embed Users"
msgstr ""
#: titanembeds/templates/embed.html.j2:95
#: titanembeds/templates/embed.html.j2:102
msgid "Guest Embed Users"
msgstr ""
#: titanembeds/templates/embed.html.j2:115
#: titanembeds/templates/embed.html.j2:122
msgid "Please choose one of the following methods to authenticate!"
msgstr ""
#: titanembeds/templates/embed.html.j2:121
#: titanembeds/templates/embed.html.j2:128
msgid "Discord Login"
msgstr ""
#: titanembeds/templates/embed.html.j2:122
#: titanembeds/templates/embed.html.j2:129
msgid "You will be invited into this server."
msgstr ""
#: titanembeds/templates/embed.html.j2:126
#: titanembeds/templates/embed.html.j2:133
msgid ""
"Of course, you also have the option to login by picking a temporary "
"username for your current browsing session."
msgstr ""
#: titanembeds/templates/embed.html.j2:128
#: titanembeds/templates/embed.html.j2:135
msgid "Username (Hit ENTER/RETURN key to confirm)"
msgstr ""
#: titanembeds/templates/embed.html.j2:140
#: titanembeds/templates/embed.html.j2:147
msgid "Change Username"
msgstr ""
#: titanembeds/templates/embed.html.j2:143
#: titanembeds/templates/embed.html.j2:150
msgid "Guests Accounts Only"
msgstr ""
#: titanembeds/templates/embed.html.j2:145
#: titanembeds/templates/embed.html.j2:152
msgid "Change your username (Hit ENTER/RETURN key to confirm)"
msgstr ""
#: titanembeds/templates/embed.html.j2:149
#: titanembeds/templates/embed.html.j2:156
msgid "Theme"
msgstr ""
#: titanembeds/templates/embed.html.j2:159
#: titanembeds/templates/embed.html.j2:167
msgid "Overwrite Current Embed Theme w/ User CSS"
msgstr ""
#: titanembeds/templates/embed.html.j2:163
#: titanembeds/templates/embed.html.j2:171
msgid "Notification Sound"
msgstr ""
#: titanembeds/templates/embed.html.j2:168
#: titanembeds/templates/embed.html.j2:176
msgid "New Messages"
msgstr ""
#: titanembeds/templates/embed.html.j2:172
#: titanembeds/templates/embed.html.j2:180
msgid "Mentions"
msgstr ""
#: titanembeds/templates/embed.html.j2:176
#: titanembeds/templates/embed.html.j2:184
msgid "Nothing"
msgstr ""
#: titanembeds/templates/embed.html.j2:180
#: titanembeds/templates/embed.html.j2:188
msgid "Display Rich Embeds"
msgstr ""
#: titanembeds/templates/embed.html.j2:185
#: titanembeds/templates/embed.html.j2:193
msgid "Enable"
msgstr ""
#: titanembeds/templates/embed.html.j2:189
#: titanembeds/templates/embed.html.j2:197
msgid "Disable"
msgstr ""
#: titanembeds/templates/embed.html.j2:201
#: titanembeds/templates/embed.html.j2:209
msgid "Just one more step..."
msgstr ""
#: titanembeds/templates/embed.html.j2:209
#: titanembeds/templates/embed.html.j2:217
msgid "NSFW Channel"
msgstr ""
#: titanembeds/templates/embed.html.j2:210
#: titanembeds/templates/embed.html.j2:218
msgid ""
"You must be at least eighteen years old to view this channel. Are you "
"over eighteen and willing to see adult content?"
msgstr ""
#: titanembeds/templates/embed.html.j2:212
#: titanembeds/templates/embed.html.j2:220
msgid "Nope"
msgstr ""
#: titanembeds/templates/embed.html.j2:213
#: titanembeds/templates/embed.html.j2:221
msgid "Continue"
msgstr ""
#: titanembeds/templates/embed.html.j2:224
#: titanembeds/templates/embed.html.j2:232
msgid "Mention"
msgstr ""
#: titanembeds/templates/embed.html.j2:229
#: titanembeds/templates/embed.html.j2:237
msgid "TitanEmbeds Administrator"
msgstr ""
#: titanembeds/templates/embed.html.j2:230
#: titanembeds/templates/embed.html.j2:238
msgid "TitanEmbeds Partner"
msgstr ""
#: titanembeds/templates/embed.html.j2:231
#: titanembeds/templates/embed.html.j2:239
msgid "TitanEmbeds Supporter"
msgstr ""
#: titanembeds/templates/embed.html.j2:232
msgid "GitHub Stargazer"
#: titanembeds/templates/embed.html.j2:240
msgid "I have voted for Titan on Discord Bots today!"
msgstr ""
#: titanembeds/templates/embed.html.j2:234
#: titanembeds/templates/embed.html.j2:242
msgid "User is offline in Discord."
msgstr ""
#: titanembeds/templates/embed.html.j2:235
#: titanembeds/templates/embed.html.j2:243
msgid "Playing"
msgstr ""
#: titanembeds/templates/embed.html.j2:236
#: titanembeds/templates/embed.html.j2:244
msgid "Roles"
msgstr ""
#: titanembeds/templates/embed.html.j2:245
#: titanembeds/templates/embed.html.j2:253
msgid "Server Emoji"
msgstr ""
#: titanembeds/templates/embed.html.j2:262
#: titanembeds/templates/embed.html.j2:270
msgid "Please login to post a message."
msgstr ""
#: titanembeds/templates/embed.html.j2:262
#: titanembeds/templates/embed.html.j2:270
msgid "Login"
msgstr ""