Skip to content

Commit f6ce11c

Browse files
committed
refactor: move Twitch channel name to environment variable
1 parent 50ed354 commit f6ce11c

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

.env.example

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
# ID of Twitch application
12
TWITCH_CLIENT_ID=
2-
TWITCH_CLIENT_SECRET=
3+
# Secret of Twitch application
4+
TWITCH_CLIENT_SECRET=
5+
# Username of the channel where it will connect and listen for events
6+
TWITCH_CHANNEL_NAME=

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ The file content of the file should be something similar to this:
5757
```env
5858
TWITCH_CLIENT_ID=theClientIdProvidedByTwitch
5959
TWITCH_CLIENT_SECRET=aSecretYouHaveToKeepSafe
60+
TWITCH_CHANNEL_NAME=<username of the Twitch streamer>
6061
```
6162

6263
### Create OAuth2 user token

src/backend/index.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@ import { connect } from "./chatClient";
22
import { listen } from "./helpers/webServer";
33
import { registerUserListener } from "./pubSubClient";
44

5-
const channel = "alexbcberio";
5+
const LOG_PREFIX = "[APP] ";
6+
7+
const channel = process.env.TWITCH_CHANNEL_NAME;
68

79
export async function bootstrap() {
8-
await Promise.all([
9-
registerUserListener(channel),
10-
connect([channel]),
11-
]);
10+
if (!channel) {
11+
console.error(
12+
`${LOG_PREFIX}Missing environment parameter TWITCH_CHANNEL_NAME`
13+
);
14+
15+
const errorCode = 1;
16+
17+
process.exit(errorCode);
18+
}
19+
20+
await Promise.all([registerUserListener(channel), connect([channel])]);
1221

1322
listen();
14-
}
23+
}

0 commit comments

Comments
 (0)