From a128fee08b532609279843ef9ff4dfc77a9f436f Mon Sep 17 00:00:00 2001 From: Vladimir Babin Date: Mon, 26 Feb 2024 11:57:06 +0300 Subject: [PATCH] Queue command for admins only --- src/bot/features/queue.ts | 8 ++------ src/bot/features/reset.ts | 3 +++ src/bot/features/start.ts | 9 ++++++--- src/bot/handlers/commands/setcommands.ts | 4 ++++ src/bot/models/user.ts | 8 +++++--- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/bot/features/queue.ts b/src/bot/features/queue.ts index c96f49b..5efe51c 100644 --- a/src/bot/features/queue.ts +++ b/src/bot/features/queue.ts @@ -1,18 +1,14 @@ import { Composer } from "grammy"; import type { Context } from "#root/bot/context.js"; import { logHandle } from "#root/bot/helpers/logging.js"; -import { UserState } from "#root/bot/models/user.js"; import { queueMenu } from "#root/bot/keyboards/queue-menu.js"; +import { isAdmin } from "#root/bot/filters/is-admin.js"; const composer = new Composer(); -const feature = composer.chatType("private"); +const feature = composer.chatType("private").filter(isAdmin); feature.command("queue", logHandle("command-queue"), async (ctx) => { - if (ctx.dbuser.state !== UserState.Submited) { - return ctx.reply("You should send /mint request before use this command!"); - } - return ctx.reply(ctx.t("queue"), { reply_markup: queueMenu }); }); diff --git a/src/bot/features/reset.ts b/src/bot/features/reset.ts index 09b0b80..79c9060 100644 --- a/src/bot/features/reset.ts +++ b/src/bot/features/reset.ts @@ -9,6 +9,9 @@ const composer = new Composer(); const feature = composer.chatType("private"); feature.command("reset", logHandle("command-reset"), async (ctx) => { + if (ctx.dbuser.minted) { + return ctx.reply("You already had minted NFT"); + } ctx.dbuser.state = UserState.WaitImage; ctx.dbuser.votes = await voteScore(ctx); ctx.dbuser.save(); diff --git a/src/bot/features/start.ts b/src/bot/features/start.ts index 38d5666..98db7fd 100644 --- a/src/bot/features/start.ts +++ b/src/bot/features/start.ts @@ -13,10 +13,13 @@ feature.command("start", logHandle("command-start"), async (ctx) => { const premium = author.user.is_premium ?? false; const add = premium ? 50 : 5; ctx.logger.error(add); + ctx.reply("TODO: there will be vote for user"); // const isUpdated = added.modifiedCount > 0; - ctx.reply( - `You are successfully vote for ${payload}. You votes: ${ctx.dbuser.votes}`, - ); + // ctx.reply( + // `You are successfully vote for ${payload}. You votes: ${ctx.dbuser.votes}`, + // ); + } else { + ctx.reply(ctx.t("unhandled")); } }); diff --git a/src/bot/handlers/commands/setcommands.ts b/src/bot/handlers/commands/setcommands.ts index b16d7c1..ef6ebac 100644 --- a/src/bot/handlers/commands/setcommands.ts +++ b/src/bot/handlers/commands/setcommands.ts @@ -30,6 +30,10 @@ function getPrivateChatAdminCommands(localeCode: string): BotCommand[] { command: "setcommands", description: i18n.t(localeCode, "setcommands_command.description"), }, + { + command: "queue", + description: "Show queue", + }, ]; } diff --git a/src/bot/models/user.ts b/src/bot/models/user.ts index 36e6a44..eef1c53 100644 --- a/src/bot/models/user.ts +++ b/src/bot/models/user.ts @@ -38,8 +38,8 @@ export class User extends TimeStamps { @prop({ type: String }) wallet?: string; - @prop({ type: Boolean }) - minted?: boolean; + @prop({ type: Boolean, required: true, default: false }) + minted!: boolean; } const UserModel = getModelForClass(User); @@ -56,5 +56,7 @@ export function findOrCreateUser(id: number) { } export function findQueue() { - return UserModel.find().sort({ votes: -1 }).limit(10); + return UserModel.find({ minted: false, state: UserState.Submited }) + .sort({ votes: -1 }) + .limit(10); }