Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #59 from takejohn/dev/language-fill
Browse files Browse the repository at this point in the history
依存関係のアップデート、言語周りの補完と修正
  • Loading branch information
ringo360 authored Mar 8, 2024
2 parents 5a72330 + d297d14 commit 9991662
Show file tree
Hide file tree
Showing 11 changed files with 656 additions and 352 deletions.
4 changes: 2 additions & 2 deletions commands/globalban.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
.addSubcommand((subcommand) =>
subcommand
.setName(LANG.commands.globalban.subcommands.remove.name)
.setDescription(LANG.commands.globalban.subcommands.remove.name)
.setDescription(LANG.commands.globalban.subcommands.remove.description)
.addUserOption((option) =>
option
.setName(LANG.commands.globalban.addRemoveOptionNames.user)
Expand All @@ -57,7 +57,7 @@ module.exports = {
.addSubcommand((subcommand) =>
subcommand
.setName(LANG.commands.globalban.subcommands.list.name)
.setDescription(LANG.commands.globalban.subcommands.list.name),
.setDescription(LANG.commands.globalban.subcommands.list.description),
),
execute: async function (
/** @type {import("discord.js").CommandInteraction} */ interaction,
Expand Down
4 changes: 3 additions & 1 deletion commands/mcstatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ module.exports = {
],
});
} else {
await interaction.editReply(`${server}はオフラインです`);
await interaction.editReply(
strFormat(LANG.commands.mcstatus.serverIsOffline, [server]),
);
}
return;
}
Expand Down
140 changes: 80 additions & 60 deletions commands/poll.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,95 @@
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { LANG } = require('../util/languages');
// @ts-check

module.exports = {
data: new SlashCommandBuilder()
.setName(LANG.commands.poll.name)
.setDescription(LANG.commands.poll.description)
.addStringOption((option) =>
option
.setName('title')
.setDescription(LANG.commands.poll.polltitle)
.setRequired(true),
)
.addStringOption((option) =>
option
.setName('choice1')
.setDescription(LANG.commands.poll.pollchoices)
.setRequired(true),
)
.addStringOption((option) =>
option
.setName('choice2')
.setDescription(LANG.commands.poll.pollchoices)
.setRequired(true),
)
.addStringOption((option) =>
option.setName('choice3').setDescription(LANG.commands.poll.pollchoices),
)
.addStringOption((option) =>
option.setName('choice4').setDescription(LANG.commands.poll.pollchoices),
)
.addStringOption((option) =>
option.setName('choice5').setDescription(LANG.commands.poll.pollchoices),
)
.addStringOption((option) =>
option.setName('choice6').setDescription(LANG.commands.poll.pollchoices),
)
.addStringOption((option) =>
option.setName('choice7').setDescription(LANG.commands.poll.pollchoices),
)
.addStringOption((option) =>
option.setName('choice8').setDescription(LANG.commands.poll.pollchoices),
)
.addStringOption((option) =>
option.setName('choice9').setDescription(LANG.commands.poll.pollchoices),
)
.addStringOption((option) =>
option.setName('choice10').setDescription(LANG.commands.poll.pollchoices),
),
execute: async function (interaction) {
const { EmbedBuilder } = require('discord.js');
const { LANG, strFormat } = require('../util/languages');
const { SimpleSlashCommandBuilder } = require('../common/SimpleCommand');

module.exports = SimpleSlashCommandBuilder.create(
LANG.commands.poll.name,
LANG.commands.poll.description,
)
.addStringOption({
name: LANG.commands.poll.options.title.name,
description: LANG.commands.poll.polltitle,
required: true,
})
.addStringOption({
name: strFormat(LANG.commands.poll.options.choice$.name, 1),
description: LANG.commands.poll.pollchoices,
required: true,
})
.addStringOption({
name: strFormat(LANG.commands.poll.options.choice$.name, 2),
description: LANG.commands.poll.pollchoices,
required: true,
})
.addStringOption({
name: strFormat(LANG.commands.poll.options.choice$.name, 3),
description: LANG.commands.poll.pollchoices,
required: false,
})
.addStringOption({
name: strFormat(LANG.commands.poll.options.choice$.name, 4),
description: LANG.commands.poll.pollchoices,
required: false,
})
.addStringOption({
name: strFormat(LANG.commands.poll.options.choice$.name, 5),
description: LANG.commands.poll.pollchoices,
required: false,
})
.addStringOption({
name: strFormat(LANG.commands.poll.options.choice$.name, 6),
description: LANG.commands.poll.pollchoices,
required: false,
})
.addStringOption({
name: strFormat(LANG.commands.poll.options.choice$.name, 7),
description: LANG.commands.poll.pollchoices,
required: false,
})
.addStringOption({
name: strFormat(LANG.commands.poll.options.choice$.name, 8),
description: LANG.commands.poll.pollchoices,
required: false,
})
.addStringOption({
name: strFormat(LANG.commands.poll.options.choice$.name, 9),
description: LANG.commands.poll.pollchoices,
required: false,
})
.addStringOption({
name: strFormat(LANG.commands.poll.options.choice$.name, 10),
description: LANG.commands.poll.pollchoices,
required: false,
})
.build(async function (interaction, title, ...choices) {
await interaction.deferReply();
const { channel } = await interaction;
const options = await interaction.options.data;
if (channel == null) {
return;
}

const filteredChoices = choices.filter((x) => x != null);
const emojis = ['1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣', '8⃣', '9⃣', '🔟'];
const poll = new EmbedBuilder();
poll.setColor(0x2aa198);
for (let i = 1; i < options.length; i++) {
const emoji = emojis[i - 1];
const option = options[i];
poll.addFields({ name: `${emoji} **${option.value}**`, value: ' ' });
for (const [i, choice] of filteredChoices.entries()) {
const emoji = emojis[i];
poll.addFields({ name: `${emoji} **${choice}**`, value: ' ' });
}
poll.setTimestamp();
poll.setFooter({
text: `Sekai.Explode - (Poll Created by ${interaction.user.displayName})`,
text: strFormat(LANG.commands.poll.footer, [
interaction.user.displayName,
]),
iconURL:
'https://github.com/TeamSekai/Sekai.Explode/raw/v14-dev/assets/images/icon.webp',
});
const message = await channel.send({ embeds: [poll] });
for (let i = 1; i < options.length; i++) {
const emoji = emojis[i - 1];
for (const i of filteredChoices.keys()) {
const emoji = emojis[i];
await message.react(emoji);
}
return await interaction.editReply(`**${options[0].value}**`);
},
};
await interaction.editReply(`**${title}**`);
});
35 changes: 22 additions & 13 deletions commands/receiveupdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ const {
PermissionsBitField,
NewsChannel,
} = require('discord.js');
const { LANG, strFormat } = require('../util/languages');

module.exports = {
data: new SlashCommandBuilder()
//TODO: i18n
.setName('follow_announcements')
.setDescription('Sekai.Explodeの最新情報をフォローします!')
.setName(LANG.commands.receiveupdate.name)
.setDescription(LANG.commands.receiveupdate.description)
.addChannelOption((option) =>
option
.setName('channel')
.setDescription('受信するチャンネルを指定します。')
.setName(LANG.commands.receiveupdate.options.channel.name)
.setDescription(LANG.commands.receiveupdate.options.channel.description)
.addChannelTypes(ChannelType.GuildText)
.setRequired(true),
),
Expand All @@ -29,24 +30,32 @@ module.exports = {
)
) {
return await interaction.editReply(
'権限がありません!(管理者権限が必要です。)',
LANG.commands.receiveupdate.permissionError,
);
}
const targetchannel = interaction.options.getChannel('channel');
const targetchannel = interaction.options.getChannel(
LANG.commands.receiveupdate.options.channel.name,
);

const channel = client.channels.resolve('1211695901760819281'); //TODO: config.jsonで編集可能に?
assert(channel instanceof NewsChannel);
try {
await channel.addFollower(targetchannel.id);
const { name, id } = interaction.guild;
console.log(
`[Sekai.Explode] new follower! ${interaction.guild.name} - ${interaction.guild.id}`,
),
await interaction.editReply(
`<#${targetchannel.id}>にSekai.Explodeのアナウンスを通知します :wave:`,
);
strFormat(LANG.commands.receiveupdate.followerAddedLog, { name, id }),
);
await interaction.editReply(
strFormat(
LANG.commands.receiveupdate.followerAddedMessage,
`<#${targetchannel.id}>`,
),
);
} catch (e) {
console.log(`Something Went wrong. ${e}`),
await interaction.editReply(`失敗しました!エラー: ${e}`);
console.log(strFormat(LANG.commands.receiveupdate.errorOccurredLog, [e]));
await interaction.editReply(
strFormat(LANG.commands.receiveupdate.errorOccurredMessage, [e]),
);
}
},
};
4 changes: 2 additions & 2 deletions commands/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ const commandReply = {
const pager = new Pager(
replyPatterns.map((pattern) => `- ${pattern}`),
{
title: '自動応答メッセージ',
title: LANG.commands.reply.subcommands.list.title,
color: 'Green',
emptyMessage: 'メッセージが設定されていません',
emptyMessage: LANG.commands.reply.subcommands.list.emptyMessage,
},
);
await pager.replyTo(interaction);
Expand Down
41 changes: 39 additions & 2 deletions language/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@
"shutdown": "[TempLink] サーバーを閉じました"
}
},
"util": {
"pager": {
"defaults": {
"title": "${0}件のアイテムがリストに入っています!",
"emptyMessage": "リストにアイテムがありません!",
"footer": "${page}/${pageCount}ページ|${length}件中${start}件目から${end}件目",
"prevButton": "前のページ",
"nextButton": "次のページ"
}
}
},
"common": {
"optionDescription": {
"ipAddress": "IPアドレスを入力",
Expand Down Expand Up @@ -527,6 +538,21 @@
"footer": "実行者: ${0}"
}
},
"receiveupdate": {
"name": "follow_announcements",
"description": "Sekai.Explodeの最新情報をフォローします!",
"options": {
"channel": {
"name": "channel",
"description": "受信するチャンネルを指定します。"
}
},
"permissionError": "権限がありません!(管理者権限が必要です。)",
"followerAddedLog": "[Sekai.Explode] new follower! ${name} - ${id}",
"followerAddedMessage": "${0}にSekai.Explodeのアナウンスを通知します :wave:",
"errorOccurredLog": "Something Went wrong. ${0}",
"errorOccurredMessage": "失敗しました!エラー: ${0}"
},
"reply": {
"name": "reply",
"description": "自動応答をカスタマイズします。",
Expand Down Expand Up @@ -565,7 +591,9 @@
},
"list": {
"name": "list",
"description": "自動応答の一覧を表示します。"
"description": "自動応答の一覧を表示します。",
"title": "自動応答メッセージ",
"emptyMessage": "メッセージが設定されていません"
}
},
"notInGuildError": "このコマンドはサーバー内でのみ使用できます!",
Expand Down Expand Up @@ -714,7 +742,16 @@
"name": "poll",
"description": "pollを作成します。",
"polltitle": "Pollのタイトル",
"pollchoices": "選択肢を入力..."
"pollchoices": "選択肢を入力...",
"options": {
"title": {
"name": "title"
},
"choice$": {
"name": "choice${0}"
}
},
"footer": "Sekai.Explode - (Poll Created by ${0})"
}
}
}
Loading

0 comments on commit 9991662

Please sign in to comment.