3 Commits
2.0.4 ... 2.0.5

Author SHA1 Message Date
Fran Jurmanović
5aa69588fb add bot endpoints 2024-03-02 14:49:57 +01:00
Fran Jurmanović
28b028d056 increase version 2023-11-01 15:48:41 +01:00
Fran Jurmanović
4ac04d4457 formatting 2023-11-01 15:48:15 +01:00
2 changed files with 84 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "legica-dana",
"version": "2.0.4",
"version": "2.0.5",
"main": "src/app.ts",
"scripts": {
"start": "bun src/app.ts"

View File

@@ -29,6 +29,55 @@ async function jobRunner() {
logger.error(err);
}
}
const botPlugin = new Elysia({ prefix: "/bot" })
.use(
basicAuth({
users: [
{
username: "admin",
password: config.PASSWORD,
},
],
errorMessage: "Unauthorized",
})
)
.get(
"/",
() => ({
uptime: client.uptime,
readyAt: client.readyAt,
readyTimestamp: client.readyTimestamp,
}),
{
detail: {
summary: "Get BOT status",
},
}
)
.post(
"/",
() => {
client.login(config.TOKEN);
return "Bot logged in started";
},
{
detail: {
summary: "Start BOT if it is not running",
},
}
)
.delete(
"/",
() => {
client.destroy();
return "Bot logged out";
},
{
detail: {
summary: "Stops the BOT.",
},
}
);
const taskPlugin = new Elysia({ prefix: "/job" })
.use(
@@ -138,7 +187,7 @@ const taskPlugin = new Elysia({ prefix: "/job" })
"/send",
async ({ set, body }) => {
try {
const url = body.url;
const url = body?.url;
if (url) {
await sendDiscordMessage(client, url);
} else {
@@ -212,6 +261,7 @@ const app = new Elysia()
)
.use(staticPlugin())
.use(taskPlugin)
.use(botPlugin)
.listen(config.PORT);
client.login(config.TOKEN);