Skip to content

Commit

Permalink
Queue command for admins only
Browse files Browse the repository at this point in the history
  • Loading branch information
chiliec committed Feb 26, 2024
1 parent c2c5580 commit a128fee
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/bot/features/queue.ts
Original file line number Diff line number Diff line change
@@ -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<Context>();

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 });
});

Expand Down
3 changes: 3 additions & 0 deletions src/bot/features/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const composer = new Composer<Context>();
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();
Expand Down
9 changes: 6 additions & 3 deletions src/bot/features/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
});

Expand Down
4 changes: 4 additions & 0 deletions src/bot/handlers/commands/setcommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function getPrivateChatAdminCommands(localeCode: string): BotCommand[] {
command: "setcommands",
description: i18n.t(localeCode, "setcommands_command.description"),
},
{
command: "queue",
description: "Show queue",
},
];
}

Expand Down
8 changes: 5 additions & 3 deletions src/bot/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

0 comments on commit a128fee

Please sign in to comment.