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,35 +1,35 @@
{ {
"name": "legica-dana", "name": "legica-dana",
"version": "2.0.4", "version": "2.0.5",
"main": "src/app.ts", "main": "src/app.ts",
"scripts": { "scripts": {
"start": "bun src/app.ts" "start": "bun src/app.ts"
}, },
"author": "Fran Jurmanović <fjurma12@outlook.com>", "author": "Fran Jurmanović <fjurma12@outlook.com>",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@elysiajs/cron": "^0.7.0", "@elysiajs/cron": "^0.7.0",
"@elysiajs/static": "^0.7.1", "@elysiajs/static": "^0.7.1",
"@elysiajs/swagger": "^0.7.3", "@elysiajs/swagger": "^0.7.3",
"axios": "^0.26.0", "axios": "^0.26.0",
"body-parser": "^1.20.2", "body-parser": "^1.20.2",
"cheerio": "^1.0.0-rc.10", "cheerio": "^1.0.0-rc.10",
"dayjs": "^1.11.10", "dayjs": "^1.11.10",
"discord.js": "^12.5.1", "discord.js": "^12.5.1",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"elysia": "^0.7.15", "elysia": "^0.7.15",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"minimatch": "^9.0.3", "minimatch": "^9.0.3",
"pino": "^8.15.4", "pino": "^8.15.4",
"typescript": "^4.1.5" "typescript": "^4.1.5"
}, },
"devDependencies": { "devDependencies": {
"@types/lodash-es": "^4.17.9", "@types/lodash-es": "^4.17.9",
"@types/node": "^20.8.2", "@types/node": "^20.8.2",
"@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4", "@typescript-eslint/parser": "^6.7.4",
"bun-types": "^1.0.4-canary.20231004T140131", "bun-types": "^1.0.4-canary.20231004T140131",
"eslint": "^8.50.0", "eslint": "^8.50.0",
"prettier": "^2.2.1" "prettier": "^2.2.1"
} }
} }

View File

@@ -29,6 +29,55 @@ async function jobRunner() {
logger.error(err); 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" }) const taskPlugin = new Elysia({ prefix: "/job" })
.use( .use(
@@ -138,7 +187,7 @@ const taskPlugin = new Elysia({ prefix: "/job" })
"/send", "/send",
async ({ set, body }) => { async ({ set, body }) => {
try { try {
const url = body.url; const url = body?.url;
if (url) { if (url) {
await sendDiscordMessage(client, url); await sendDiscordMessage(client, url);
} else { } else {
@@ -212,6 +261,7 @@ const app = new Elysia()
) )
.use(staticPlugin()) .use(staticPlugin())
.use(taskPlugin) .use(taskPlugin)
.use(botPlugin)
.listen(config.PORT); .listen(config.PORT);
client.login(config.TOKEN); client.login(config.TOKEN);