Created
April 14, 2023 22:55
-
-
Save NotArchon/25ea84bbecaa242b624a05749dc9ede8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.neox.web.pages; | |
| import io.archon.discord.DiscordInteraction; | |
| import io.archon.discord.api.Interaction; | |
| import io.archon.discord.api.interactions.Ping; | |
| import io.archon.web.model.PageHandler; | |
| import io.archon.web.network.HttpAsyncRequest; | |
| import io.archon.web.network.messages.JsonMessage; | |
| import io.archon.web.network.messages.StatusMessage; | |
| import io.archon.web.other.PageMapper; | |
| import io.netty5.handler.codec.http.HttpResponseStatus; | |
| @PageMapper("/discord-interactions") | |
| public class DiscordInteractionsPage implements PageHandler, DiscordInteraction.Handler { | |
| private HttpAsyncRequest httpReq; | |
| private boolean validateRequest(HttpAsyncRequest httpReq) { | |
| String sig = (String) httpReq.headers().get("HTTP_X_SIGNATURE_ED25519"); | |
| String time = (String) httpReq.headers().get("HTTP_X_SIGNATURE_TIMESTAMP"); | |
| if(sig == null || time == null) | |
| return false; | |
| System.err.println(" sig=" + sig); | |
| System.err.println(" time=" + time); | |
| // todo | |
| return true; | |
| } | |
| @Override | |
| public void handle(HttpAsyncRequest httpReq) { | |
| System.err.println("Discord Interaction:"); | |
| if(!validateRequest(httpReq)) { | |
| httpReq.write(new StatusMessage(HttpResponseStatus.UNAUTHORIZED)); | |
| return; | |
| } | |
| System.err.println(" post=" + httpReq.getPostData()); | |
| this.httpReq = httpReq; | |
| DiscordInteraction.handle(httpReq.getPostData(), this); | |
| } | |
| @Override | |
| public void handle(Interaction interaction, Ping ping) { | |
| httpReq.write(JsonMessage.normal(ping.pong())); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment