Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: FEATURE 環境変数で Runner の動作を制御できるように #359

Merged
merged 3 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ yarn start

すべて必須です。指定しなければ起動に失敗します。

| 変数名 | 説明 |
| ----------------- | --------------------------------------------------------------- |
| `DISCORD_TOKEN` | BOT のトークン |
| `MAIN_CHANNEL_ID` | VoiceDiff(VC 入退室ログ)を送信する **テキスト** チャンネルの ID |
| `GUILD_ID` | 限界開発鯖の ID |
| `PREFIX` | コマンドの接頭辞、デフォルト値は `"!"` |
| 変数名 | 説明 |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DISCORD_TOKEN` | BOT のトークン |
| `MAIN_CHANNEL_ID` | VoiceDiff(VC 入退室ログ)を送信する **テキスト** チャンネルの ID |
| `GUILD_ID` | 限界開発鯖の ID |
| `PREFIX` | コマンドの接頭辞、デフォルト値は `"!"` |
| `FEATURE` | 有効にする機能のカンマ区切り文字列、デフォルト値は全ての機能。`"MESSAGE_CREATE"`, `"MESSAGE_UPDATE"`, `"COMMAND"`, `"VOICE_ROOM"`, `"ROLE"`, `"EMOJI"` を組み合わせ可能。 |
110 changes: 68 additions & 42 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,17 @@ const {
DISCORD_TOKEN: token,
MAIN_CHANNEL_ID: mainChannelId,
GUILD_ID,
PREFIX
} = extractEnv(['DISCORD_TOKEN', 'MAIN_CHANNEL_ID', 'GUILD_ID', 'PREFIX'], {
PREFIX: '!'
});
PREFIX,
FEATURE
} = extractEnv(
['DISCORD_TOKEN', 'MAIN_CHANNEL_ID', 'GUILD_ID', 'PREFIX', 'FEATURE'],
{
PREFIX: '!',
FEATURE: 'MESSAGE_CREATE,MESSAGE_UPDATE,COMMAND,VOICE_ROOM,ROLE,EMOJI'
}
);

const features = FEATURE.split(',');

const intents = [
GatewayIntentBits.Guilds, // GUILD_CREATE による初期化
Expand All @@ -83,6 +90,8 @@ function readyLog(client: Client): void {
console.info('');
console.info('起動完了しました。');
console.info('');
console.info('有効になっている機能> ' + features.join(', '));
console.info('');
console.info('接続クライアント> ' + connectionClient.username);
console.info('接続クライアントID> ' + connectionClient.id);
console.info('接続クライアントバージョン> ' + projectVersion);
Expand All @@ -99,15 +108,21 @@ const reservationRepo = new InMemoryReservationRepository();
const clock = new ActualClock();
const sequencesYaml = loadEmojiSeqYaml(['assets', 'emoji-seq.yaml']);

const runner = new MessageResponseRunner(
const messageCreateRunner = new MessageResponseRunner(
new MessageProxy(client, transformerForMessage())
);
runner.addResponder(allMessageEventResponder(typoRepo, sequencesYaml));
if (features.includes('MESSAGE_CREATE')) {
messageCreateRunner.addResponder(
allMessageEventResponder(typoRepo, sequencesYaml)
);
}

const updateRunner = new MessageUpdateResponseRunner(
const messageUpdateRunner = new MessageUpdateResponseRunner(
new MessageUpdateProxy(client, transformerForUpdateMessage())
);
updateRunner.addResponder(allMessageUpdateEventResponder());
if (features.includes('MESSAGE_UPDATE')) {
messageUpdateRunner.addResponder(allMessageUpdateEventResponder());
}

const scheduleRunner = new ScheduleRunner(clock);

Expand All @@ -121,50 +136,61 @@ const stats = new DiscordMemberStats(client, GUILD_ID as Snowflake);
const KAWAEMON_ID = '391857452360007680' as Snowflake;
const roleManager = new DiscordRoleManager(client, GUILD_ID as Snowflake);

registerAllCommandResponder({
typoRepo,
reservationRepo,
factory: new DiscordVoiceConnectionFactory<AssetKey | KaereMusicKey>(client, {
COFFIN_INTRO: join('assets', 'party', 'coffin-intro.mp3'),
COFFIN_DROP: join('assets', 'party', 'coffin-drop.mp3'),
KAKAPO: join('assets', 'party', 'kakapo.mp3'),
KAKUSIN_DAISUKE: join('assets', 'party', 'kakusin-daisuke.mp3'),
NEROYO: join('assets', 'kaere', 'neroyo.mp3')
}),
clock,
scheduleRunner,
random: new MathRandomGenerator(),
roomController: new DiscordVoiceRoomController(client),
commandRunner,
stats,
sheriff: new DiscordSheriff(client),
ping: new DiscordWS(client),
fetcher: new GenVersionFetcher(),
messageRepo: new DiscordMessageRepository(client),
membersRepo: stats,
roleRepo: roleManager
});
if (features.includes('COMMAND')) {
registerAllCommandResponder({
typoRepo,
reservationRepo,
factory: new DiscordVoiceConnectionFactory<AssetKey | KaereMusicKey>(
client,
{
COFFIN_INTRO: join('assets', 'party', 'coffin-intro.mp3'),
COFFIN_DROP: join('assets', 'party', 'coffin-drop.mp3'),
KAKAPO: join('assets', 'party', 'kakapo.mp3'),
KAKUSIN_DAISUKE: join('assets', 'party', 'kakusin-daisuke.mp3'),
NEROYO: join('assets', 'kaere', 'neroyo.mp3')
}
),
clock,
scheduleRunner,
random: new MathRandomGenerator(),
roomController: new DiscordVoiceRoomController(client),
commandRunner,
stats,
sheriff: new DiscordSheriff(client),
ping: new DiscordWS(client),
fetcher: new GenVersionFetcher(),
messageRepo: new DiscordMessageRepository(client),
membersRepo: stats,
roleRepo: roleManager
});
}

const provider = new VoiceRoomProxy<VoiceChannelParticipant>(
client,
(voiceState) => new DiscordParticipant(voiceState)
);
const voiceRunner = new VoiceRoomResponseRunner(provider);
const voiceRoomRunner = new VoiceRoomResponseRunner(provider);
const output = new DiscordOutput(client, mainChannelId);
voiceRunner.addResponder(new VoiceDiff(output));
if (features.includes('VOICE_ROOM')) {
voiceRoomRunner.addResponder(new VoiceDiff(output));
}

const roleRunner = new RoleResponseRunner();
roleRunner.addResponder(
allRoleResponder({
kawaemonId: KAWAEMON_ID,
roleManager,
output
})
);
roleProxy(client, roleRunner);
if (features.includes('ROLE')) {
roleRunner.addResponder(
allRoleResponder({
kawaemonId: KAWAEMON_ID,
roleManager,
output
})
);
roleProxy(client, roleRunner);
}

const emojiRunner = new EmojiResponseRunner(new EmojiProxy(client));
emojiRunner.addResponder(allEmojiResponder(output));
if (features.includes('EMOJI')) {
emojiRunner.addResponder(allEmojiResponder(output));
}

client.once('ready', () => {
readyLog(client);
Expand Down