Skip to content

Commit

Permalink
Fix minor
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoscur committed Nov 24, 2024
1 parent bc0ede7 commit 33e2c2a
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 24 deletions.
11 changes: 10 additions & 1 deletion ecosystem.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
5 changes: 0 additions & 5 deletions jest.config.js

This file was deleted.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 4 additions & 2 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 🎥',
Expand All @@ -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 = {
Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}])`
)
);
16 changes: 11 additions & 5 deletions src/photoStage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function buildStage(bot: Telegraf<PhiloContext>) {

// ---------------------------------------------------------------------------------------------------
// Sharing / Publishing: Collecting Appraisals
// TODO? let clickLock = false;

scene.action(Publisher.ACTION.SHARE, async (ctx, next) => {
const publisher = ctx.di.get(Publisher);
Expand All @@ -76,9 +77,8 @@ export function buildStage(bot: Telegraf<PhiloContext>) {
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);
});
Expand All @@ -89,7 +89,7 @@ export function buildStage(bot: Telegraf<PhiloContext>) {

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);
Expand All @@ -102,7 +102,7 @@ export function buildStage(bot: Telegraf<PhiloContext>) {

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);
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/services/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Camera {
name = 'still-test';
options: StillOptions = {
roi: '', // x,y,w,h
height: 1080,
// height: 1080,
};

#mutex: Promise<unknown> | false = false;
Expand Down
4 changes: 2 additions & 2 deletions src/services/Producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/services/Timelapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export class Timelapse {
events.emit('error', error);
abort();
}
} finally {
logger.timeEnd('timelapse');
}
};
setTimeout(() => {
Expand Down

0 comments on commit 33e2c2a

Please sign in to comment.