import define from "../../define.js"; import { ApiError } from "../../error.js"; import { Users, ReversiGames } from "../../../../models/index.js"; import { matchAnyUser, matchSpecificUser } from "../../../../services/reversi/index.js"; export const meta = { tags: [ "reversi" ], requireCredential: true, kind: "write:account", errors: { noSuchUser: { message: "No such user.", code: "NO_SUCH_USER", id: "0b4f0559-b484-4e31-9581-3f73cee89b28" }, isYourself: { message: "Target user is yourself.", code: "TARGET_IS_YOURSELF", id: "96fd7bd6-d2bc-426c-a865-d055dcd2828e" } }, res: { type: "object", optional: true, nullable: false } }; export const paramDef = { type: "object", properties: { userId: { type: "string", format: "misskey:id", nullable: true }, noIrregularRules: { type: "boolean", default: false }, multiple: { type: "boolean", default: false } }, required: [] }; export default define(meta, paramDef, async (ps, user)=>{ if (ps.userId === user.id) throw new ApiError(meta.errors.isYourself); const target = ps.userId ? await Users.findOneBy({ id: ps.userId }).then((u)=>{ if (!u) throw new ApiError(meta.errors.noSuchUser); return u; }) : null; const game = target ? await matchSpecificUser(user, target, ps.multiple) : await matchAnyUser(user, { noIrregularRules: ps.noIrregularRules }, ps.multiple); return game ? await ReversiGames.packDetail(game) : undefined; });