add a discord server for api users to help eachother

master
Aevann1 2022-07-18 02:46:46 +02:00
parent b84bd72beb
commit 81b762fbc2
6 changed files with 31 additions and 19 deletions

View File

@ -19,7 +19,7 @@ class OauthApp(Base):
description = Column(String)
author_id = Column(Integer, ForeignKey("users.id"))
author = relationship("User")
author = relationship("User", back_populates="apps")
def __repr__(self):
return f"<OauthApp(id={self.id})>"

View File

@ -138,6 +138,7 @@ class User(Base):
blocking = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.user_id", back_populates="user")
blocked = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.target_id", back_populates="target")
authorizations = relationship("ClientAuth", back_populates="user")
apps = relationship("OauthApp", back_populates="author")
awards = relationship("AwardRelationship", primaryjoin="User.id==AwardRelationship.user_id", back_populates="user")
referrals = relationship("User")

View File

@ -88,6 +88,16 @@ def discord_redirect(v):
v.discord_id=x["id"]
g.db.add(v)
if v.apps:
url=f"https://discord.com/api/guilds/998387482984980541/members/{x['id']}"
name=v.username
data={
"access_token":token,
"nick":name,
}
requests.put(url, headers=headers, json=data, timeout=5)
time.sleep(0.1)
url=f"https://discord.com/api/guilds/{DISCORD_SERVER_ID}/members/{x['id']}"
name=v.username

View File

@ -141,26 +141,27 @@ def admin_app_approve(v, aid):
app = g.db.get(OauthApp, aid)
user = app.author
app.client_id = secrets.token_urlsafe(64)[:64]
g.db.add(app)
if not app.client_id:
app.client_id = secrets.token_urlsafe(64)[:64]
g.db.add(app)
access_token = secrets.token_urlsafe(128)[:128]
new_auth = ClientAuth(
oauth_client = app.id,
user_id = user.id,
access_token=access_token
)
access_token = secrets.token_urlsafe(128)[:128]
new_auth = ClientAuth(
oauth_client = app.id,
user_id = user.id,
access_token=access_token
)
g.db.add(new_auth)
g.db.add(new_auth)
send_repeatable_notification(user.id, f"@{v.username} 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.")
send_repeatable_notification(user.id, f"@{v.username} 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!")
ma = ModAction(
kind="approve_app",
user_id=v.id,
target_user_id=user.id,
)
g.db.add(ma)
ma = ModAction(
kind="approve_app",
user_id=v.id,
target_user_id=user.id,
)
g.db.add(ma)
return {"message": "Application approved"}

View File

@ -34,7 +34,7 @@
<div class="d-flex">
{% if not app.client_id%}
<a role="button" class="btn btn-primary ml-auto" onclick="post_toast(this,'/admin/app/approve/{{app.id}}')">Approve</a>
<a role="button" class="btn btn-primary ml-auto mr-2" onclick="post_toast(this,'/admin/app/approve/{{app.id}}')">Approve</a>
<a role="button" class="btn btn-secondary mr-0" onclick="post_toast(this,'/admin/app/reject/{{app.id}}')">Reject</a>
{% else %}

View File

@ -39,7 +39,7 @@
<div class="d-flex">
{% if not app.client_id %}
<a role="button" class="btn btn-primary ml-auto" onclick="post_toast(this,'/admin/app/approve/{{app.id}}')">Approve</a>
<a role="button" class="btn btn-primary ml-auto mr-2" onclick="post_toast(this,'/admin/app/approve/{{app.id}}')">Approve</a>
<a role="button" class="btn btn-secondary mr-0" onclick="post_toast(this,'/admin/app/reject/{{app.id}}')">Reject</a>
{% else %}