93 lines
No EOL
3.3 KiB
HTML
93 lines
No EOL
3.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
</head>
|
|
<body>
|
|
<button onclick="createToken('testinguser', '0', ['822089558886842418']);">create token</button>
|
|
<button onclick="sendMessage('822089558886842418', '822089558886842421', 'hello');">send message</button>
|
|
<button onclick="getChannels('822089558886842418');">get channels</button>
|
|
<button onclick="getGuildInfo('822089558886842418');">get info</button>
|
|
<button onclick="getOwnUserInfo();">get own user info</button>
|
|
<button onclick="eventPoll('822089558886842418');">poll event</button>
|
|
|
|
|
|
<script>
|
|
let createdToken;
|
|
|
|
async function createToken(username, discordID, guildAccess) {
|
|
const res = await fetch("http://localhost:4050/api/v1/tokens/create", {
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
username,
|
|
discordID,
|
|
guildAccess
|
|
}),
|
|
headers: {
|
|
"content-type": "application/json"
|
|
}
|
|
});
|
|
const json = await res.json();
|
|
console.log("createToken()", json);
|
|
createdToken = json.token;
|
|
}
|
|
|
|
async function sendMessage(guildId, channelId, content) {
|
|
const res = await fetch(`http://localhost:4050/api/v1/guilds/${guildId}/channels/${channelId}/messages/create`, {
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
content
|
|
}),
|
|
headers: {
|
|
"content-type": "application/json",
|
|
"authorization": createdToken
|
|
}
|
|
});
|
|
console.log("sendMessage() stauts", await res.status);
|
|
}
|
|
|
|
async function getChannels(guildId) {
|
|
const res = await fetch(`http://localhost:4050/api/v1/guilds/${guildId}/channels`, {
|
|
method: "GET",
|
|
headers: {
|
|
"authorization": createdToken
|
|
}
|
|
});
|
|
console.log("getChannels()", await res.json());
|
|
}
|
|
|
|
async function getGuildInfo(guildId) {
|
|
const res = await fetch(`http://localhost:4050/api/v1/guilds/${guildId}`, {
|
|
method: "GET",
|
|
headers: {
|
|
"authorization": createdToken
|
|
}
|
|
});
|
|
console.log("getGuildInfo()", await res.json());
|
|
}
|
|
|
|
async function getOwnUserInfo() {
|
|
const res = await fetch(`http://localhost:4050/api/v1/users/@self`, {
|
|
method: "GET",
|
|
headers: {
|
|
"authorization": createdToken
|
|
}
|
|
});
|
|
console.log("getOwnUserInfo()", await res.json());
|
|
}
|
|
|
|
async function eventPoll(guildId) {
|
|
const res = await fetch(`http://localhost:4050/api/v1/guilds/${guildId}/events/poll`, {
|
|
method: "GET",
|
|
headers: {
|
|
"authorization": createdToken
|
|
}
|
|
});
|
|
console.log("eventPoll()", await res.json());
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |