remove discord
parent
4b2ce3b7a0
commit
aa508fc076
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}")
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -256,7 +256,6 @@
|
|||
{% if SITE_NAME == 'rDrama' %}
|
||||
<a rel="nofollow noopener noreferrer" class="dropdown-item" href="https://t.me/rdramanet"><i class="fab fa-telegram fa-fw mr-3"></i>Telegram Channel</a>
|
||||
<a rel="nofollow noopener noreferrer" class="dropdown-item" href="https://t.me/+tOgq7xeeir83OTU0"><i class="fab fa-telegram fa-fw mr-3"></i>Telegram Chat</a>
|
||||
<a class="dropdown-item" href="/discord"><i class="fab fa-discord fa-fw mr-3"></i>Discord</a>
|
||||
{% endif %}
|
||||
|
||||
{% if SITE_NAME == 'rDrama' %}
|
||||
|
@ -322,7 +321,6 @@
|
|||
{% if SITE_NAME == 'rDrama' %}
|
||||
<a rel="nofollow noopener noreferrer" class="nav-item nav-link" href="https://t.me/rdramanet"><i class="fab fa-telegram fa-fw mr-3"></i>Telegram Channel</a>
|
||||
<a rel="nofollow noopener noreferrer" class="nav-item nav-link" href="https://t.me/+tOgq7xeeir83OTU0"><i class="fab fa-telegram fa-fw mr-3"></i>Telegram Chat</a>
|
||||
<a class="nav-item nav-link" href="/discord"><i class="fab fa-discord fa-fw mr-3"></i>Discord</a>
|
||||
{% endif %}
|
||||
|
||||
{% if SITE_NAME == 'rDrama' %}<a class="nav-item nav-link" href="/archives"><i class="fas fa-book fa-fw mr-3"></i>Archives</a>{% endif %}
|
||||
|
|
|
@ -308,42 +308,6 @@
|
|||
|
||||
</div>
|
||||
|
||||
|
||||
{% if SITE_NAME == 'rDrama' %}
|
||||
<h2 class="h5" name="referral">Linked Accounts</h2>
|
||||
|
||||
<p class="text-small text-muted">Manage your connections to other services.</p>
|
||||
|
||||
<div class="settings-section rounded">
|
||||
|
||||
<div class="d-lg-flex">
|
||||
|
||||
<div class="title w-lg-25">
|
||||
<label>Discord</label>
|
||||
</div>
|
||||
|
||||
<div class="body w-lg-100">
|
||||
|
||||
{% if v.discord_id %}
|
||||
<form action="/settings/remove_discord" method="post">
|
||||
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||
<input type="submit" onclick="disable(this)" class="btn btn-secondary text-capitalize mr-2 mb-0 mt-2" value="Disconnect Discord">
|
||||
</form>
|
||||
|
||||
<div class="text-small text-muted mt-3">Disconnecting your Discord account will remove you from the {{SITE_NAME}} Discord server.</div>
|
||||
{% else %}
|
||||
<a href="/discord" class="btn btn-primary">Link Discord</a>
|
||||
<div class="text-small text-muted mt-3">Link your Discord account to join the {{SITE_NAME}} Discord server.</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<h2 class="h5" name="referral">RSS Feed</h2>
|
||||
|
||||
<p class="text-small text-muted">Subscribe to the {{SITE_NAME}} RSS feed.</p>
|
||||
|
|
Loading…
Reference in New Issue