Пример #1
0
def post():
    guild_id = request.form.get("guild_id")
    channel_id = request.form.get('channel_id')
    content = request.form.get('content')
    if "user_id" in session:
        dbUser = GuildMembers.query.filter(GuildMembers.guild_id == guild_id).filter(GuildMembers.user_id == str(session['user_id'])).first()
    else:
        dbUser = None
    if user_unauthenticated():
        key = session['user_keys'][guild_id]
    else:
        key = None
    content, illegal_post, illegal_reasons = format_post_content(guild_id, channel_id, content, dbUser)
    status = update_user_status(guild_id, session['username'], key)
    message = {}
    if illegal_post:
        status_code = 417
    if status['banned'] or status['revoked']:
        status_code = 401
    else:
        chan = filter_guild_channel(guild_id, channel_id)
        if not chan.get("write") or chan["channel"]["type"] != "text":
            status_code = 401
        elif not illegal_post:
            userid = session["user_id"]
            content = format_everyone_mention(chan, content)
            webhook = get_channel_webhook_url(guild_id, channel_id)
            # if userid in get_administrators_list():
            #     content = "(Titan Dev) " + content
            if webhook:
                if (session['unauthenticated']):
                    username = session["username"] + "#" + str(session["user_id"])
                    avatar = url_for('static', filename='img/titanembeds_square.png', _external=True)
                    dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
                    if dbguild:
                        icon = dbguild.guest_icon
                        if icon:
                            avatar = icon
                else:
                    username = session["username"]
                    if dbUser:
                        if dbUser.nickname:
                            username = dbUser.nickname
                    # if content.startswith("(Titan Dev) "):
                    #     content = content[12:]
                    #     username = "******" + username
                    username = username + "#" + str(session['discriminator'])
                    avatar = session['avatar']
                message = discord_api.execute_webhook(webhook.get("id"), webhook.get("token"), username, avatar, content)
            else:
                message = discord_api.create_message(channel_id, content)
            status_code = message['code']
    response = jsonify(message=message.get('content', message), status=status, illegal_reasons=illegal_reasons)
    response.status_code = status_code
    return response
Пример #2
0
def post():
    guild_id = request.form.get("guild_id")
    channel_id = request.form.get('channel_id')
    content = request.form.get('content', "")
    file = None
    if "file" in request.files:
        file = request.files["file"]
    if file and file.filename == "":
        file = None
    rich_embed = request.form.get("richembed", None)
    if rich_embed:
        rich_embed = json.loads(rich_embed)
    if "user_id" in session:
        dbUser = redisqueue.get_guild_member(guild_id, session["user_id"])
    else:
        dbUser = None
    if user_unauthenticated():
        key = session['user_keys'][guild_id]
    else:
        key = None
    content, illegal_post, illegal_reasons = format_post_content(
        guild_id, channel_id, content, dbUser)
    status = update_user_status(guild_id, session['username'], key)
    message = {}
    if illegal_post:
        status_code = 417
    if status['banned'] or status['revoked']:
        status_code = 401
    else:
        chan = filter_guild_channel(guild_id, channel_id)
        if not chan.get("write") or chan["channel"]["type"] != "text":
            status_code = 401
        elif (file and not chan.get("attach_files")) or (
                rich_embed and not chan.get("embed_links")):
            status_code = 406
        elif not illegal_post:
            userid = session["user_id"]
            content = format_everyone_mention(chan, content)
            webhook = get_channel_webhook_url(guild_id, channel_id)
            # if userid in get_administrators_list():
            #     content = "(Titan Dev) " + content
            if webhook:
                if (session['unauthenticated']):
                    username = session["username"]
                    if len(username) > 25:
                        username = username[:25]
                    username = username + "#" + str(session["user_id"])
                    avatar = url_for('static',
                                     filename='img/titanembeds_square.png',
                                     _external=True)
                    dbguild = db.session.query(Guilds).filter(
                        Guilds.guild_id == guild_id).first()
                    if dbguild:
                        icon = dbguild.guest_icon
                        if icon:
                            avatar = icon
                else:
                    username = session["username"]
                    if dbUser:
                        if dbUser["nick"]:
                            username = dbUser["nick"]
                    # if content.startswith("(Titan Dev) "):
                    #     content = content[12:]
                    #     username = "******" + username
                    if len(username) > 25:
                        username = username[:25]
                    username = username + "#" + str(session['discriminator'])
                    avatar = session['avatar']
                message = discord_api.execute_webhook(webhook.get("id"),
                                                      webhook.get("token"),
                                                      username, avatar,
                                                      content, file,
                                                      rich_embed)
                delete_webhook_if_too_much(webhook)
            else:
                message = discord_api.create_message(channel_id, content, file,
                                                     rich_embed)
            status_code = message['code']
    db.session.commit()
    response = jsonify(message=message.get('content', message),
                       status=status,
                       illegal_reasons=illegal_reasons)
    response.status_code = status_code
    return response