Добавлена локализация, настройка частоты цитат и админ-панель

This commit is contained in:
Zwuck
2025-12-16 12:08:51 +05:00
parent 21b9c48cea
commit db535c2560
9 changed files with 189 additions and 640 deletions

View File

@@ -1,10 +1,13 @@
import { Update, Ctx, Start, Help, On, Message } from 'nestjs-telegraf';
import { Context } from 'telegraf';
import { Update, Ctx, Start, Help, On, Message, Command, Action, InjectBot } from 'nestjs-telegraf';
import { Context, Telegraf, Markup } from 'telegraf';
import { UsersService } from '../users/users.service';
@Update()
export class BotService {
constructor(private readonly usersService: UsersService) { }
constructor(
private readonly usersService: UsersService,
@InjectBot() private readonly bot: Telegraf<Context>
) { }
@Start()
async start(@Ctx() ctx: Context) {
@@ -13,14 +16,38 @@ export class BotService {
this.usersService.create({
id: user.id,
fullName: `${user.first_name} ${user.last_name || ''}`.trim(),
createdAt: new Date().toISOString(),
});
await ctx.reply(`Welcome, ${user.first_name}! You have been registered for motivational quotes.`);
await ctx.reply('Приветствую тебя, мой дорогой друг. Я бот, который будет писать тебе мотивирующие цитаты. Сейчас цитаты буду приходит один раз в час, в настройках можно изменить это время.');
}
}
@Help()
async help(@Ctx() ctx: Context) {
await ctx.reply('I will send you a motivational quote every 3 hours.');
await ctx.reply('Я буду присылать тебе мотивирующие цитаты. Используй /settings чтобы изменить частоту.');
}
@Command('settings')
async settings(@Ctx() ctx: Context) {
await ctx.reply('Выберите частоту получения цитат:', Markup.inlineKeyboard([
[Markup.button.callback('1 час', 'frequency_1'), Markup.button.callback('3 часа', 'frequency_3')],
[Markup.button.callback('5 часов', 'frequency_5'), Markup.button.callback('7 часов', 'frequency_7')],
[Markup.button.callback('9 часов', 'frequency_9'), Markup.button.callback('12 часов', 'frequency_12')],
]));
}
@Action(/^frequency_(\d+)$/)
async onFrequencySelect(@Ctx() ctx: Context & { match: RegExpExecArray }) {
const user = ctx.from;
if (!user) return;
const hours = parseInt(ctx.match[1]);
this.usersService.update(user.id, { frequency: hours });
await ctx.answerCbQuery();
await ctx.editMessageText(`Отлично! Теперь я буду присылать цитаты каждые ${hours} ч.`);
}
async sendAdminMessage(userId: number, message: string) {
await this.bot.telegram.sendMessage(userId, message);
}
}