diff --git a/dojo_plugin/pages/discord.py b/dojo_plugin/pages/discord.py index a98fccbc7..77b8389f2 100644 --- a/dojo_plugin/pages/discord.py +++ b/dojo_plugin/pages/discord.py @@ -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") diff --git a/dojo_plugin/utils/discord.py b/dojo_plugin/utils/discord.py index b2d314258..63a3b93fc 100644 --- a/dojo_plugin/utils/discord.py +++ b/dojo_plugin/utils/discord.py @@ -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 @@ -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")