def donate_patch(): item = request.form.get('item') amount = int(request.form.get('amount')) if amount <= 0: abort(400) subtract_amt = 0 entry = db.session.query(Cosmetics).filter( Cosmetics.user_id == session["user_id"]).first() if item == "custom_css_slots": subtract_amt = 100 if item == "webhook_icon": subtract_amt = 300 if entry is not None and entry.webhook_icon: abort(400) amt_change = -1 * subtract_amt * amount subtract = set_titan_token(session["user_id"], amt_change, "BUY " + item + " x" + str(amount)) if not subtract: return ('', 402) session["tokens"] += amt_change if item == "custom_css_slots": if not entry: entry = Cosmetics(session["user_id"]) entry.css = True entry.css_limit = 0 entry.css_limit += amount if item == "webhook_icon": if not entry: entry = Cosmetics(session["user_id"]) entry.webhook_icon = True db.session.add(entry) db.session.commit() return ('', 204)
def cosmetics_post(): user_id = request.form.get("user_id", None) if not user_id: abort(400) css = request.form.get("css", None) css_limit = int(request.form.get("css_limit", 0)) webhook_icon = request.form.get("webhook_icon", None) entry = db.session.query(Cosmetics).filter( Cosmetics.user_id == user_id).first() if entry: abort(409) user = Cosmetics(user_id) if css: css = css.lower() == "true" user.css = css if css_limit is not None: user.css_limit = css_limit if webhook_icon is not None: webhook_icon = webhook_icon.lower() == "true" user.webhook_icon = webhook_icon db.session.add(user) db.session.commit() return ('', 204)