simple homepage for bot invite and usage instructions
This commit is contained in:
@@ -14,6 +14,9 @@ public class HandlerKernel implements HttpHandler {
|
|||||||
|
|
||||||
public HandlerKernel() {
|
public HandlerKernel() {
|
||||||
handlers.add(new GetDiscordInviteByGuildId());
|
handlers.add(new GetDiscordInviteByGuildId());
|
||||||
|
|
||||||
|
// Static endpoints
|
||||||
|
handlers.add(new MainEndpoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package me.youhavetrouble.inviter.http.endpoints;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
import me.youhavetrouble.inviter.Main;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class MainEndpoint implements EndpointHandler {
|
||||||
|
|
||||||
|
private final Pattern pathPattern = Pattern.compile("^/$");
|
||||||
|
|
||||||
|
private final String template;
|
||||||
|
|
||||||
|
public MainEndpoint() {
|
||||||
|
String rawTemplate = null;
|
||||||
|
try (InputStream resource = this.getClass().getResourceAsStream("/template/index.html")) {
|
||||||
|
rawTemplate = new String(resource.readAllBytes());
|
||||||
|
rawTemplate = rawTemplate.replaceAll("\\{\\{discord_app_id}}", Main.getJda().getSelfUser().getApplicationId());
|
||||||
|
} catch (IOException | NullPointerException e) {
|
||||||
|
Main.LOGGER.warn("Failed to load template for main endpoint", e);
|
||||||
|
}
|
||||||
|
this.template = rawTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Pattern pathPattern() {
|
||||||
|
return pathPattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(@NotNull HttpExchange exchange) throws IOException {
|
||||||
|
if (template == null) {
|
||||||
|
exchange.sendResponseHeaders(404, -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exchange.getRequestMethod().equals("GET")) {
|
||||||
|
exchange.sendResponseHeaders(405, -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
exchange.getResponseHeaders().set("Content-Type", "text/html; charset=UTF-8");
|
||||||
|
exchange.sendResponseHeaders(200, template.getBytes(StandardCharsets.UTF_8).length);
|
||||||
|
exchange.getResponseBody().write(template.getBytes(StandardCharsets.UTF_8));
|
||||||
|
exchange.getResponseBody().close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta name="title" content="Discord Inviter">
|
||||||
|
<meta name="description" content="A simple tool to invite users to a Discord server"/>
|
||||||
|
<meta name="keywords" content="Discord, Inviter, Tool, Invite Users"/>
|
||||||
|
<meta name="author" content="YouHaveTrouble"/>
|
||||||
|
<meta name="og:type" content="website"/>
|
||||||
|
<meta name="og:title" content="Discord Inviter"/>
|
||||||
|
<meta name="og:description" content="A simple tool to invite users to a Discord server"/>
|
||||||
|
<meta name="og:url" content="https://inviter.yht.one"/>
|
||||||
|
<meta name="twitter:title" content="Discord Inviter"/>
|
||||||
|
<meta name="twitter:description" content="A simple tool to invite users to a Discord server"/>
|
||||||
|
<title>Discord Inviter</title>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--color-primary: #5865F2;
|
||||||
|
--color-primary-highlight: #4752C4;
|
||||||
|
--color-text: #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-family: system-ui, sans-serif;
|
||||||
|
font-weight: normal;
|
||||||
|
vertical-align: baseline;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
line-height: 1.5;
|
||||||
|
background-color: #272727;
|
||||||
|
color: var(--color-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
min-height: 100vh;
|
||||||
|
padding: 1rem;
|
||||||
|
gap: 2rem;
|
||||||
|
text-align: center;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
ol, ul {
|
||||||
|
text-align: left;
|
||||||
|
margin-left: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0.1rem 0.2rem;
|
||||||
|
background-color: rgba(255, 255, 255, 0.05);
|
||||||
|
border-radius: 0.2rem;
|
||||||
|
white-space: break-spaces;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
a[href]:not([role="button"]) {
|
||||||
|
color: var(--color-primary);
|
||||||
|
text-decoration: none;
|
||||||
|
transition: color 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
a[href]:not([role="button"]):hover {
|
||||||
|
color: var(--color-primary-highlight);
|
||||||
|
}
|
||||||
|
|
||||||
|
[role="button"] {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
background-color: var(--color-primary);
|
||||||
|
color: var(--color-text);
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
transition: background-color 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
[role="button"]:hover {
|
||||||
|
background-color: var(--color-primary-highlight);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
<div>
|
||||||
|
<h1>Inviter</h1>
|
||||||
|
<p>Creates permanent invite links that make and recreate invite links if they expire or get removed.</p>
|
||||||
|
<a
|
||||||
|
role="button"
|
||||||
|
href="https://discord.com/oauth2/authorize?client_id={{discord_app_id}}"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>Install the bot</a>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h2>Usage</h2>
|
||||||
|
<ol>
|
||||||
|
<li>Install the bot using the button above.</li>
|
||||||
|
<li>
|
||||||
|
<a
|
||||||
|
href="https://discord.com/developers/docs/activities/building-an-activity#step-0-enable-developer-mode"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
Enable developer mode
|
||||||
|
</a> in your discord client and copy your guilds ID.
|
||||||
|
</li>
|
||||||
|
<li>Now you can use <span class="highlight">https://inviter.yht.one/invite/<your_guild_id></span></li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user