2022-02-01 03:49:12 +02:00
|
|
|
<!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>
|
2022-02-02 11:46:42 +02:00
|
|
|
<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>
|
2022-02-02 20:24:14 +02:00
|
|
|
<button onclick="getGuildInfo('822089558886842418');">get info</button>
|
|
|
|
<button onclick="getOwnUserInfo();">get own user info</button>
|
2022-02-02 11:46:42 +02:00
|
|
|
<button onclick="eventPoll('822089558886842418');">poll event</button>
|
|
|
|
|
2022-02-01 03:49:12 +02:00
|
|
|
|
|
|
|
<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
|
|
|
|
}
|
|
|
|
});
|
2022-02-02 11:46:42 +02:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2022-02-02 20:24:14 +02:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2022-02-02 11:46:42 +02:00
|
|
|
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());
|
2022-02-01 03:49:12 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|