Skip to content

Commit 1fd93d2

Browse files
committed
biome: format
1 parent 189d6d5 commit 1fd93d2

10 files changed

Lines changed: 159 additions & 181 deletions

File tree

bots/asakatsu-bot/commands/ask.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { execWithContext } from "../lib/executor";
22
import { REACTION, type Context } from "../lib/types";
33

44
await execWithContext(async (c) => {
5-
const poll = await c.channel.send(
6-
`[明日の朝活意思確認]
5+
const poll = await c.channel.send(
6+
`[明日の朝活意思確認]
77
明日の朝 8:00 までに起きる予定の人は、このメッセージに ${REACTION} を付けてください。
88
起きたら、何かしらのメッセージを投稿してください。(起きていないと警告メッセージが飛びます)`,
9-
);
10-
await poll.react(REACTION);
9+
);
10+
await poll.react(REACTION);
1111
});

bots/asakatsu-bot/commands/check.ts

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,42 @@ import { execWithContext } from "../lib/executor";
22
import { REACTION } from "../lib/types";
33

44
await execWithContext(async (ctx) => {
5-
const now = new Date();
6-
const yesterday19 = new Date(now);
7-
// TODO: UTC+9 以外の TZ で実行された時動かなそう
8-
yesterday19.setDate(now.getDate() - 1);
9-
yesterday19.setHours(19, 0, 0, 0);
5+
const now = new Date();
6+
const yesterday19 = new Date(now);
7+
// TODO: UTC+9 以外の TZ で実行された時動かなそう
8+
yesterday19.setDate(now.getDate() - 1);
9+
yesterday19.setHours(19, 0, 0, 0);
1010

11-
const msgs = await ctx.channel.messages.fetch({ limit: 100 });
12-
const pollMsg = msgs.find(
13-
(m) =>
14-
m.author.id === ctx.client.user?.id &&
15-
m.createdTimestamp >= yesterday19.getTime() &&
16-
m.content.startsWith("[明日の朝活意思確認]"),
17-
);
18-
if (!pollMsg) {
19-
console.error("昨日のアンケートが見つかりません");
20-
return;
21-
}
11+
const msgs = await ctx.channel.messages.fetch({ limit: 100 });
12+
const pollMsg = msgs.find(
13+
(m) =>
14+
m.author.id === ctx.client.user?.id &&
15+
m.createdTimestamp >= yesterday19.getTime() &&
16+
m.content.startsWith("[明日の朝活意思確認]"),
17+
);
18+
if (!pollMsg) {
19+
console.error("昨日のアンケートが見つかりません");
20+
return;
21+
}
2222

23-
const reaction = pollMsg.reactions.cache.get(REACTION);
24-
if (!reaction) return console.error("ERROR: リアクション無し (0)"); // ボットはいるはず
25-
const users = await reaction.users.fetch();
26-
const targets = users.filter((u) => !u.bot).map((u) => u.id);
27-
if (!targets.length) {
28-
console.log("OK: ユーザーのリアクション無し");
29-
return;
30-
}
23+
const reaction = pollMsg.reactions.cache.get(REACTION);
24+
if (!reaction) return console.error("ERROR: リアクション無し (0)"); // ボットはいるはず
25+
const users = await reaction.users.fetch();
26+
const targets = users.filter((u) => !u.bot).map((u) => u.id);
27+
if (!targets.length) {
28+
console.log("OK: ユーザーのリアクション無し");
29+
return;
30+
}
3131

32-
// TODO: 同上; UTC+9 以外の TZ で実行された時動かなそう
33-
const today5 = new Date(now).setHours(5, 0, 0, 0); // 5 時より前は寝る前のメッセージとする
34-
const todayMsgs = await ctx.channel.messages.fetch({ limit: 100 });
35-
const greeted = new Set(
36-
todayMsgs
37-
.filter((m) => m.createdTimestamp >= today5)
38-
.map((m) => m.author.id),
39-
);
32+
// TODO: 同上; UTC+9 以外の TZ で実行された時動かなそう
33+
const today5 = new Date(now).setHours(5, 0, 0, 0); // 5 時より前は寝る前のメッセージとする
34+
const todayMsgs = await ctx.channel.messages.fetch({ limit: 100 });
35+
const greeted = new Set(todayMsgs.filter((m) => m.createdTimestamp >= today5).map((m) => m.author.id));
4036

41-
const sleepyheads = targets.filter((id) => !greeted.has(id));
42-
if (sleepyheads.length) {
43-
await ctx.channel.send(
44-
`${sleepyheads.map((id) => `<@${id}>`).join(" ")} **8 時に起きられない人、厳しいって**`,
45-
);
46-
} else {
47-
await ctx.channel.send("全員が起床済みでした 🎉");
48-
}
37+
const sleepyheads = targets.filter((id) => !greeted.has(id));
38+
if (sleepyheads.length) {
39+
await ctx.channel.send(`${sleepyheads.map((id) => `<@${id}>`).join(" ")} **8 時に起きられない人、厳しいって**`);
40+
} else {
41+
await ctx.channel.send("全員が起床済みでした 🎉");
42+
}
4943
});

bots/asakatsu-bot/lib/executor.ts

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,39 @@ import { Client, GatewayIntentBits, Partials } from "discord.js";
22
import { Env, type Context } from "./types";
33

44
export async function execWithContext(fn: (c: Context) => Promise<void>) {
5-
const env = Env.parse(process.env);
6-
const client = new Client({
7-
intents: [
8-
GatewayIntentBits.Guilds,
9-
GatewayIntentBits.GuildMessages,
10-
GatewayIntentBits.GuildMessageReactions,
11-
GatewayIntentBits.MessageContent,
12-
],
13-
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
14-
});
5+
const env = Env.parse(process.env);
6+
const client = new Client({
7+
intents: [
8+
GatewayIntentBits.Guilds,
9+
GatewayIntentBits.GuildMessages,
10+
GatewayIntentBits.GuildMessageReactions,
11+
GatewayIntentBits.MessageContent,
12+
],
13+
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
14+
});
1515

16-
client.once("ready", async () => {
17-
try {
18-
const channel = await client.channels.fetch(env.CHANNEL_ID);
19-
if (!channel?.isTextBased()) {
20-
console.error(
21-
"指定チャンネルが見つからないか、テキストチャンネルではありません",
22-
);
23-
return;
24-
}
25-
if (!channel.isSendable()) {
26-
console.error("チャンネルはメッセージ送信不可能です");
27-
return;
28-
}
16+
client.once("ready", async () => {
17+
try {
18+
const channel = await client.channels.fetch(env.CHANNEL_ID);
19+
if (!channel?.isTextBased()) {
20+
console.error("指定チャンネルが見つからないか、テキストチャンネルではありません");
21+
return;
22+
}
23+
if (!channel.isSendable()) {
24+
console.error("チャンネルはメッセージ送信不可能です");
25+
return;
26+
}
2927

30-
const ctx: Context = {
31-
env,
32-
channel,
33-
client,
34-
};
28+
const ctx: Context = {
29+
env,
30+
channel,
31+
client,
32+
};
3533

36-
await fn(ctx);
37-
} finally {
38-
client.destroy();
39-
}
40-
});
41-
client.login(env.DISCORD_TOKEN);
34+
await fn(ctx);
35+
} finally {
36+
client.destroy();
37+
}
38+
});
39+
client.login(env.DISCORD_TOKEN);
4240
}

bots/asakatsu-bot/lib/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { Client, type SendableChannels } from "discord.js";
33
import { z } from "zod";
44

55
export const Env = z.object({
6-
DISCORD_TOKEN: z.string(),
7-
CHANNEL_ID: z.string(),
6+
DISCORD_TOKEN: z.string(),
7+
CHANNEL_ID: z.string(),
88
});
99
export type Env = z.infer<typeof Env>;
1010

1111
export const REACTION = "👍";
1212

1313
export type Context = {
14-
env: Env;
15-
channel: SendableChannels;
16-
client: Client;
14+
env: Env;
15+
channel: SendableChannels;
16+
client: Client;
1717
};

bots/asakatsu-bot/package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"name": "asakatsu-bot",
3-
"version": "0.1.0",
4-
"module": "index.ts",
5-
"type": "module",
6-
"private": true,
7-
"devDependencies": {
8-
"@types/bun": "^1.3.5"
9-
},
10-
"peerDependencies": {
11-
"typescript": "^5.9.3"
12-
},
13-
"dependencies": {
14-
"discord.js": "^14.25.1",
15-
"zod": "^4.3.5"
16-
}
2+
"name": "asakatsu-bot",
3+
"version": "0.1.0",
4+
"module": "index.ts",
5+
"type": "module",
6+
"private": true,
7+
"devDependencies": {
8+
"@types/bun": "^1.3.5"
9+
},
10+
"peerDependencies": {
11+
"typescript": "^5.9.3"
12+
},
13+
"dependencies": {
14+
"discord.js": "^14.25.1",
15+
"zod": "^4.3.5"
16+
}
1717
}

bots/asakatsu-bot/tsconfig.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
2-
"compilerOptions": {
3-
// Environment setup & latest features
4-
"lib": ["ESNext"],
5-
"target": "ESNext",
6-
"module": "Preserve",
7-
"moduleDetection": "force",
8-
"jsx": "react-jsx",
9-
"allowJs": true,
2+
"compilerOptions": {
3+
// Environment setup & latest features
4+
"lib": ["ESNext"],
5+
"target": "ESNext",
6+
"module": "Preserve",
7+
"moduleDetection": "force",
8+
"jsx": "react-jsx",
9+
"allowJs": true,
1010

11-
// Bundler mode
12-
"moduleResolution": "bundler",
13-
"allowImportingTsExtensions": true,
14-
"verbatimModuleSyntax": true,
15-
"noEmit": true,
11+
// Bundler mode
12+
"moduleResolution": "bundler",
13+
"allowImportingTsExtensions": true,
14+
"verbatimModuleSyntax": true,
15+
"noEmit": true,
1616

17-
// Best practices
18-
"strict": true,
19-
"skipLibCheck": true,
20-
"noFallthroughCasesInSwitch": true,
21-
"noUncheckedIndexedAccess": true,
22-
"noImplicitOverride": true,
17+
// Best practices
18+
"strict": true,
19+
"skipLibCheck": true,
20+
"noFallthroughCasesInSwitch": true,
21+
"noUncheckedIndexedAccess": true,
22+
"noImplicitOverride": true,
2323

24-
// Some stricter flags (disabled by default)
25-
"noUnusedLocals": false,
26-
"noUnusedParameters": false,
27-
"noPropertyAccessFromIndexSignature": false
28-
}
24+
// Some stricter flags (disabled by default)
25+
"noUnusedLocals": false,
26+
"noUnusedParameters": false,
27+
"noPropertyAccessFromIndexSignature": false
28+
}
2929
}

bots/auto-moderator/src/io.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ export function env(name: string) {
55
}
66

77
// should not throw
8-
export async function retry(
9-
count: number,
10-
func: () => Promise<string>
11-
): Promise<string | Error> {
8+
export async function retry(count: number, func: () => Promise<string>): Promise<string | Error> {
129
let err: Error = new Error("失敗していません");
1310
for (const _ of new Array(count).fill(0)) {
1411
try {
@@ -31,16 +28,13 @@ export async function webhook(message: string) {
3128
}
3229

3330
export async function queryNotion(query: object) {
34-
return await fetch(
35-
"https://api.notion.com/v1/databases/e8d7215f-b522-4be4-a9a3-e7d3be4d41ff/query",
36-
{
37-
method: "POST",
38-
headers: {
39-
"Notion-Version": "2022-06-28",
40-
"Content-Type": "application/json",
41-
Authorization: `Bearer ${env("NOTION_API_KEY")}`,
42-
},
43-
body: JSON.stringify(query),
44-
}
45-
);
31+
return await fetch("https://api.notion.com/v1/databases/e8d7215f-b522-4be4-a9a3-e7d3be4d41ff/query", {
32+
method: "POST",
33+
headers: {
34+
"Notion-Version": "2022-06-28",
35+
"Content-Type": "application/json",
36+
Authorization: `Bearer ${env("NOTION_API_KEY")}`,
37+
},
38+
body: JSON.stringify(query),
39+
});
4640
}

bots/auto-moderator/src/main.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ https://developers.notion.com/docs/working-with-databases
99
*/
1010

1111
// the url is safe to publish.
12-
const NOTION_TASK_PAGE_URL =
13-
"https://www.notion.so/utcode/e8d7215fb5224be4a9a3e7d3be4d41ff";
12+
const NOTION_TASK_PAGE_URL = "https://www.notion.so/utcode/e8d7215fb5224be4a9a3e7d3be4d41ff";
1413
const DAY = 24 * 60 * 60 * 1000;
1514

1615
const query = {
@@ -19,9 +18,7 @@ const query = {
1918
{
2019
property: "期日",
2120
date: {
22-
before: new Date(Date.now() + 3 * DAY)
23-
.toISOString()
24-
.match(/^\d{4}-\d{2}-\d{2}/)?.[0],
21+
before: new Date(Date.now() + 3 * DAY).toISOString().match(/^\d{4}-\d{2}-\d{2}/)?.[0],
2522
},
2623
},
2724
{
@@ -46,9 +43,7 @@ interface FormatTaskReturn {
4643
}
4744
function formatTask(task: Task): FormatTaskReturn {
4845
const due = task.properties.期日?.date.start;
49-
const title = task.properties.タイトル?.title
50-
.map((title) => title.plain_text)
51-
.join("");
46+
const title = task.properties.タイトル?.title.map((title) => title.plain_text).join("");
5247

5348
const unregistered: { id: string; name?: string }[] = [];
5449

@@ -72,9 +67,7 @@ function formatTask(task: Task): FormatTaskReturn {
7267
});
7368

7469
const assignee = assignees?.join(" ");
75-
const formatted = assignee
76-
? `・【${due}${title} ${assignee}`
77-
: `・【${due}${title} (担当者不在)`;
70+
const formatted = assignee ? `・【${due}${title} ${assignee}` : `・【${due}${title} (担当者不在)`;
7871

7972
return { formatted, unregistered };
8073
}
@@ -84,13 +77,10 @@ async function main() {
8477
const json = v.parse(NotionFetchResponse, await res.json());
8578
const taskResults = json.results.map(formatTask);
8679

87-
if (taskResults.length === 0)
88-
return "本日は期限が迫っているタスクはありませんでした。";
80+
if (taskResults.length === 0) return "本日は期限が迫っているタスクはありませんでした。";
8981

9082
const tasks = taskResults.map((t) => t.formatted);
91-
const allUnregistered = [
92-
...new Set(taskResults.flatMap((t) => t.unregistered)),
93-
];
83+
const allUnregistered = [...new Set(taskResults.flatMap((t) => t.unregistered))];
9484

9585
let message = `
9686
3日以内に期限が迫っているタスクがあります!

0 commit comments

Comments
 (0)