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)
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)
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)
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)
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)
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)
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)
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)
async def run(): loop = asyncio.get_event_loop() start_time = time.time() await bot.login(config.BOT_TOKEN) await main_bot.login(config.MAIN_TOKEN) loop.create_task(bot.connect()) loop.create_task(main_bot.connect()) await bot.wait_until_ready() end_time = time.time() - start_time print("Took to boot: {0}".format(end_time)) cache.__init__(cache) await cache.load_cache(cache, bot, main_bot, db) bot.load_extension('jishaku') update_partners.start()
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)
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
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)
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)
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
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)
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'))
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)
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'))
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)
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
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'))
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)
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
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))
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