diff --git a/files/classes/user.py b/files/classes/user.py index 478d372ab..a070a658c 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -2,7 +2,6 @@ from sqlalchemy.orm import deferred, aliased from sqlalchemy.sql import func from secrets import token_hex import pyotp -from files.helpers.discord import remove_user from files.helpers.media import * from files.helpers.const import * from files.classes.casino_game import Casino_Game @@ -819,7 +818,6 @@ class User(Base): if days: self.unban_utc = int(time.time()) + (days * 86400) g.db.add(self) - elif self.discord_id: remove_user(self) self.is_banned = admin.id if admin else AUTOJANNY_ID if reason and len(reason) <= 256: diff --git a/files/helpers/awards.py b/files/helpers/awards.py index 6986e59b6..637e2132f 100644 --- a/files/helpers/awards.py +++ b/files/helpers/awards.py @@ -2,7 +2,6 @@ from flask import g import time from files.helpers.alerts import send_repeatable_notification from files.helpers.const import * -from files.helpers.discord import remove_role from files.classes.badges import Badge from files.classes.user import User @@ -17,7 +16,6 @@ def award_timers(v, bot=False): v.patron = 0 v.patron_utc = 0 notify_if_not_bot(f"Your {patron} status has expired!") - if not bot and v.discord_id: remove_role(v, "1") if v.unban_utc and v.unban_utc < now: v.is_banned = 0 v.unban_utc = 0 diff --git a/files/helpers/const.py b/files/helpers/const.py index d419058f9..4dc688d9a 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -9,15 +9,11 @@ from flask import request import tldextract from os import path - SITE = environ.get("SITE").strip() SITE_NAME = environ.get("SITE_NAME").strip() SECRET_KEY = environ.get("SECRET_KEY").strip() PROXY_URL = environ.get("PROXY_URL").strip() GIPHY_KEY = environ.get('GIPHY_KEY').strip() -DISCORD_SERVER_ID = environ.get("DISCORD_SERVER_ID").strip() -DISCORD_CLIENT_ID = environ.get("DISCORD_CLIENT_ID").strip() -DISCORD_CLIENT_SECRET = environ.get("DISCORD_CLIENT_SECRET").strip() DISCORD_BOT_TOKEN = environ.get("DISCORD_BOT_TOKEN").strip() HCAPTCHA_SITEKEY = environ.get("HCAPTCHA_SITEKEY").strip() HCAPTCHA_SECRET = environ.get("HCAPTCHA_SECRET").strip() @@ -1239,8 +1235,6 @@ tiers={ "(Jigsaw)": 6, } -DISCORD_WELCOME_CHANNEL = "846509313941700618" - has_sidebar = path.exists(f'files/templates/sidebar_{SITE_NAME}.html') has_logo = path.exists(f'files/assets/images/{SITE_NAME}/logo.webp') has_app = path.exists(f'files/assets/app_{SITE_NAME}_v2.4.apk') diff --git a/files/helpers/discord.py b/files/helpers/discord.py index 7fe8ce844..c9f4517a9 100644 --- a/files/helpers/discord.py +++ b/files/helpers/discord.py @@ -1,49 +1,9 @@ import requests -import threading + from .const import * headers = {"Authorization": f"Bot {DISCORD_BOT_TOKEN}"} -def discord_wrap(f): - - def wrapper(*args, **kwargs): - - user=args[0] - if not user.discord_id: - return - - - thread=threading.Thread(target=f, args=args, kwargs=kwargs) - thread.start() - - wrapper.__name__=f.__name__ - return wrapper - - - -@discord_wrap -def add_role(user, role_name): - role_id = ROLES[role_name] - url = f"https://discordapp.com/api/guilds/{DISCORD_SERVER_ID}/members/{user.discord_id}/roles/{role_id}" - requests.put(url, headers=headers, timeout=5) - -@discord_wrap -def remove_role(user, role_name): - role_id = ROLES[role_name] - url = f"https://discordapp.com/api/guilds/{DISCORD_SERVER_ID}/members/{user.discord_id}/roles/{role_id}" - requests.delete(url, headers=headers, timeout=5) - -@discord_wrap -def remove_user(user): - url=f"https://discordapp.com/api/guilds/{DISCORD_SERVER_ID}/members/{user.discord_id}" - requests.delete(url, headers=headers, timeout=5) - -@discord_wrap -def set_nick(user, nick): - url=f"https://discordapp.com/api/guilds/{DISCORD_SERVER_ID}/members/{user.discord_id}" - data={"nick": nick} - requests.patch(url, headers=headers, json=data, timeout=5) - def send_changelog_message(message): data={"content": message} for id in DISCORD_CHANGELOG_CHANNEL_IDS: diff --git a/files/routes/admin.py b/files/routes/admin.py index 4a10abe49..382124c58 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -17,7 +17,6 @@ from flask import * from files.__main__ import app, cache, limiter from .front import frontlist from .login import check_for_alts -from files.helpers.discord import add_role import datetime import requests from urllib.parse import quote, urlencode diff --git a/files/routes/awards.py b/files/routes/awards.py index e2f3478ae..84c0a9b29 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -4,7 +4,6 @@ from files.helpers.alerts import * from files.helpers.get import * from files.helpers.const import * from files.helpers.regex import * -from files.helpers.discord import * from files.helpers.actions import * from files.classes.award import * from .front import frontlist @@ -19,8 +18,6 @@ from copy import deepcopy @auth_required @feature_required('AWARDS') def shop(v): - - AWARDS = deepcopy(AWARDS2) if v.house: @@ -311,7 +308,6 @@ def award_thing(v, thing_type, id): if author.patron_utc: author.patron_utc += 2629746 else: author.patron_utc = int(time.time()) + 2629746 author.procoins += 2500 - if author.discord_id: add_role(author, "1") badge_grant(user=v, badge_id=103) elif kind == "rehab": if author.rehab: author.rehab += 86400 diff --git a/files/routes/discord.py b/files/routes/discord.py deleted file mode 100644 index fff30625e..000000000 --- a/files/routes/discord.py +++ /dev/null @@ -1,127 +0,0 @@ -from files.helpers.wrappers import * -from files.helpers.security import * -from files.helpers.discord import add_role -from files.__main__ import app -import requests - - -@app.get("/discord") -@is_not_permabanned -def join_discord(v): - if v.shadowbanned: return {"error": "Internal Server Error"}, 500 - now=int(time.time()) - state=generate_hash(f"{now}+{v.id}+discord") - state=f"{now}.{state}" - return redirect(f"https://discord.com/api/oauth2/authorize?client_id={DISCORD_CLIENT_ID}&redirect_uri=https%3A%2F%2F{SITE}%2Fdiscord_redirect&response_type=code&scope=identify%20guilds.join&state={state}") - - -@app.get("/discord_redirect") -@is_not_permabanned -def discord_redirect(v): - if v.shadowbanned: abort(400) - now = int(time.time()) - state = request.values.get('state') - if not state or not '.' in state: abort(400) - state = state.split('.') - timestamp= state[0] - state= state[1] - - try: - if int(timestamp) < now-600: - abort(400) - except: - abort(400) - - if not validate_hash(f"{timestamp}+{v.id}+discord", state): - abort(400) - - code = request.values.get("code","") - if not code: - abort(400) - - data={ - "client_id": DISCORD_CLIENT_ID, - 'client_secret': DISCORD_CLIENT_SECRET, - 'grant_type': 'authorization_code', - 'code': code, - 'redirect_uri': f"https://{SITE}/discord_redirect", - 'scope': 'identify guilds.join' - } - headers={ - 'Content-Type': 'application/x-www-form-urlencoded' - } - url="https://discord.com/api/oauth2/token" - - x=requests.post(url, headers=headers, data=data, timeout=5) - - x=x.json() - - - token=x["access_token"] - - - url="https://discord.com/api/users/@me" - headers={ - 'Authorization': f"Bearer {token}" - } - x=requests.get(url, headers=headers, timeout=5) - - x=x.json() - - - - headers={ - 'Authorization': f"Bot {DISCORD_BOT_TOKEN}", - 'Content-Type': "application/json" - } - - if v.discord_id and v.discord_id != x['id']: - url=f"https://discord.com/api/guilds/{DISCORD_SERVER_ID}/members/{v.discord_id}" - requests.delete(url, headers=headers, timeout=5) - - if g.db.query(User).filter(User.id!=v.id, User.discord_id==x["id"]).one_or_none(): - return render_template("message.html", title="Discord account already linked.", error="This Discord account is already in use by another user.", v=v) - - v.discord_id=x["id"] - g.db.add(v) - - url=f"https://discord.com/api/guilds/{DISCORD_SERVER_ID}/members/{x['id']}" - - name=v.username - - data={ - "access_token":token, - "nick":name, - } - - x=requests.put(url, headers=headers, json=data, timeout=5) - - if x.status_code in {201, 204}: - time.sleep(0.1) - add_role(v, "linked") - - if v.patron: - time.sleep(0.1) - add_role(v, str(v.patron)) - - if SITE == 'rdrama.net' and v.id == AEVANN_ID: - time.sleep(0.1) - add_role(v, "admin") - - time.sleep(0.1) - requests.put("https://discord.com/api/guilds/913091440035389520/members/788152118669606932", headers=headers, json={"access_token":token,"roles":[915260962540511292]}, timeout=5) - else: - return x.json() - - - if x.status_code==204: - - url=f"https://discord.com/api/guilds/{DISCORD_SERVER_ID}/members/{v.discord_id}" - data={ - "nick": name - } - - requests.patch(url, headers=headers, json=data, timeout=5) - - - return redirect(f"https://discord.com/channels/{DISCORD_SERVER_ID}/{DISCORD_WELCOME_CHANNEL}") diff --git a/files/routes/front.py b/files/routes/front.py index 8356480c4..e33c140d9 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -1,6 +1,5 @@ from files.helpers.wrappers import * from files.helpers.get import * -from files.helpers.discord import * from files.helpers.const import * from files.helpers.sorting_and_time import * from files.__main__ import app, cache, limiter diff --git a/files/routes/oauth.py b/files/routes/oauth.py index bcab2073a..496d93c13 100644 --- a/files/routes/oauth.py +++ b/files/routes/oauth.py @@ -162,7 +162,7 @@ def admin_app_approve(v, aid): g.db.add(new_auth) - send_repeatable_notification(user.id, f"@{v.username} (Admin) has approved your application `{app.app_name}`. Here's your access token: `{access_token}`\nPlease check the guide [here](/api) if you don't know what to do next, and join this [discord server](/discord) if you need help!") + send_repeatable_notification(user.id, f"@{v.username} (Admin) has approved your application `{app.app_name}`. Here's your access token: `{access_token}`\nPlease check the guide [here](/api) if you don't know what to do next!") ma = ModAction( kind="approve_app", diff --git a/files/routes/settings.py b/files/routes/settings.py index 7a2480944..2b3d1bba2 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals from files.helpers.alerts import * from files.helpers.sanitize import * -from files.helpers.discord import remove_user, set_nick from files.helpers.const import * from files.helpers.regex import * from files.helpers.actions import * @@ -13,7 +12,6 @@ import youtube_dl from .front import frontlist import os from files.helpers.sanitize import filter_emojis_only -from files.helpers.discord import add_role from shutil import copyfile import requests import tldextract @@ -367,7 +365,6 @@ def gumroad(v): if existing: abort(400, f"{patron} rewards already claimed on another account") v.patron = tier - if v.discord_id: add_role(v, f"{tier}") v.procoins += procoins send_repeatable_notification(v.id, f"You have received {procoins} Marseybux! You can use them to buy awards in the [shop](/shop).") @@ -673,21 +670,6 @@ def settings_apps(v): return render_template("settings_apps.html", v=v) - -@app.post("/settings/remove_discord") -@limiter.limit("1/second;30/minute;200/hour;1000/day") -@limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}') -@auth_required -def settings_remove_discord(v): - - remove_user(v) - - v.discord_id=None - g.db.add(v) - - - return redirect("/settings/profile") - @app.get("/settings/content") @auth_required def settings_content_get(v): @@ -699,7 +681,6 @@ def settings_content_get(v): @limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}') @is_not_permabanned def settings_name_change(v): - new_name=request.values.get("name").strip() if new_name==v.username: @@ -727,15 +708,10 @@ def settings_name_change(v): error=f"Username `{new_name}` is already in use.") v=get_account(v.id) - v.username=new_name v.name_changed_utc=int(time.time()) - - set_nick(v, new_name) - g.db.add(v) - return redirect("/settings/profile") diff --git a/files/routes/users.py b/files/routes/users.py index 16fc1b262..f8b6a39db 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1247,7 +1247,6 @@ def settings_kofi(v): tier = kofi_tiers[transaction.amount] v.patron = tier - if v.discord_id: add_role(v, f"{tier}") procoins = procoins_li[tier] diff --git a/files/templates/header.html b/files/templates/header.html index 28c210c7d..3b4907190 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -256,7 +256,6 @@ {% if SITE_NAME == 'rDrama' %} Telegram Channel Telegram Chat - Discord {% endif %} {% if SITE_NAME == 'rDrama' %} @@ -322,7 +321,6 @@ {% if SITE_NAME == 'rDrama' %} Telegram Channel Telegram Chat - Discord {% endif %} {% if SITE_NAME == 'rDrama' %}Archives{% endif %} diff --git a/files/templates/settings_profile.html b/files/templates/settings_profile.html index 5eb974351..69a358512 100644 --- a/files/templates/settings_profile.html +++ b/files/templates/settings_profile.html @@ -308,42 +308,6 @@ - - {% if SITE_NAME == 'rDrama' %} -

Linked Accounts

- -

Manage your connections to other services.

- -
- -
- -
- -
- -
- - {% if v.discord_id %} -
- - -
- -
Disconnecting your Discord account will remove you from the {{SITE_NAME}} Discord server.
- {% else %} - Link Discord -
Link your Discord account to join the {{SITE_NAME}} Discord server.
- {% endif %} - -
- -
- -
- {% endif %} - -

RSS Feed

Subscribe to the {{SITE_NAME}} RSS feed.