From fb393ae1aa6d96c386efc1c204e8b084c630ffd0 Mon Sep 17 00:00:00 2001 From: Milmon <115549630@qq.com> Date: Wed, 3 Apr 2024 17:19:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A4=BA=E4=BE=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=9A=84=E4=B8=80=E4=BA=9B=E7=BB=86=E8=8A=82=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20`withHandlerClass`=20=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=20(#60)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: undefined --- dev/hook.md | 17 +++++++++++++++++ docs/user/problem-create.md | 5 ++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/dev/hook.md b/dev/hook.md index 8dc552b6..ae197313 100644 --- a/dev/hook.md +++ b/dev/hook.md @@ -13,9 +13,26 @@ export async function apply(ctx: Context) { // RecordDetail 为需要捕获的路由名 // #get 表示仅捕获 GET 请求,若无此后缀表示捕获该路由的所有请求 ctx.on('handler/after/RecordDetail#get', (h) => { // handler 系列钩子的一参数为对应的 Handler 实例 + // 不允许查看 24 小时以前的提交记录 if (h.rdoc._id.getTimestamp() < new Date(Date.now() - Time.day)) { h.rdoc.code = ''; } }); } ``` + +```ts +import { Context } from 'hydrooj'; + +async function getAnnounce(domainId: string, limit = 5) { + // 获取公告... + return adocs; +} + +export async function apply(ctx: Context) { + ctx.withHandlerClass('HomeHandler', (HomeHandler) => { + // 修改 HomeHandler 中的一个方法(添加公告) + HomeHandler.prototype.getAnnounce = getAnnounce; + }); +} +``` \ No newline at end of file diff --git a/docs/user/problem-create.md b/docs/user/problem-create.md index 9ecc3e29..ea8cc2b3 100644 --- a/docs/user/problem-create.md +++ b/docs/user/problem-create.md @@ -199,15 +199,14 @@ int main(int argc, char* argv[]) { rnd.setSeed(time(NULL)); int a = rnd.next(1000); int b = rnd.next(1000); - int d = a+b; // 本程序的输出将作为用户程序的输入 cout << a << " " << b << endl; int c; // 用户程序的最后输出将作为本程序的输入 cin >> c; //对比用户结果和预期结果 - if (a+b != ans) - quitf(_wa, "%d + %d expected %d, found %d", a, b,d,c); //输出错误的具体信息,便于做题者调试 + if (a+b != c) + quitf(_wa, "%d + %d expected %d, found %d", a, b, a+b, c); //输出错误的具体信息,便于做题者调试 else quitf(_ok, "answer of %d + %d is %d",a,b,c); }