Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5aa69588fb | ||
|
|
28b028d056 | ||
|
|
4ac04d4457 | ||
|
|
9d137b6b52 | ||
|
|
79110bdb1c | ||
|
|
0d2fba3883 | ||
|
|
77aa924161 |
66
package.json
66
package.json
@@ -1,35 +1,35 @@
|
||||
{
|
||||
"name": "legica-dana",
|
||||
"version": "2.0.2",
|
||||
"main": "src/app.ts",
|
||||
"scripts": {
|
||||
"start": "bun src/app.ts"
|
||||
},
|
||||
"author": "Fran Jurmanović <fjurma12@outlook.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@elysiajs/cron": "^0.7.0",
|
||||
"@elysiajs/static": "^0.7.1",
|
||||
"@elysiajs/swagger": "^0.7.3",
|
||||
"axios": "^0.26.0",
|
||||
"body-parser": "^1.20.2",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"dayjs": "^1.11.10",
|
||||
"discord.js": "^12.5.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"elysia": "^0.7.15",
|
||||
"lodash-es": "^4.17.21",
|
||||
"minimatch": "^9.0.3",
|
||||
"pino": "^8.15.4",
|
||||
"typescript": "^4.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash-es": "^4.17.9",
|
||||
"@types/node": "^20.8.2",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
||||
"@typescript-eslint/parser": "^6.7.4",
|
||||
"bun-types": "^1.0.4-canary.20231004T140131",
|
||||
"eslint": "^8.50.0",
|
||||
"prettier": "^2.2.1"
|
||||
}
|
||||
"name": "legica-dana",
|
||||
"version": "2.0.5",
|
||||
"main": "src/app.ts",
|
||||
"scripts": {
|
||||
"start": "bun src/app.ts"
|
||||
},
|
||||
"author": "Fran Jurmanović <fjurma12@outlook.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@elysiajs/cron": "^0.7.0",
|
||||
"@elysiajs/static": "^0.7.1",
|
||||
"@elysiajs/swagger": "^0.7.3",
|
||||
"axios": "^0.26.0",
|
||||
"body-parser": "^1.20.2",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"dayjs": "^1.11.10",
|
||||
"discord.js": "^12.5.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"elysia": "^0.7.15",
|
||||
"lodash-es": "^4.17.21",
|
||||
"minimatch": "^9.0.3",
|
||||
"pino": "^8.15.4",
|
||||
"typescript": "^4.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash-es": "^4.17.9",
|
||||
"@types/node": "^20.8.2",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
||||
"@typescript-eslint/parser": "^6.7.4",
|
||||
"bun-types": "^1.0.4-canary.20231004T140131",
|
||||
"eslint": "^8.50.0",
|
||||
"prettier": "^2.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
52
src/app.ts
52
src/app.ts
@@ -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);
|
||||
|
||||
@@ -6,8 +6,6 @@ import { Client, MessageEmbed, TextChannel } from "discord.js";
|
||||
|
||||
dayjs.extend(customParseFormat);
|
||||
|
||||
const dateRegex = /\d{1,2}.\d{1,2}.\d{4}/g;
|
||||
|
||||
export async function sendDiscordMessage(
|
||||
client: Client,
|
||||
url: string,
|
||||
@@ -17,6 +15,7 @@ export async function sendDiscordMessage(
|
||||
const { img, title } = await getImgTitle(url);
|
||||
|
||||
if (dateCheck) {
|
||||
const dateRegex = /\d{1,2}.\d{1,2}.\d{4}/g;
|
||||
const date = dateRegex.exec(title)?.[0];
|
||||
const dayjsDate = dayjs(date, config.LEGICA_DATE_FORMAT);
|
||||
if (!dateCheck.isSame(dayjsDate, "D"))
|
||||
|
||||
@@ -17,7 +17,7 @@ const config: ProjectConfig = {
|
||||
APP_VERSION: version,
|
||||
LEGICA_URL: "https://sib.net.hr/legica-dana",
|
||||
TIMEZONE: process.env.TIMEZONE || "utc",
|
||||
LEGICA_DATE_FORMAT: process.env.LEGICA_DATE_FORMAT || "DD.MM.YYYY",
|
||||
LEGICA_DATE_FORMAT: process.env.LEGICA_DATE_FORMAT || "D.M.YYYY",
|
||||
};
|
||||
|
||||
export { config };
|
||||
|
||||
Reference in New Issue
Block a user