From 33e2c2a9bd77ee681260414dfba30c7eacc474f1 Mon Sep 17 00:00:00 2001 From: Phoscur Date: Sun, 24 Nov 2024 22:31:34 +0100 Subject: [PATCH] Fix minor --- ecosystem.config.cjs | 11 ++++++++++- jest.config.js | 5 ----- package-lock.json | 6 +++--- package.json | 6 +++--- src/commands/index.ts | 1 + src/context.ts | 2 +- src/i18n.ts | 6 ++++-- src/main.ts | 6 +++++- src/photoStage.ts | 16 +++++++++++----- src/services/Camera.ts | 2 +- src/services/Producer.ts | 4 ++-- src/services/Timelapse.ts | 2 ++ 12 files changed, 43 insertions(+), 24 deletions(-) delete mode 100644 jest.config.js diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs index 921ece5..1f25c93 100644 --- a/ecosystem.config.cjs +++ b/ecosystem.config.cjs @@ -8,7 +8,16 @@ module.exports = { watch: true, // Delay between restart watch_delay: 1000, - ignore_watch: ['node_modules', 'src', 'sun*', 'ecosystem.config.js', 'README.md'], + ignore_watch: [ + 'node_modules', + 'src', + 'stora*', + 'sun*', + 'time*', + 'photo*', + 'ecosystem.config.js', + 'README.md', + ], watch_options: { followSymlinks: false, }, diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 5839600..0000000 --- a/jest.config.js +++ /dev/null @@ -1,5 +0,0 @@ -/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */ -module.exports = { - preset: 'ts-jest', - testEnvironment: 'node', -}; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d12e21c..4283397 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3078,9 +3078,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "license": "MIT", "dependencies": { "path-key": "^3.1.0", diff --git a/package.json b/package.json index 701e677..e3f30f7 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,10 @@ "scripts": { "start": "tsx --env-file=.env src/main.ts", "command": "tsx --env-file=.env src/commands/index.ts", - "production": "npm run build && npm run run-built", - "run-built": "node --env-file=.env dist/main.js", - "lint": "oxlint", + "production": "npm run build && npm run built", "build": "tsc -b", + "built": "node --env-file=.env dist/main.js", + "lint": "oxlint", "clean-build": "tsc -b --clean", "watch": "tsx watch --env-file=.env src/main.ts", "test": "vitest", diff --git a/src/commands/index.ts b/src/commands/index.ts index e0dbf9b..4215b08 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -8,6 +8,7 @@ const logger = di.get(Logger); const args = process.argv.slice(3); const command = process.argv[2]; /* +Full backup & restore 1. Tar/Gzip & Upload diff --git a/src/context.ts b/src/context.ts index cd972f6..a4e597b 100644 --- a/src/context.ts +++ b/src/context.ts @@ -79,7 +79,7 @@ export function createTelegramMessengerChat( getMessage: messageFactory.bind(null, bot, chatId), getChannelMessage: messageFactory.bind(null, bot, copyTargetChatId), sendMessage: bot.telegram.sendMessage.bind(bot.telegram, chatId), - sendMessageCopy: bot.telegram.copyMessage.bind(bot.telegram, chatId, copyTargetChatId), + sendMessageCopy: bot.telegram.copyMessage.bind(bot.telegram, copyTargetChatId, chatId), sendPhoto: bot.telegram.sendPhoto.bind(bot.telegram, chatId), sendAnimation: bot.telegram.sendAnimation.bind(bot.telegram, chatId), createAnimation: async ( diff --git a/src/i18n.ts b/src/i18n.ts index ef120c8..97ad153 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -27,7 +27,7 @@ const base = { }, de: { 'action.presetSwitch': 'Einstellung wechseln ๐Ÿ“ท', - 'action.shotSingle': 'Einzelschuss ๐Ÿฅƒ', + 'action.shotSingle': 'Schรผsschen ๐Ÿฅƒ', 'action.timelapse': 'Zeitraffer jetzt ๐ŸŽฅ', 'action.timelapse-half': 'Halber ๐ŸŽฅ', 'action.timelapse-third': 'Drittel ๐ŸŽฅ', @@ -51,7 +51,9 @@ type BasicEntry = keyof BasicIndex; export type SlottedTranslate = (index: BasicIndex, ...args: BasicEntry[]) => string; export function dateFormat(d = new Date()) { - return `${d.getDate()}.${d.getMonth() + 1}.${d.getFullYear()} ${d.getHours()}:${d.getMinutes()}`; + const clock = d.toLocaleTimeString().slice(0, 5); + // js dates are the best, I don't regret to have removed dayjs at all!!11 + return `${d.getDate()}.${d.getMonth() + 1}.${d.getFullYear()} ${clock}`; } const composite = { diff --git a/src/main.ts b/src/main.ts index 778f92f..ad2ae9c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -41,4 +41,8 @@ async function setupBot() { process.once('SIGTERM', () => bot.stop('SIGTERM')); } -setupBot().then(() => console.log('๐Ÿš€ Bot is running!')); +setupBot().then(() => + console.log( + `๐Ÿš€ Bot is running!\n(In chat [${process.env.TELEGRAM_CHAT_ID}], sharing to channel [${process.env.TELEGRAM_CHANNEL_ID}])` + ) +); diff --git a/src/photoStage.ts b/src/photoStage.ts index 1f75fc9..0529019 100644 --- a/src/photoStage.ts +++ b/src/photoStage.ts @@ -67,6 +67,7 @@ export function buildStage(bot: Telegraf) { // --------------------------------------------------------------------------------------------------- // Sharing / Publishing: Collecting Appraisals + // TODO? let clickLock = false; scene.action(Publisher.ACTION.SHARE, async (ctx, next) => { const publisher = ctx.di.get(Publisher); @@ -76,9 +77,8 @@ export function buildStage(bot: Telegraf) { if (!~ADMINS.indexOf(user)) { return ctx.answerCbQuery(publisher.callbackMessageNoPermission); } + if (!isActionableMessage(message)) return next(); - if (!message) return next(); - if (isTextMessage(message)) return next(); await publisher.share(ctx.group, message.message_id); await ctx.answerCbQuery(publisher.callbackMessageShare); }); @@ -89,7 +89,7 @@ export function buildStage(bot: Telegraf) { const { message } = ctx.callbackQuery; const user = ctx.from?.username || 'Anonymous'; - if (!(isPhotoMessage(message) || isVideoMessage(message))) return next(); + if (!isActionableMessage(message)) return next(); const liked = await publisher.saveLike(message.message_id, user, data); await publisher.updateCaptions(ctx.group, message.message_id); @@ -102,7 +102,7 @@ export function buildStage(bot: Telegraf) { const { message } = ctx.callbackQuery; const user = ctx.from?.username || ''; - if (!(isPhotoMessage(message) || isVideoMessage(message))) return next(); + if (!isActionableMessage(message)) return next(); if (!~ADMINS.indexOf(user)) { return ctx.answerCbQuery(publisher.callbackMessageNoPermission); @@ -242,6 +242,12 @@ function isTextMessage(message: any): message is Message.TextMessage { function isVideoMessage(message: any): message is Message.VideoMessage { return 'video' in message; } +function isAnimationMessage(message: any): message is Message.AnimationMessage { + return 'animation' in message; +} function isPhotoMessage(message: any): message is Message.PhotoMessage { - return 'video' in message; + return 'photo' in message; +} +function isActionableMessage(message: any) { + return isAnimationMessage(message) || isVideoMessage(message) || isPhotoMessage(message); } diff --git a/src/services/Camera.ts b/src/services/Camera.ts index 60d51b1..73ce8e1 100644 --- a/src/services/Camera.ts +++ b/src/services/Camera.ts @@ -9,7 +9,7 @@ export class Camera { name = 'still-test'; options: StillOptions = { roi: '', // x,y,w,h - height: 1080, + // height: 1080, }; #mutex: Promise | false = false; diff --git a/src/services/Producer.ts b/src/services/Producer.ts index 3a12623..8228321 100644 --- a/src/services/Producer.ts +++ b/src/services/Producer.ts @@ -35,8 +35,8 @@ export class Producer { { count: 420, intervalMS: 12000, prefix: 'timelapse' }, { count: 210, intervalMS: 12000, prefix: 'timelapse-half' }, { count: 140, intervalMS: 12000, prefix: 'timelapse-third' }, - { count: 30, intervalMS: 2000, prefix: 'timelapse-short' }, - { count: 14, intervalMS: 2000, prefix: 'timelapse-super-short' }, + { count: 30, intervalMS: 3000, prefix: 'timelapse-short' }, + { count: 14, intervalMS: 3000, prefix: 'timelapse-super-short' }, ] as const; #logger = inject(Logger); diff --git a/src/services/Timelapse.ts b/src/services/Timelapse.ts index 0ed75da..6938270 100644 --- a/src/services/Timelapse.ts +++ b/src/services/Timelapse.ts @@ -119,6 +119,8 @@ export class Timelapse { events.emit('error', error); abort(); } + } finally { + logger.timeEnd('timelapse'); } }; setTimeout(() => {