Skip to content

Commit

Permalink
Add validate command to validate a specific entry
Browse files Browse the repository at this point in the history
  • Loading branch information
nlinnanen committed May 3, 2024
1 parent 160688e commit 84230c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/commands/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ const performPistokoe = async (ctx: ActionContext | CommandContext) => {
await ctx.replyWithPhoto(entry?.fileId, validationKeyboard);
};

export const validate = async (ctx: CommandContext) => {
if (!admins.has(ctx.from.id)) return;

const args = ctx.message.text.split(" ");

if (args.length <= 1)
return ctx.reply(
"Please give the id of entry to validate as an argument (eg. /validate 10)",
);

const possibleNum = Number.parseInt(args[1]);

if(Number.isNaN(possibleNum)) return ctx.reply("Given id is not a number!");

const entry = await getEntry(possibleNum);
if (!entry) return ctx.reply("No such entry");

underValidation.set(ctx.chat.id, entry.id);
await ctx.replyWithHTML(formatEntryWithUser(entry as unknown as EntryWithUser));
await ctx.replyWithPhoto(entry.fileId, validationKeyboard);
}

export const notValidated = async (ctx: ActionContext | CommandContext) => {
const notValidated = await amountToValidate();
await ctx.reply(`Number of entries not validated: ${notValidated}`);
Expand Down Expand Up @@ -113,7 +135,7 @@ export const adminLogin = async (
const userId = ctx.message.from.id;
admins.add(userId);
await ctx.reply(
"You are now an admin! \n/csv - get all entries in csv \n/pistokoe - validate entries \n/remove [entry id] - remove one entry \n/numtovalidate - number of entries not yet validated \n/allphotos [user id or username] - gets all uploaded photos by user \n/updatedistance [entry id] [distance] - sets a new distance on an entry \n/resetvalidation [entry id] - resets the validation of entry",
"You are now an admin! \n/csv - get all entries in csv \n/pistokoe - validate entries \n/remove [entry id] - remove one entry \n/numtovalidate - number of entries not yet validated \n/allphotos [user id or username] - gets all uploaded photos by user \n/updatedistance [entry id] [distance] - sets a new distance on an entry \n/resetvalidation [entry id] - resets the validation of entry \n/validate [entry id] - starts validation from specific entry",
);
return next();
};
Expand Down
2 changes: 1 addition & 1 deletion src/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const getRandomNotValidEntry = async () => {
};

const getEntry = (id: number) =>
prisma.entry.findUniqueOrThrow({ where: { id }, include: { user: true } });
prisma.entry.findUnique({ where: { id }, include: { user: true } });

const removeEntry = (id: number) =>
prisma.entry.delete({
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
stopValidation,
valid1x,
valid2x,
validate,
} from "./commands/admin";
import entries from "./commands/entries";
import entry from "./commands/entry";
Expand Down Expand Up @@ -74,6 +75,7 @@ bot.command("remove", remove);
bot.command("allphotos", allPhotosFromUser);
bot.command("resetvalidation", resetValidation);
bot.command("updatedistance", setDistance);
bot.command("validate", validate);

bot.action("invalid", invalid);
bot.action("valid1x", valid1x);
Expand Down

0 comments on commit 84230c6

Please sign in to comment.