-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: remove unused method * chore: fixed `ICommand` typing * feat: /user-settings speaker
- Loading branch information
1 parent
f2f7cc5
commit 81f5567
Showing
5 changed files
with
132 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
import { | ||
API, | ||
APIChatInputApplicationCommandInteraction, | ||
APIInteractionGuildMember, | ||
RESTPostAPIChatInputApplicationCommandsJSONBody, | ||
} from "@discordjs/core"; | ||
import { NonNullableByKey } from "../common/types.js"; | ||
import Dict from "./dict.js"; | ||
import Join from "./join.js"; | ||
import Leave from "./leave.js"; | ||
import Ping from "./ping.js"; | ||
import { UserSettings } from "./userSetting.js"; | ||
|
||
export const commands: ICommand[] = [ | ||
new Ping(), | ||
new Join(), | ||
new Leave(), | ||
new Dict(), | ||
new UserSettings(), | ||
]; | ||
|
||
export interface ICommand { | ||
defition(): RESTPostAPIChatInputApplicationCommandsJSONBody; | ||
run( | ||
api: API, | ||
i: NonNullableByKey< | ||
APIChatInputApplicationCommandInteraction, | ||
"guild_id", | ||
string | ||
NonNullableByKey< | ||
APIChatInputApplicationCommandInteraction, | ||
"guild_id", | ||
string | ||
>, | ||
"member", | ||
APIInteractionGuildMember | ||
>, | ||
): Promise<unknown>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { | ||
SlashCommandBuilder, | ||
SlashCommandStringOption, | ||
SlashCommandSubcommandBuilder, | ||
} from "@discordjs/builders"; | ||
import { | ||
API, | ||
APIApplicationCommandInteractionDataSubcommandOption, | ||
APIApplicationCommandStringOption, | ||
APIChatInputApplicationCommandInteraction, | ||
APIInteractionGuildMember, | ||
RESTPostAPIChatInputApplicationCommandsJSONBody, | ||
} from "@discordjs/core"; | ||
import { transmute } from "../common/functions.js"; | ||
import { NonNullableByKey } from "../common/types.js"; | ||
import { prisma } from "../index.js"; | ||
import { voices } from "../synthesizer/index.js"; | ||
import { ICommand } from "./index.js"; | ||
|
||
export class UserSettings implements ICommand { | ||
defition(): RESTPostAPIChatInputApplicationCommandsJSONBody { | ||
return new SlashCommandBuilder() | ||
.setName("user-settings") | ||
.setDescription("ユーザー側の設定を変更します") | ||
.addSubcommand( | ||
new SlashCommandSubcommandBuilder() | ||
.setName("speaker") | ||
.setDescription("話者を設定します") | ||
.addStringOption( | ||
new SlashCommandStringOption() | ||
.setName("speaker") | ||
.setDescription("話者") | ||
.setRequired(true) | ||
.addChoices( | ||
...Object.entries(voices).map((x) => { | ||
return { name: x[0], value: x[1] }; | ||
}), | ||
), | ||
), | ||
) | ||
.toJSON(); | ||
} | ||
|
||
async run( | ||
api: API, | ||
i: NonNullableByKey< | ||
NonNullableByKey< | ||
APIChatInputApplicationCommandInteraction, | ||
"guild_id", | ||
string | ||
>, | ||
"member", | ||
APIInteractionGuildMember | ||
>, | ||
): Promise<unknown> { | ||
const synthesizer = (await prisma.synthesizer.findFirst({ | ||
where: { | ||
userId: i.member.user.id, | ||
}, | ||
})) ?? { | ||
pitch: 1.0, | ||
speed: 1.0, | ||
userId: i.member.user.id, | ||
voice: "ja-JP-NanamiNeural", | ||
}; | ||
|
||
const command = i.data.options?.[0]; | ||
|
||
if ( | ||
!transmute<APIApplicationCommandInteractionDataSubcommandOption>(command) | ||
) | ||
return; | ||
|
||
if (command.name === "speaker") { | ||
const speaker = command.options?.[0]; | ||
|
||
if (!transmute<APIApplicationCommandStringOption>(speaker)) | ||
throw "unreachable"; | ||
|
||
const old = synthesizer.voice; | ||
synthesizer.voice = speaker.value; | ||
|
||
await prisma.synthesizer.upsert({ | ||
create: synthesizer, | ||
update: synthesizer, | ||
where: { userId: i.member.user.id }, | ||
}); | ||
|
||
return await api.interactions.editReply(i.application_id, i.token, { | ||
embeds: [ | ||
{ | ||
title: "話者を変更しました", | ||
description: `話者を ${ | ||
Object.entries(voices).find((x) => x[1] === old)?.[0] | ||
} から ${ | ||
Object.entries(voices).find((x) => x[1] === speaker.value)?.[0] | ||
} へ変更しました`, | ||
color: 0x00ff00, | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
throw "unreachable"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters