Skip to content

Commit 9867e7d

Browse files
committed
devcontainer: Remove recommended secrets from devcontainer.json
1 parent 7a1959d commit 9867e7d

File tree

6 files changed

+46
-28
lines changed

6 files changed

+46
-28
lines changed

.devcontainer/devcontainer.json

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
"dockerComposeFile": "compose.yaml",
66
"service": "slackbot",
77
"workspaceFolder": "/code",
8-
"secrets": {
9-
"HTTP_PROXY_TOKEN": {
10-
"description": "http-local-fwdをクローンするためのGitHubトークン。repo権限付きの Personal Access Token を使用してください。"
11-
}
12-
},
13-
"features":{
8+
"features": {
149
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
1510
"version": "latest"
1611
},
@@ -31,9 +26,19 @@
3126
"files.autoSave": "off",
3227
"editor.formatOnSave": true,
3328
"editor.codeActionsOnSave": {
34-
"source.fixAll.eslint": "explicit"
35-
}
36-
}
29+
"source.fixAll": "always",
30+
"source.fixAll.eslint": "always"
31+
},
32+
"eslint.format.enable": true
33+
},
34+
"extensions": [
35+
"ms-vscode.vscode-typescript-next",
36+
"dbaeumer.vscode-eslint",
37+
"GitHub.copilot",
38+
"GitHub.copilot-chat",
39+
"GitHub.vscode-pull-request-github",
40+
"toba.vsfire"
41+
]
3742
}
3843
}
39-
}
44+
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# slackbot
22

3+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=false&ref=master&repo=105612722&skip_quickstart=false)
4+
35
[![Test][action-image]][action-url]
46
[![Coverage Status][codecov-image]][codecov-url]
57

@@ -13,8 +15,6 @@
1315

1416
TSGのSlackで動くSlackbotたち
1517

16-
自分がOWNERのコードの変更は直接masterにpushして構いません。 ([CODEOWNERS](CODEOWNERS)参照)
17-
1818
## 環境構築
1919

2020
### Prerequisites

helloworld/HelloWorld.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { randomUUID } from 'crypto';
1+
import {randomUUID} from 'crypto';
22
import type EventEmitter from 'events';
33
import os from 'os';
4-
import type { BlockAction, ViewSubmitAction } from '@slack/bolt';
5-
import type { SlackMessageAdapter } from '@slack/interactive-messages';
6-
import type { MessageEvent, WebClient } from '@slack/web-api';
7-
import { Mutex } from 'async-mutex';
4+
import type {BlockAction, ViewSubmitAction} from '@slack/bolt';
5+
import type {SlackMessageAdapter} from '@slack/interactive-messages';
6+
import type {MessageEvent, WebClient} from '@slack/web-api';
7+
import {Mutex} from 'async-mutex';
88
import logger from '../lib/logger';
9-
import type { SlackInterface } from '../lib/slack';
10-
import { extractMessage } from '../lib/slackUtils';
9+
import type {SlackInterface} from '../lib/slack';
10+
import {extractMessage} from '../lib/slackUtils';
1111
import State from '../lib/state';
1212
import counterEditDialog from './views/counterEditDialog';
1313
import helloWorldMessage from './views/helloWorldMessage';
@@ -20,7 +20,7 @@ export interface StateObj {
2020

2121
const mutex = new Mutex();
2222

23-
const log = logger.child({ bot: 'helloworld' });
23+
const log = logger.child({bot: 'helloworld'});
2424

2525
export class HelloWorld {
2626
#slack: WebClient;
@@ -31,7 +31,7 @@ export class HelloWorld {
3131

3232
#state: StateObj;
3333

34-
#SANDBOX_ID = process.env.CHANNEL_SANDBOX!;
34+
#SANDBOX_ID = process.env.CHANNEL_SANDBOX ?? '';
3535

3636
// インスタンスを生成するためのファクトリメソッド
3737
static async create(slack: SlackInterface) {
@@ -86,7 +86,7 @@ export class HelloWorld {
8686
const stateValues = Object.assign({}, ...stateObjects);
8787

8888
mutex.runExclusive(() => (
89-
this.setCounterValue(parseInt(stateValues.counter_input.value))
89+
this.setCounterValue(parseInt(stateValues.counter_input.value) || 0)
9090
));
9191
});
9292

@@ -113,10 +113,19 @@ export class HelloWorld {
113113
if (this.#state.latestStatusMessage?.channel === this.#SANDBOX_ID) {
114114
const timestamp = new Date(parseInt(this.#state.latestStatusMessage.ts) * 1000);
115115
const elapsed = (Date.now() - timestamp.getTime()) / 1000;
116+
117+
// 直近のメッセージが60分以内に投稿されている場合は何もせず終了
116118
if (elapsed < 60 * 60) {
117119
log.info('Skipping postHelloWorld because the latest message was posted less than 60 minutes ago');
118120
return;
119121
}
122+
123+
// 直近のメッセージが60分以上前に投稿されている場合は削除して投稿し直す
124+
log.info('Removing last status message because the latest message was posted more than 60 minutes ago');
125+
await this.#slack.chat.delete({
126+
channel: this.#state.latestStatusMessage.channel,
127+
ts: this.#state.latestStatusMessage.ts,
128+
});
120129
}
121130

122131
const result = await this.#slack.chat.postMessage({
@@ -138,7 +147,7 @@ export class HelloWorld {
138147
this.#state.counter = value;
139148

140149
if (!this.#state.latestStatusMessage) {
141-
log.warn('latestStatusMessage is not set');
150+
log.error('latestStatusMessage is not set');
142151
return;
143152
}
144153

@@ -152,7 +161,7 @@ export class HelloWorld {
152161
}
153162

154163
// カウンター編集ダイアログを表示する
155-
private async showCounterEditDialog({ triggerId }: { triggerId: string }) {
164+
private async showCounterEditDialog({triggerId}: { triggerId: string }) {
156165
log.info('Showing counter edit dialog');
157166

158167
await this.#slack.views.open({

helloworld/views/counterEditDialog.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default (state: StateObj): View => ({
2222
action_id: 'counter_input',
2323
is_decimal_allowed: false,
2424
min_value: '0',
25+
max_value: '10000000000',
2526
initial_value: state.counter.toString(),
2627
},
2728
label: {

helloworld/views/helloWorldMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default (state: StateObj): KnownBlock[] => [
5454
elements: [
5555
{
5656
type: 'plain_text',
57-
text: '⚠この値は再起動後も保存されます。前回このメッセージを投稿してから60分以上経っている場合はメッセージが再投稿されますが、以前のメッセージの数字は更新されなくなります。ボタンを押すとエラーが出る場合は、「Slackbotを作ろう」ページの「WebSocketトンネルをセットアップする」などを参考に Event API のセットアップが正常にできているかもう一度確認してください。',
57+
text: '⚠この値は再起動後も保存されます。前回このメッセージを投稿してから60分以上経っている場合は、以前のメッセージが削除され再投稿されます。ボタンを押すとエラーが出る場合は、「Slackbotを作ろう」ページの「WebSocketトンネルをセットアップする」などを参考に Event API のセットアップが正常にできているかもう一度確認してください。',
5858
emoji: true,
5959
},
6060
],

tsconfig.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
"./node_modules"
1414
],
1515
"compilerOptions": {
16-
"target": "es2015",
16+
"target": "ESNext",
1717
"module": "CommonJS",
1818
"moduleResolution": "node",
1919
"noImplicitAny": true,
2020
"resolveJsonModule": true,
2121
"esModuleInterop": true,
22-
"lib": ["es2021", "DOM"],
22+
"lib": [
23+
"ESNext",
24+
"DOM"
25+
],
2326
"skipLibCheck": true,
2427
"experimentalDecorators": true
2528
}
26-
}
29+
}

0 commit comments

Comments
 (0)