Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
0
async def stats():
    content = await request.get_json(force=True)

    with suppress(Exception):
        guilds = content['guilds']
        users = content['users']

    from __init__ import db

    db.stats.update_one({"type": 'UserGuildCount'},
                        {"$set": {
                            "guilds": guilds,
                            "users": users
                        }})
    cache.update_cache(cache, 'guilds', guilds)
    cache.update_cache(cache, 'users', "{:,}".format(users))

    return content
Exemplo n.º 4
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)
Exemplo n.º 5
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
Exemplo n.º 6
0
async def application_manage(response, logged_in_user, userid, bot, db):
    user = bot.get_guild(671078170874740756).get_member(int(userid))
    message = ''
    if response['app_review'] == 'accept':
        message += f"{logged_in_user} acceped {user} ({userid}) application"
        db.apps.update_one(
            {'userID': int(userid)},
            {'$set': {
                "status": 1,
                "staff_reason": response['reason']
            }})
        cache.update_cache(cache, 'staff_apps', list(db.apps.find()))
        if user:
            roles = [
                bot.get_guild(671078170874740756).get_role(776530530346205244),
                bot.get_guild(671078170874740756).get_role(679647636479148050)
            ]
            for role in roles:
                await user.add_roles(role,
                                     reason="Staff application was approved.")
            await user.send(
                "Congratulations! Your staff application for Dredd Support has been approved!"
            )
    elif response['app_review'] == 'decline':
        message += f"{logged_in_user} declined {user} ({userid}) application for {response['reason']}"
        db.apps.update_one(
            {'userID': int(userid)},
            {'$set': {
                "status": 2,
                "staff_reason": response['reason']
            }})
        cache.update_cache(cache, 'staff_apps', list(db.apps.find()))
        if user:
            await user.send(
                f"Unfortunatelly your staff application for Dredd Support has been declined at this time for: {response['reason']}"
            )
    elif response['app_review'] == 'delete':
        message += f"{logged_in_user} deleted {user} ({userid}) application for {response['reason']}"
        db.apps.delete_one({'userID': int(userid)})
        if user:
            await user.send(
                f"Unfortunatelly your staff application for Dredd Support has been deleted at this time for: {response['reason']}"
            )
        cache.update_cache(cache, 'staff_apps', list(db.apps.find()))

    return message
Exemplo n.º 7
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))