Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Commit 514b11c

Browse files
authored
Merge pull request #320 from OutiServer/develop
Release 3.3.4
2 parents 2f39d8b + 12f5a9c commit 514b11c

5 files changed

Lines changed: 109 additions & 6 deletions

File tree

package-lock.json

Lines changed: 35 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "outiserverbot",
3-
"version": "3.2.1",
3+
"version": "3.3.4",
44
"engines": {
55
"node": "16.16.0"
66
},
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@discordjs/opus": "^0.8.0",
1818
"@discordjs/voice": "^0.11.0",
19+
"@koozaki/romaji-conv": "^2.0.18",
1920
"axios": "^0.27.2",
2021
"better-sqlite3": "^7.6.2",
2122
"bufferutil": "^4.0.6",

src/commands/main/word.js

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/events/discord/messageCreate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { EmbedBuilder, MessageType } = require('discord.js');
22
const { default: axios } = require('axios');
33
const url = require('url');
4+
const romajiConv = require('@koozaki/romaji-conv');
45

56
/**
67
* @param {import('../../Bot')} client
@@ -112,7 +113,7 @@ module.exports = async (client, message) => {
112113
if (client.speakers.get(message.guildId)) {
113114
if (client.speakers.get(message.guildId).speakerChannelIds.includes(message.channelId)) {
114115
if (message.content.length < 1 && message.attachments.size >= 1) client.speakers.get(message.guildId).addSpearkQueue(`ファイルが${message.attachments.size}個送信されました`, message.id, speaker.speaker_id);
115-
else client.speakers.get(message.guildId).addSpearkQueue(message.content, message.id, speaker.speaker_id);
116+
else client.speakers.get(message.guildId).addSpearkQueue(romajiConv(message.content).toHiragana(), message.id, speaker.speaker_id);
116117
}
117118
}
118119

src/utils/SpearkClient.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,21 @@ class SpeakerClient {
153153
return result.status;
154154
}
155155

156+
/**
157+
*
158+
* @param {string} uuid
159+
* @param {string} surface
160+
* @param {string} pronunciation
161+
* @param {number} accentType
162+
*
163+
* @returns {number}
164+
*/
165+
static async updateWord(uuid, surface, pronunciation, accentType) {
166+
const result = await rpc.put(`user_dict_word/${uuid}?surface=${encodeURI(surface)}&pronunciation=${encodeURI(pronunciation)}&accent_type=${accentType}`);
167+
168+
return result.status;
169+
}
170+
156171
/**
157172
*
158173
* @param {string} wordUUID

0 commit comments

Comments
 (0)