Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM users upon successful discord linking #412

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dojo_plugin/pages/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,12 @@ def discord_redirect():
db.session.rollback()
return {"success": False, "error": "Discord user already in use"}, 400

# DM the user the flag for white belt
discord_dojo = Dojos.from_id("discord-dojo").first()
if discord_dojo:
discord_challenge == discord_dojo.modules[0].challenges[0]
flag = serialize_user_flag(user_id, discord_challenge.challenge_id)
send_dm("""You have linked your pwn.college account with this discord account! You may now submit the flag: {flag}.""", discord_id)
send_dm("""**NOTE:** This is the ONLY communication from pwn.college that you will receive over discord DMs. Assume any other communication is a phishing attempt!""", discord_id)

return redirect("/settings#discord")
8 changes: 8 additions & 0 deletions dojo_plugin/utils/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def discord_request(endpoint, method="GET", **json):
def guild_request(endpoint, method="GET", **json):
return discord_request(f"/guilds/{DISCORD_GUILD_ID}{endpoint}", method=method, **json)

def bot_request(endpoint, method="GET", **json):
return discord_request(f"/users/@me{endpoint}", method=method, **json)


def get_bot_join_server_url():
# "Server Members Intent" also required
Expand Down Expand Up @@ -94,6 +97,11 @@ def send_message(message, channel_name):
discord_request(f"/channels/{channel_id}/messages", method="POST", content=message)


def send_dm(message, recipient_id):
channel_id = bot_request("/channels", method="POST", recipient_id=recipient_id)["id"]
discord_request(f"/channels/{channel_id}/messages", method="POST", content=message)


def add_role(discord_id, role_name):
role_id = get_discord_roles()[role_name]
guild_request(f"/members/{discord_id}/roles/{role_id}", method="PUT")
Loading