@@ -29,6 +29,26 @@ module.exports = {
2929 . setDescription ( 'アクセント値(音が下がる場所を指す)' )
3030 . setRequired ( true ) ) ,
3131 )
32+ . addSubcommand ( subCommand => subCommand
33+ . setName ( 'update' )
34+ . setDescription ( '辞書をアップデートする' )
35+ . addStringOption ( option => option
36+ . setName ( 'uuid' )
37+ . setDescription ( '単語のUUID' )
38+ . setRequired ( true ) )
39+ . addStringOption ( option => option
40+ . setName ( 'surface' )
41+ . setDescription ( '読み上げる単語' )
42+ . setRequired ( true ) )
43+ . addStringOption ( option => option
44+ . setName ( 'pronunciation' )
45+ . setDescription ( 'カタカナでの読み方' )
46+ . setRequired ( true ) )
47+ . addIntegerOption ( option => option
48+ . setName ( 'accent_type' )
49+ . setDescription ( 'アクセント値(音が下がる場所を指す)' )
50+ . setRequired ( true ) ) ,
51+ )
3252 . addSubcommand ( subCommand => subCommand
3353 . setName ( 'remove' )
3454 . setDescription ( '辞書から削除する' )
@@ -78,9 +98,42 @@ module.exports = {
7898 }
7999 }
80100 break ;
101+ case 'update' :
102+ {
103+ const uuid = interaction . options . getString ( 'uuid' , false ) ;
104+ if ( ( await SpeakerClient . wordList ( ) ) . filter ( word => word . key === uuid ) . length < 1 ) return await interaction . followUp ( 'そのUUIDは登録されていません' ) ;
105+
106+ const pronunciation = interaction . options . getString ( 'pronunciation' , true ) ;
107+ // eslint-disable-next-line no-irregular-whitespace
108+ if ( pronunciation . match ( / ^ [ ァ - ヶ ー ] * $ / ) === null ) {
109+ await interaction . followUp ( 'オプション、pronunciationは全角カタカナである必要があります' ) ;
110+ }
111+ else {
112+ const statusCode = await SpeakerClient . updateWord ( interaction . options . getString ( 'uuid' , true ) , interaction . options . getString ( 'surface' , true ) , pronunciation , interaction . options . getInteger ( 'accent_type' , true ) ) ;
113+ if ( statusCode === 204 ) {
114+ await interaction . followUp ( {
115+ embeds : [
116+ new EmbedBuilder ( )
117+ . setTitle ( '単語登録を上書きしました' )
118+ . addFields ( [
119+ { name : 'UUID' , value : interaction . options . getString ( 'uuid' , true ) } ,
120+ { name : '読み上げ単語' , value : interaction . options . getString ( 'surface' , true ) } ,
121+ { name : '読み上げ方' , value : interaction . options . getString ( 'pronunciation' , true ) } ,
122+ { name : 'アクセント値(音が下がる場所を指す)' , value : interaction . options . getInteger ( 'accent_type' , true ) . toString ( ) } ,
123+ ] ) ,
124+
125+ ] ,
126+ } ) ;
127+ }
128+ else {
129+ await interaction . followUp ( `単語の登録に失敗しました、HTTPStatusCode: ${ statusCode } ` ) ;
130+ }
131+ }
132+ }
133+ break ;
81134 case 'remove' :
82135 {
83- const uuid = interaction . options . getString ( 'uuid' , true ) ;
136+ const uuid = interaction . options . getString ( 'uuid' , false ) ;
84137 if ( ( await SpeakerClient . wordList ( ) ) . filter ( word => word . key === uuid ) . length < 1 ) return await interaction . followUp ( 'そのUUIDは登録されていません' ) ;
85138
86139 const statusCode = await SpeakerClient . removeWord ( uuid ) ;
@@ -129,7 +182,7 @@ module.exports = {
129182 new ButtonBuilder ( )
130183 . setCustomId ( 'stop' )
131184 . setLabel ( '⏹️' )
132- . setStyle ( 'DANGER' ) ,
185+ . setStyle ( ButtonStyle . Danger ) ,
133186 ] ,
134187 ) ;
135188
0 commit comments