mirror of
				https://github.com/TitanEmbeds/Titan.git
				synced 2025-11-04 07:47:10 +01:00 
			
		
		
		
	Add voting page and track referrals
This commit is contained in:
		@@ -0,0 +1,35 @@
 | 
			
		||||
"""Added DiscordBotsOrgTransactions table
 | 
			
		||||
 | 
			
		||||
Revision ID: b18fcc759865
 | 
			
		||||
Revises: dffebf852b41
 | 
			
		||||
Create Date: 2018-02-27 06:14:12.133576
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
# revision identifiers, used by Alembic.
 | 
			
		||||
revision = 'b18fcc759865'
 | 
			
		||||
down_revision = 'dffebf852b41'
 | 
			
		||||
branch_labels = None
 | 
			
		||||
depends_on = None
 | 
			
		||||
 | 
			
		||||
from alembic import op
 | 
			
		||||
import sqlalchemy as sa
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def upgrade():
 | 
			
		||||
    # ### commands auto generated by Alembic - please adjust! ###
 | 
			
		||||
    op.create_table('discordbotsorg_transactions',
 | 
			
		||||
    sa.Column('id', sa.Integer(), nullable=False),
 | 
			
		||||
    sa.Column('user_id', sa.BigInteger(), nullable=False),
 | 
			
		||||
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=False),
 | 
			
		||||
    sa.Column('action', sa.String(length=255), nullable=False),
 | 
			
		||||
    sa.Column('referrer', sa.BigInteger(), nullable=True),
 | 
			
		||||
    sa.PrimaryKeyConstraint('id')
 | 
			
		||||
    )
 | 
			
		||||
    # ### end Alembic commands ###
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def downgrade():
 | 
			
		||||
    # ### commands auto generated by Alembic - please adjust! ###
 | 
			
		||||
    op.drop_table('discordbotsorg_transactions')
 | 
			
		||||
    # ### end Alembic commands ###
 | 
			
		||||
@@ -71,6 +71,10 @@ def terms():
 | 
			
		||||
def privacy():
 | 
			
		||||
    return render_template("privacy_policy.html.j2")
 | 
			
		||||
 | 
			
		||||
@app.route("/vote")
 | 
			
		||||
def vote():
 | 
			
		||||
    return render_template("discordbotsorg_vote.html.j2")
 | 
			
		||||
 | 
			
		||||
@app.before_first_request
 | 
			
		||||
def before_first_request():
 | 
			
		||||
    discord_api.init_discordrest()
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
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.database import db, Guilds, UnauthenticatedUsers, UnauthenticatedBans, AuthenticatedUsers, GuildMembers, Messages, get_channel_messages, list_all_guild_members, get_guild_member, get_administrators_list, get_badges, DiscordBotsOrgTransactions
 | 
			
		||||
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, redis_store
 | 
			
		||||
from titanembeds.oauth import user_has_permission, generate_avatar_url, check_user_can_administrate_guild
 | 
			
		||||
@@ -6,6 +6,7 @@ from flask import Blueprint, abort, jsonify, session, request, url_for
 | 
			
		||||
from flask import current_app as app
 | 
			
		||||
from flask_socketio import emit
 | 
			
		||||
from sqlalchemy import and_
 | 
			
		||||
from urllib.parse import urlparse, parse_qsl, urlsplit
 | 
			
		||||
import random
 | 
			
		||||
import json
 | 
			
		||||
import datetime
 | 
			
		||||
@@ -466,16 +467,27 @@ def user_info(guild_id, user_id):
 | 
			
		||||
            usr["badges"].append("discordbotsorgvoted")
 | 
			
		||||
    return jsonify(usr)
 | 
			
		||||
    
 | 
			
		||||
@api.route("/webhook/discordbotsorg/vote/{}".format(config.get("discordbotsorg-webhook-secret", "")), methods=["POST"])
 | 
			
		||||
@api.route("/webhook/discordbotsorg/vote", methods=["POST"])
 | 
			
		||||
def webhook_discordbotsorg_vote():
 | 
			
		||||
    incoming = request.get_json()
 | 
			
		||||
    client_id = incoming.get('bot')
 | 
			
		||||
    if config["client-id"] != client_id:
 | 
			
		||||
        abort(401)
 | 
			
		||||
    if request.headers.get("Authorization", "") != config.get("discordbotsorg-webhook-secret", ""):
 | 
			
		||||
        abort(403)
 | 
			
		||||
    user_id = incoming.get("user")
 | 
			
		||||
    vote_type = incoming.get("type")
 | 
			
		||||
    params = dict(parse_qsl(urlsplit(url).query))
 | 
			
		||||
    if vote_type == "upvote":
 | 
			
		||||
        redis_store.set("DiscordBotsOrgVoted/" + user_id, "voted", 86400)
 | 
			
		||||
    else:
 | 
			
		||||
        redis_store.delete("DiscordBotsOrgVoted/" + user_id)
 | 
			
		||||
    referrer = None
 | 
			
		||||
    if "referrer" in params:
 | 
			
		||||
        try:
 | 
			
		||||
            referrer = int(float(params["referrer"]))
 | 
			
		||||
        except:
 | 
			
		||||
            pass
 | 
			
		||||
    DBLTrans = DiscordBotsOrgTransactions(int(float(user_id)), vote_type, referrer)
 | 
			
		||||
    db.session.add(DBLTrans)
 | 
			
		||||
    return ('', 204)
 | 
			
		||||
@@ -15,6 +15,7 @@ from .titan_tokens import TitanTokens, get_titan_token
 | 
			
		||||
from .token_transactions import TokenTransactions
 | 
			
		||||
from .patreon import Patreon
 | 
			
		||||
from .disabled_guilds import DisabledGuilds, list_disabled_guilds
 | 
			
		||||
from .discordbotsorg_transactions import DiscordBotsOrgTransactions
 | 
			
		||||
 | 
			
		||||
def set_titan_token(user_id, amt_change, action):
 | 
			
		||||
    token_count = get_titan_token(user_id)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								webapp/titanembeds/database/discordbotsorg_transactions.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								webapp/titanembeds/database/discordbotsorg_transactions.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
from titanembeds.database import db
 | 
			
		||||
import datetime
 | 
			
		||||
import time
 | 
			
		||||
 | 
			
		||||
class DiscordBotsOrgTransactions(db.Model):
 | 
			
		||||
    __tablename__ = "discordbotsorg_transactions"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                    # Auto increment id
 | 
			
		||||
    user_id = db.Column(db.BigInteger, nullable=False)              # Discord user id of user
 | 
			
		||||
    timestamp = db.Column(db.TIMESTAMP, nullable=False)             # The timestamp of when the action took place
 | 
			
		||||
    action = db.Column(db.String(255), nullable=False)              # Very short description of the action
 | 
			
		||||
    referrer = db.Column(db.BigInteger, nullable=True)              # Discord user id of the referrer
 | 
			
		||||
    
 | 
			
		||||
    def __init__(self, user_id, action, referrer=None):
 | 
			
		||||
        self.user_id = user_id
 | 
			
		||||
        self.action = action
 | 
			
		||||
        if referrer:
 | 
			
		||||
            self.referrer = referrer
 | 
			
		||||
        self.timestamp = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
 | 
			
		||||
@@ -483,7 +483,7 @@
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        var dblAdContents = "<i class=\"material-icons right\">close</i></span><span id=\"dblBalloon\"><h6>Loving the Titan, the Discord server widget?</h6><br>Show your appreciation <em>by voting for Titan daily</em> on <a href=\"https://discordbots.org/bot/Titan/vote\" target=\"_blank\">Discord Bot List</a> and get a <span class=\"yellow-text\">golden</span> name!";
 | 
			
		||||
        var dblAdContents = "<i class=\"material-icons right\">close</i></span><span id=\"dblBalloon\"><h6>Loving the Titan, the Discord server widget?</h6><br>Show your appreciation <em>by voting for Titan daily</em> on <a href=\"https://titanembeds.com/vote\" target=\"_blank\">Discord Bot List</a> and get a <span class=\"yellow-text\">golden</span> name and other rewards!";
 | 
			
		||||
        $(".brand-logo").showBalloon({
 | 
			
		||||
            html: true,
 | 
			
		||||
            position: "bottom",
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								webapp/titanembeds/templates/discordbotsorg_vote.html.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								webapp/titanembeds/templates/discordbotsorg_vote.html.j2
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
{% extends 'site_layout.html.j2' %}
 | 
			
		||||
{% set title="Vote for Titan on Discord Bots List!" %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
<h1>Vote for Titan on Discord Bots List!</h1>
 | 
			
		||||
<div class="row">
 | 
			
		||||
  <div class="col s12">
 | 
			
		||||
    <div class="card-panel indigo lighten-5 z-depth-3 hoverable black-text">
 | 
			
		||||
        <p class="flow-text">By voting for Titan, we'll be better known on DBL. Let's spread the word about the project!</p>
 | 
			
		||||
        <p>You'll receive a <em class="orange-text">GOLDEN NAME</em> in chat and have <em>a chance to win</em> one of the <strong>heroic</strong> prizes!</p>
 | 
			
		||||
        <p>Prizes include (but not limited to) Titan Tokens and $4.99 Discord Nitro (Paypal)! Vote often, and <strong>daily</strong>, to increase your chances of winning!</p>
 | 
			
		||||
        <br>
 | 
			
		||||
        <a class="waves-effect waves-light btn" href="https://discordbots.org/bot/Titan/vote" target="_blank">Visit Discord Bots!</a>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<hr>
 | 
			
		||||
 | 
			
		||||
<div class="row">
 | 
			
		||||
  <div class="col s12">
 | 
			
		||||
    <div class="card-panel indigo lighten-5 z-depth-3 hoverable black-text">
 | 
			
		||||
        <p class="flow-text">It just doesn't end here! Invite your buddies to vote for Titan too!</p>
 | 
			
		||||
        <p>Give your pals a personalized referral link and get rewarded for being a <em>great referrer</em>!</p>
 | 
			
		||||
        <br>
 | 
			
		||||
        {% if "user_id" in session and not session["unauthenticated"] %}
 | 
			
		||||
        <input readonly value="https://discordbots.org/bot/Titan/vote?referrer={{ session["user_id"] }}" id="disabled" type="text" onClick="this.setSelectionRange(0, this.value.length)">
 | 
			
		||||
        {% else %}
 | 
			
		||||
        <p class="red-text">Please <a href="{{ url_for("user.login_authenticated", redirect=url_for("vote")) }}">Login</a> to view your personalized referral link.</p>
 | 
			
		||||
        {% endif %}
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@@ -29,9 +29,9 @@
 | 
			
		||||
  <body>
 | 
			
		||||
    <div id="dblbanner">
 | 
			
		||||
      <span>
 | 
			
		||||
        <strong>Hey!</strong> Upvote us on <a href="https://discordbots.org/bot/Titan/vote" target="_blank">Discord Bots List</a> to show your
 | 
			
		||||
        <strong>Hey!</strong> Upvote us on <a href="{{ url_for("vote") }}">Discord Bots List</a> to show your
 | 
			
		||||
        appreciation of the Titan Embeds project! (We'll provide you with a <em>royal
 | 
			
		||||
        <span class="yellow-text">golden name</span></em> in return for your vote)
 | 
			
		||||
        <span class="yellow-text">golden name</span></em> and rewards in return for your vote)
 | 
			
		||||
      </span>
 | 
			
		||||
    </div>
 | 
			
		||||
    <main>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user