-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path归零者-ja.js
More file actions
95 lines (95 loc) · 2.32 KB
/
归零者-ja.js
File metadata and controls
95 lines (95 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"use strict";
const {
mw,
tracer,
SpanStatusCode,
setSpanAttributes,
} = require("./mediaWiki");
const {
ATTR_HTTP_REQUEST_RESEND_COUNT,
} = require("@opentelemetry/semantic-conventions");
(async () => {
await tracer.startActiveSpan(
__filename.slice(__dirname.length + 1),
async span => {
try {
const api = new mw.Api(require("./config").ja);
await api.login();
const edit = async (retry = 0) => {
if (retry >= 3) return;
return await tracer.startActiveSpan("edit", async span => {
try {
if (retry)
span.setAttribute(
ATTR_HTTP_REQUEST_RESEND_COUNT,
retry,
);
let r;
try {
r = setSpanAttributes(
span,
await api.post({
action: "edit",
text: "<noinclude>{{サンドボックス冒頭}}</noinclude>\n== ここから下に書き込んでください ==",
summary: "砂場ならし",
nocreate: true,
tags: "Bot",
bot: true,
token: await api.getToken(
"csrf",
retry,
),
title: "ヘルプ:サンドボックス",
}),
);
if (!r) throw new Error(r);
if (r?.error) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: JSON.stringify(r.error),
});
console.error(r.error);
span.end();
return await edit(++retry);
}
} catch (e) {
span.recordException(e);
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
return console.error(e);
}
console.table(r.edit);
if (r.edit.nochange !== true)
console.info(
`https://ja.moegirl.org.cn/Special:Diff/${r.edit.oldrevid}/${r.edit.newrevid}`,
);
} catch (e) {
span.recordException(e);
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
console.error(e);
} finally {
span.end();
}
});
};
edit();
span.setStatus({ code: SpanStatusCode.OK });
} catch (e) {
span.recordException(e);
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
console.error(e);
} finally {
span.end();
await global.sdk?.shutdown();
}
},
);
})();