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