4 Commits
2.0.6 ... 2.1.0

Author SHA1 Message Date
Fran Jurmanović
7e0c088fa7 increase minor version 2024-08-16 23:07:41 +02:00
Fran Jurmanović
43b4757696 change selectors to fit the new design 2024-08-16 23:00:39 +02:00
Fran Jurmanović
3c6bdeab60 add build script 2024-05-20 23:18:22 +02:00
Fran Jurmanović
11a26bff83 version increase 2024-04-17 20:54:09 +02:00
6 changed files with 18 additions and 11 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -1,9 +1,11 @@
{
"name": "legica-dana",
"version": "2.0.6",
"version": "2.1.0",
"main": "src/app.ts",
"scripts": {
"start": "bun run src/app.ts"
"start": "bun run src/app.ts",
"build-script": "bun build src/app.ts --outdir dist --target bun",
"start-build": "bun run dist/app.js"
},
"author": "Fran Jurmanović <fjurma12@outlook.com>",
"license": "MIT",
@@ -18,6 +20,7 @@
"discord.js": "^12.5.1",
"dotenv": "^8.2.0",
"elysia": "^0.7.15",
"ffmpeg-static": "^5.2.0",
"lodash-es": "^4.17.21",
"minimatch": "^9.0.3",
"pino": "^8.15.4",

View File

@@ -195,7 +195,8 @@ const taskPlugin = new Elysia({ prefix: "/job" })
return true;
} catch (err) {
set.status = 400;
return err;
logger.error(err);
return false;
}
},
{

View File

@@ -2,10 +2,10 @@ import { config } from "@constants";
import axios from "axios";
import cheerio from "cheerio";
export async function getFirstHtml(): Promise<string> {
export async function getFirstHtml(): Promise<string | undefined> {
const response = await axios.get(config.LEGICA_URL);
const html = response.data;
const $ = cheerio.load(html);
const { href } = $(".News-link.c-def")?.attr() || {};
const href = $(".legica-dana").first().find("a").attr("href");
return href;
}

View File

@@ -7,8 +7,9 @@ export async function getImgTitle(href: string): Promise<Legica> {
const html = response.data;
const $ = cheerio.load(html);
const title = $(".Article-inner > h1").text();
const { src: img } = $(".Article-media > img").attr() || {};
const title = $(".article-title-container > h1").text();
const src = $(".image-holder", ".article-content").find("img").attr("src");
if (!src) throw new Error(`Image not found at ${href}.`);
return { title, img };
return { title, img: src };
}

View File

@@ -11,7 +11,6 @@ export async function sendDiscordMessage(
url: string,
dateCheck?: dayjs.Dayjs
): Promise<void> {
if (!url) return;
const { img, title } = await getImgTitle(url);
if (dateCheck) {
@@ -26,7 +25,7 @@ export async function sendDiscordMessage(
);
}
client.channels.cache.forEach(async (channel) => {
const promises = client.channels.cache.map(async (channel) => {
try {
if (channel.type !== "text") return null;
const embeddedMessage = new MessageEmbed().setTitle(title).setImage(img);
@@ -50,13 +49,16 @@ export async function sendDiscordMessage(
console.error(`Reaction ${reaction} to channel ${channel.id} failed.`);
}
}
} catch {
} catch (err) {
console.error(`Message to channel ${channel.id} failed.`);
throw err;
}
});
await Promise.all(promises);
}
export async function sendNextMessage(client: Client): Promise<void> {
const href = await getFirstHtml();
if (!href) throw new Error("URL cannot be empty!");
await sendDiscordMessage(client, href, dayjs());
}