Skip to content

Commit

Permalink
Merge pull request #24 from CHProducts/dev
Browse files Browse the repository at this point in the history
コマンド追加とか
  • Loading branch information
MotiCAT authored Jan 26, 2024
2 parents e51394f + be54a74 commit 94275bf
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/Events/onInteractionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export async function onInteractionCreate(interaction: BaseInteraction): Promise
break;
}
}
if (interaction.isMessageContextMenuCommand()) {
switch (interaction.commandName) {
case '日本語に翻訳':
interactions.translate(interaction);
break;
}
}
if (!interaction.isChatInputCommand()) return;
if (!interaction.guild) {
interaction.reply('このコマンドはDMでは使用できません。');
Expand Down
12 changes: 10 additions & 2 deletions src/deploy-commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { PermissionsBitField, REST, Routes, SlashCommandBuilder } from 'discord.js';
import {
ContextMenuCommandBuilder,
PermissionsBitField,
REST,
Routes,
SlashCommandBuilder,
ApplicationCommandType
} from 'discord.js';
import { config } from 'dotenv';

config();
Expand Down Expand Up @@ -160,7 +167,8 @@ const commands = [
new SlashCommandBuilder()
.setName('user')
.setDescription('ユーザーの情報を表示します')
.addUserOption((option) => option.setName('user').setDescription('ユーザー'))
.addUserOption((option) => option.setName('user').setDescription('ユーザー')),
new ContextMenuCommandBuilder().setName('日本語に翻訳').setType(ApplicationCommandType.Message)
];

const rest = new REST().setToken(process.env.DISCORD_TOKEN!);
Expand Down
1 change: 1 addition & 0 deletions src/embeds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export const embeds = {
.addFields({ name: 'Error', value: '指定したユーザーをミュートできませんでした。' })
.setColor('#ff0000')
.build(),
translateError: new Builder().addFields({ name: 'Error', value: '翻訳に失敗しました。' }).setColor('#ff0000').build(),
untimeoutHelp: new Builder()
.setTitle('untimeoutコマンド')
.setDescription('指定したユーザーのミュートを解除するコマンド')
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions src/interactions/context_translate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { embeds } from '../embeds';
import translate from 'deepl';
import { EmbedBuilder, MessageContextMenuCommandInteraction } from 'discord.js';

export async function translateCommand(interaction: MessageContextMenuCommandInteraction) {
if (!interaction.targetMessage.content) return interaction.reply(embeds.translateError);
translate({
text: interaction.targetMessage.content,
target_lang: 'JA',
auth_key: process.env.DEEPL_API_KEY!,
free_api: true
})
.then((res) => {
const embed = new EmbedBuilder()
.setTitle('翻訳結果')
.setDescription(res.data.translations[0].text)
.setColor('#0099ff')
.setFooter({ text: 'Powered by DeepL' });
interaction.reply({ embeds: [embed] });
})
.catch((err) => {
console.error(err);
interaction.reply(embeds.translateError);
});
}
8 changes: 5 additions & 3 deletions src/interactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { avatarCommand } from './avatar';
import { banCommand } from './ban';
import { banlistCommand } from './banlist';
import { bannerCommand } from './banner';
import { noCommand } from './button_no';
import { yesCommand } from './button_yes';
import { clearCommand } from './clear';
import { closeticketCommand } from './closeticket';
import { translateCommand } from './context_translate';
import { createticketCommand } from './createticket';
import { helpCommand } from './help';
import { inlistCommand } from './inlist';
Expand All @@ -15,7 +18,6 @@ import { leaveCommand } from './leave';
import { logCommand } from './log';
import { mcskinCommand } from './mcskin';
import { mcstatusCommand } from './mcstatus';
import { noCommand } from './no';
import { pingCommand } from './ping';
import { responseCommand } from './response';
import { responseComplete } from './response_complete';
Expand All @@ -26,7 +28,6 @@ import { statusCommand } from './status';
import { timeoutCommand } from './timeout';
import { untimeoutCommand } from './untimeout';
import { userCommand } from './user';
import { yesCommand } from './yes';

export const interactions = {
help: helpCommand,
Expand Down Expand Up @@ -57,5 +58,6 @@ export const interactions = {
closeticket: closeticketCommand,
yes: yesCommand,
no: noCommand,
responseComplete: responseComplete
responseComplete: responseComplete,
translate: translateCommand
};

0 comments on commit 94275bf

Please sign in to comment.