Exemple #1
0
async def staff():
    user = models.User.get_from_cache()
    if not verify_staff(db, user):
        abort(403)
    success = request.args.get('success')
    response = await request.form
    if request.method == 'POST' and response:
        success = f'{user}'
        # Staff apps
        success += update_apps(db, response)
        # Website announcement
        success += update_announcement(response)
        # Invites
        success += block_invites(response)

        if len(success) > len(str(user)):
            webhook = DiscordWebhook(url=config.WEBHOOK_TOKEN,
                                     content=f"UPDATE: {success}")
            webhook.execute()
        success = success[len(str(user)):]
        return redirect(url_for('.staff', success=success))

    return await render_template(
        'staff/main.html',
        icon=image,
        color=WebsiteTheme.color,
        staff=cache.get_from_cache(cache, 'staff_open'),
        success=success,
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        applications=list(db.apps.find({'status': 0})),
        reason=cache.get_from_cache(cache, 'reason'),
        user=user)
Exemple #2
0
async def get_stats():
    return await make_response(
        jsonify({
            "guilds": cache.get_from_cache(cache, 'guilds'),
            "users": cache.get_from_cache(cache, 'users'),
            "status": 200
        }), 200)
Exemple #3
0
async def user_app(userid):
    logged_in_user = models.User.get_from_cache()
    if not verify_staff(db, logged_in_user):
        abort(403)
    success = None
    if request.method == 'POST':
        message = ''
        response = await request.form
        message += await application_manage(response, logged_in_user, userid,
                                            bot, db)
        webhook = DiscordWebhook(url=config.WEBHOOK_TOKEN,
                                 content=f"UPDATE: {message}")
        webhook.execute()
        return redirect('/staff/applications/')

    return await render_template(
        'staff/apps.html',
        icon=image,
        color=WebsiteTheme.color,
        staff=cache.get_from_cache(cache, 'staff_open'),
        success=success,
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, logged_in_user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        application=db.apps.find_one({'userID': int(userid)}),
        bot=bot,
        user=logged_in_user)
Exemple #4
0
async def exc(e):
    user = models.User.get_from_cache()
    error_channel = bot.get_channel(836993491485458454)

    emb = discord.Embed(color=discord.Color.red(), title="Error Occured!")
    error = "".join(traceback.format_exception(type(e), e, e.__traceback__))
    if len(error) > 2000:
        mystbin_client = mystbin.Client()
        error = await mystbin_client.post(error, syntax='python')
    else:
        error = f"```py\n{error}```"
    emb.description = f"{error}"
    await error_channel.send(embed=emb, content="Error occured!")

    return await render_template(
        'errors/exception.html',
        not_found_icon=not_found_icon,
        color=WebsiteTheme.color,
        icon=image,
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        error=e,
        user=user)
Exemple #5
0
async def bot_lists():
    user = models.User.get_from_cache()
    return await render_template(
        'lists.html',
        icon=image,
        color=WebsiteTheme.color,
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        user=user)
Exemple #6
0
async def ratelimited(e):
    user = models.User.get_from_cache()
    return await render_template(
        'errors/custom.html',
        title="429 - Ratelimited",
        description="You're accessing this route too fast, please slow down!",
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        user=user)
Exemple #7
0
async def forbidden(e):
    user = models.User.get_from_cache()
    return await render_template(
        'errors/custom.html',
        title="403 - Forbidden",
        description=
        "The route you're trying to access is not accessible by you!",
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        user=user)
Exemple #8
0
def update_apps(db, response):
    success = ''
    if cache.get_from_cache(
            cache, 'staff_open') and response['staff_apps'] == 'disabled':
        db.apps.update_one({'open': True}, {'$set': {'open': False}})
        cache.update_cache(cache, 'staff_open', False)
        success += ' disabled the applications'
    elif not cache.get_from_cache(
            cache, 'staff_open') and response['staff_apps'] == 'enabled':
        db.apps.update_one({'open': False}, {'$set': {'open': True}})
        cache.update_cache(cache, 'staff_open', True)
        success += ' enabled the applications'

    return success
Exemple #9
0
async def my_application():
    user = models.User.get_from_cache()
    return await render_template(
        'staff/apps.html',
        icon=image,
        color=WebsiteTheme.color,
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        application=db.apps.find_one({'userID': user.id}),
        bot=bot,
        user=user)
Exemple #10
0
async def view_guild(guild):
    user = models.User.get_from_cache()
    guild = main_bot.get_guild(guild)
    return await render_template(
        'guildinfo.html',
        color=WebsiteTheme.color,
        icon=image,
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        user=user,
        bot=main_bot,
        guild=guild)
Exemple #11
0
def block_invites(response):
    success = ''
    reason = cache.get_from_cache(cache, 'reason')
    if reason and response['bot-invite'] != reason and response[
            'bot-invite'] != '' or not reason and response['bot-invite'] != '':
        cache.update_cache(cache, 'allow_invite', False)
        cache.update_cache(cache, 'reason', response['bot-invite'])
        success += f' disabled new invitations for {response["bot-invite"]}'
    elif not cache.get_from_cache(
            cache, 'allow_invite') and response['bot-invite'] == '':
        cache.update_cache(cache, 'allow_invite', True)
        cache.update_cache(cache, 'reason', response['bot-invite'])
        success += " enabled new invitations"

    return success
Exemple #12
0
async def bot_invite_guild(guild):
    if not cache.get_from_cache(cache, 'allow_invite'):
        return redirect('/invite')
    else:
        return await discord_session.create_session(scope=["bot"],
                                                    permissions=477588727,
                                                    guild_id=guild,
                                                    disable_guild_select=True)
Exemple #13
0
def update_announcement(response):
    success = ''
    if cache.get_from_cache(
            cache, 'announcement'
    ) and response['announcement'] != cache.get_from_cache(
            cache, 'announcement'
    ) and response['announcement'] != '' or not cache.get_from_cache(
            cache, 'announcement') and response['announcement'] != '':
        cache.update_cache(cache, 'announcement', response['announcement'])
        with suppress(Exception):
            cache.update_cache(cache, 'announcement_color', response['color'])
        success += f" set the announcement to {cache.get_from_cache(cache, 'announcement')}"
    elif cache.get_from_cache(
            cache, 'announcement') and response['announcement'] == '':
        cache.update_cache(cache, 'announcement_color', None)
        cache.update_cache(cache, 'announcement', None)
        success += ' reset the announcement'
    elif cache.get_from_cache(
            cache, 'announcement'
    ) and response['announcement'] == cache.get_from_cache(
            cache, 'announcement') and cache.get_from_cache(
                cache, 'announcement_color') != response['color']:
        cache.update_cache(cache, 'announcement_color', response['color'])
        success += ' set the color to {0}'.format(response['color'])

    return success
Exemple #14
0
async def staff_apps():
    user = models.User.get_from_cache()
    if not verify_staff(db, user):
        abort(403)
    success = None
    return await render_template(
        'staff/applications.html',
        icon=image,
        color=WebsiteTheme.color,
        staff=cache.get_from_cache(cache, 'staff_open'),
        success=success,
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        applications=cache.get_from_cache(cache, 'staff_apps'),
        bot=bot,
        user=user)
Exemple #15
0
async def affiliates():
    user = models.User.get_from_cache()
    if not bot.is_ready():
        return "Partners are not yet cached :/ Should be cached in the next few seconds, if not please report this to us <a href='/support/'>here</a>"
    return await render_template(
        'affiliates.html',
        icon=image,
        color=WebsiteTheme.color,
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        all_partners=cache.get_from_cache(cache, 'partners'),
        top_partner=cache.get_from_cache(cache, 'top_partner'),
        bot=bot,
        cache=cache,
        user=user)
Exemple #16
0
async def my_profile():
    user = models.User.get_from_cache()
    guilds = user.guilds if user.guilds else await user.fetch_guilds()
    apps = list(db.apps.find({'userID': user.id}))
    return await render_template(
        'profile.html',
        color=WebsiteTheme.color,
        icon=image,
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        applications=apps,
        user=user,
        guilds=guilds,
        bot=main_bot,
        allow_invites=cache.get_from_cache(cache, 'allow_invite'),
        reason=cache.get_from_cache(cache, 'reason'))
Exemple #17
0
async def apply():
    user = models.User.get_from_cache()
    if user:
        if not user.guilds:
            await user.fetch_guilds()
        guilds = [x.name for x in user.guilds]
    else:
        guilds = None

    apps_closed, submitted, saw_success = False, False, False
    if not cache.get_from_cache(cache, 'staff_open'):
        apps_closed = True
    elif cache.get_from_cache(cache, 'staff_open'):
        if request.method == 'GET':
            if user:
                db_check = db.apps.find_one({'userID': user.id})
                if db_check and not request.args.get('submitted'):
                    saw_success, submitted = True, True
                elif db_check and request.args.get('submitted'):
                    submitted = True
        elif request.method == 'POST':
            submitted = True
            response = await request.form
            user = bot.get_user(int(user.id))
            await log_app(bot, user, response, db)
            cache.update_cache(cache, 'staff_apps', list(db.apps.find()))
            return redirect(url_for('.apply', submitted=submitted))

    return await render_template(
        'applications.html',
        icon=image,
        color=WebsiteTheme.color,
        submitted=submitted,
        saw_success=saw_success,
        apps_closed=apps_closed,
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        user=user,
        guilds=guilds)
Exemple #18
0
async def bot_invite():
    user = models.User.get_from_cache()
    if user:
        guilds = user.guilds if user.guilds else await user.fetch_guilds()
    else:
        guilds = None
    return await render_template(
        'invite.html',
        icon=image,
        color=WebsiteTheme.color,
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        allow_invite=cache.get_from_cache(cache, 'allow_invite'),
        reason=cache.get_from_cache(cache, 'reason'),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        user=user,
        guilds=guilds,
        bot=main_bot)
Exemple #19
0
async def about_page():
    user = models.User.get_from_cache()
    return await render_template(
        'about.html',
        icon=image,
        color=WebsiteTheme.color,
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        moksej=cache.get_from_cache(cache, 'moksej'),
        zenpa=cache.get_from_cache(cache, 'zenpa'),
        duck=cache.get_from_cache(cache, 'duck'),
        support=cache.get_from_cache(cache, 'staff'),
        discord=discord,
        on_leave=cache.get_from_cache(cache, 'on_leave'),
        user=user,
        guild_count=cache.get_from_cache(cache, 'guilds'),
        user_count=cache.get_from_cache(cache, 'users'))
Exemple #20
0
    async def token(*args, **kwargs):
        if not request.headers:
            return await make_response(
                jsonify({
                    'message': 'Please provide the authorization token!',
                    'status': 401
                }), 401)

        if 'Authorization' in request.headers and request.headers[
                'Authorization'] != '':
            token = request.headers['Authorization']
        else:
            return await make_response(
                jsonify({
                    'message': 'The authorization is missing!',
                    'status': 401
                }), 401)

        if 'Client' in request.headers and request.headers['Client'] != '':
            client = request.headers['Client']
        else:
            return await make_response(
                jsonify({
                    'message': 'Client information is missing!',
                    'status': 401
                }), 401)

        valid_token = cache.get_from_cache(cache, 'api_token')
        valid_client = cache.get_from_cache(cache, 'api_client')
        if token and token != valid_token or client != valid_client:
            return await make_response(
                jsonify({
                    'message': 'The token or client is invalid!',
                    'status': 403
                }), 403)
        elif token and token == valid_token and client == valid_client:
            return await f(*args, **kwargs)
Exemple #21
0
async def main_page():
    user = models.User.get_from_cache()
    return await render_template(
        'index.html',
        icon=image,
        color=WebsiteTheme.color,
        staff=cache.get_from_cache(cache, 'staff_open'),
        logged_in=await discord_session.authorized,
        is_staff=verify_staff(db, user),
        announcement=cache.get_from_cache(cache, 'announcement'),
        announcement_color=cache.get_from_cache(cache, 'announcement_color'),
        dredd=cache.get_from_cache(cache, 'me'),
        discord=discord,
        user=user,
        guild_count=cache.get_from_cache(cache, 'guilds'),
        user_count=cache.get_from_cache(cache, 'users'))
Exemple #22
0
async def update_partners():
    await cache.load_cache(cache, bot, main_bot, db)
    partners_list = cache.get_from_cache(cache, 'partners')
    cache.update_cache(cache, 'top_partner', random.choice(partners_list))