Skip to content

Commit

Permalink
Merge pull request #42 from CHProducts/dev
Browse files Browse the repository at this point in the history
機能追加とバグ修正と
  • Loading branch information
MotiCAT authored Mar 2, 2024
2 parents d4ffd20 + fc8ad93 commit 7a74aac
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Events/onGuildMemberUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function onGuildMemberUpdate(oldMember: GuildMember | PartialGuildM
const MemberLog = new Database('MemberLog');
list['member'] = await MemberLog.keys();
const serverId = oldMember.guild.id;
if (list['join'].includes(serverId)) {
if (list['member'].includes(serverId)) {
try {
const MemberLogData = (await MemberLog.get(serverId)) as string;
const channel = oldMember.guild.channels.cache.get(MemberLogData);
Expand Down
6 changes: 6 additions & 0 deletions src/Events/onInteractionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ export async function onInteractionCreate(interaction: BaseInteraction): Promise
case 'log':
interactions.log(interaction);
break;
case 'mcbeskin':
interactions.mcbeskin(interaction);
break;
case 'mcskin':
interactions.mcskin(interaction);
break;
Expand All @@ -113,6 +116,9 @@ export async function onInteractionCreate(interaction: BaseInteraction): Promise
case 'status':
interactions.status(interaction);
break;
case 'ticket':
interactions.ticket(interaction);
break;
case 'timeout':
interactions.timeout(interaction);
break;
Expand Down
3 changes: 3 additions & 0 deletions src/Events/onMessageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export async function onMessageCreate(message: Message): Promise<Awaitable<void>
case 'log':
commands.log(message);
break;
case 'mcbeskin':
commands.mcbeskin(message);
break;
case 'mcskin':
commands.mcskin(message);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { joinCommand } from './join';
import { kickCommand } from './kick';
import { leaveCommand } from './leave';
import { logCommand } from './log';
import { mcbeskinCommand } from './mcbeskin';
import { mcskinCommand } from './mcskin';
import { mcstatusCommand } from './mcstatus';
import { pingCommand } from './ping';
Expand Down Expand Up @@ -43,6 +44,7 @@ export const commands = {
kick: kickCommand,
leave: leaveCommand,
log: logCommand,
mcbeskin: mcbeskinCommand,
mcskin: mcskinCommand,
mcstatus: mcstatusCommand,
ping: pingCommand,
Expand Down
21 changes: 21 additions & 0 deletions src/commands/mcbeskin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { embeds } from '../embeds';
import axios from 'axios';
import { Message, EmbedBuilder } from 'discord.js';

export async function mcbeskinCommand(message: Message) {
const name = message.content.split(' ')[1];
if (!name) return message.reply(embeds.mcbeskinHelp);
try {
const response = await axios.get(`https://api.geysermc.org/v2/xbox/xuid/${name}`);
const xuid = response.data.xuid.toString(16).toUpperCase();
const uuid = '00000000-0000-0000-000' + xuid.slice(0, 1) + '-' + xuid.slice(1);
const embed = new EmbedBuilder()
.setTitle(`${name}のスキン`)
.setColor('#0099ff')
.setImage(`https://api.tydiumcraft.net/v1/players/skin?uuid=${uuid}&type=player`)
.setThumbnail(`https://api.tydiumcraft.net/v1/players/skin?uuid=${uuid}&type=skin`);
message.reply({ embeds: [embed] });
} catch (error) {
message.reply(embeds.defaultError);
}
}
12 changes: 10 additions & 2 deletions src/deploy-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ const commands = [
.setDescription('ユーザーをキックします')
.addUserOption((option) => option.setName('member').setDescription('キックするユーザー').setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.KickMembers),
new SlashCommandBuilder()
.setName('mcbeskin')
.setDescription('Minecraft BEのスキンを表示します')
.addStringOption((option) => option.setName('user').setDescription('スキンを表示するユーザー').setRequired(true)),
new SlashCommandBuilder()
.setName('mcskin')
.setDescription('Minecraftのスキンを表示します')
Expand All @@ -87,7 +91,6 @@ const commands = [
.addStringOption((option) => option.setName('address').setDescription('サーバーアドレス').setRequired(true))
.addIntegerOption((option) => option.setName('port').setDescription('ポート番号').setRequired(false)),
new SlashCommandBuilder().setName('ping').setDescription('BotのPingを表示します'),
new SlashCommandBuilder().setName('resnow').setDescription('レスポンスを表示します'),
new SlashCommandBuilder()
.setName('response')
.setDescription('レスポンスを設定します')
Expand Down Expand Up @@ -130,6 +133,11 @@ const commands = [
.addStringOption((option) => option.setName('query').setDescription('検索する内容').setRequired(true)),
new SlashCommandBuilder().setName('server').setDescription('サーバーの情報を表示します'),
new SlashCommandBuilder().setName('status').setDescription('Botのステータスを表示します'),
new SlashCommandBuilder()
.setName('ticket')
.setDescription('チケットを作成します')
.addStringOption((option) => option.setName('title').setDescription('チケットのタイトル').setRequired(false))
.addStringOption((option) => option.setName('description').setDescription('チケットの説明').setRequired(false)),
new SlashCommandBuilder()
.setName('timeout')
.setDescription('タイムアウトします')
Expand All @@ -149,7 +157,7 @@ const commands = [
new ContextMenuCommandBuilder().setName('英語に翻訳').setType(ApplicationCommandType.Message)
];

const rest = new REST().setToken(process.env.DISCORD_TOKEN!);
const rest = new REST().setToken(process.env.TOKEN!);

(async () => {
try {
Expand Down
16 changes: 13 additions & 3 deletions src/embeds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export const embeds = {
{ name: 'Commands', value: '`server`, `user`, `list`, `invite`, `search`' },
{
name: 'Server',
value: '`join`, `leave`, `response`, `log`'
value: '`join`, `leave`, `response`, `log`, `ticket`'
},
{ name: 'Minecraft', value: '`mcskin`, `mcstatus`' },
{ name: 'Minecraft', value: '`mcskin`, `mcbeskin`, `mcstatus`' },
{ name: 'Moderation', value: '`ban`, `unban`, `kick`, `role`, `clear`, `timeout`, `untimeout`' }
)
.setTimestamp()
Expand All @@ -40,7 +40,7 @@ export const embeds = {
},
{
name: ':arrow_up:botの歴史',
value: '```diff\n+ 2023/05/21 認証\n+ 2023/02/21 v1.0 Release\n- 2023/02/10 暴走\n+ 2022/05/15 Botアカウントの作成\n```'
value: '```diff\n+ 2023/06/27 100サーバー達成\n+ 2023/05/21 認証\n+ 2023/02/21 v1.0 Release\n- 2023/02/10 暴走\n+ 2022/05/15 Botアカウントの作成\n```'
},
{
name: ':link:関連リンク',
Expand Down Expand Up @@ -150,6 +150,16 @@ export const embeds = {
.setColor('#ff0000')
.build(),
kickSuccess: new Builder().addFields({ name: 'Success', value: '指定したユーザーをkickしました。' }).setColor('#0099ff').build(),
mcbeskinHelp: new Builder()
.setTitle('mcbeskinコマンド')
.setDescription('指定したユーザーのマイクラBEスキンを取得するコマンド')
.setColor('#0099ff')
.addFields({
name: '使い方',
value: 'mc!mcbeskin ユーザー名'
})
.setFooter({ text: 'Motcher v2.0' })
.build(),
mcskinHelp: new Builder()
.setTitle('mcskinコマンド')
.setDescription('指定したユーザーのマイクラスキンを取得するコマンド')
Expand Down
1 change: 0 additions & 1 deletion src/interactions/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export async function banCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers)) return interaction.reply(embeds.banPermissionError);
const member = interaction.options.getMember('member') as GuildMember;
if (!member) return interaction.reply(embeds.banHelp);
member
.ban()
.then(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/interactions/context_en_translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export async function en_translateCommand(interaction: MessageContextMenuCommand
.then((res) => {
const embed = new EmbedBuilder()
.setTitle('Translation Result')
.setDescription(res.data.translations[0].text)
.addFields({ name: 'Original', value: interaction.targetMessage.content })
.addFields({ name: 'Translation (EN)', value: res.data.translations[0].text })
.setColor('#0099ff')
.setFooter({ text: 'Powered by DeepL' });
interaction.reply({ embeds: [embed] });
Expand Down
3 changes: 2 additions & 1 deletion src/interactions/context_ja_translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export async function ja_translateCommand(interaction: MessageContextMenuCommand
.then((res) => {
const embed = new EmbedBuilder()
.setTitle('翻訳結果')
.setDescription(res.data.translations[0].text)
.addFields({ name: '原文', value: interaction.targetMessage.content })
.addFields({ name: '翻訳(日本語)', value: res.data.translations[0].text })
.setColor('#0099ff')
.setFooter({ text: 'Powered by DeepL' });
interaction.reply({ embeds: [embed] });
Expand Down
4 changes: 4 additions & 0 deletions src/interactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { joinCommand } from './join';
import { kickCommand } from './kick';
import { leaveCommand } from './leave';
import { logCommand } from './log';
import { mcbeskinCommand } from './mcbeskin';
import { mcskinCommand } from './mcskin';
import { mcstatusCommand } from './mcstatus';
import { pingCommand } from './ping';
Expand All @@ -26,6 +27,7 @@ import { roleCommand } from './role';
import { searchCommand } from './search';
import { serverCommand } from './server';
import { statusCommand } from './status';
import { ticketCommand } from './ticket';
import { timeoutCommand } from './timeout';
import { untimeoutCommand } from './untimeout';
import { userCommand } from './user';
Expand All @@ -43,6 +45,7 @@ export const interactions = {
join: joinCommand,
kick: kickCommand,
leave: leaveCommand,
mcbeskin: mcbeskinCommand,
mcskin: mcskinCommand,
mcstatus: mcstatusCommand,
ping: pingCommand,
Expand All @@ -52,6 +55,7 @@ export const interactions = {
search: searchCommand,
server: serverCommand,
status: statusCommand,
ticket: ticketCommand,
timeout: timeoutCommand,
untimeout: untimeoutCommand,
user: userCommand,
Expand Down
21 changes: 21 additions & 0 deletions src/interactions/mcbeskin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { embeds } from '../embeds';
import axios from 'axios';
import { ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';

export async function mcbeskinCommand(interaction: ChatInputCommandInteraction) {
await interaction.deferReply();
const name = interaction.options.getString('user');
try {
const response = await axios.get(`https://api.geysermc.org/v2/xbox/xuid/${name}`);
const xuid = response.data.xuid.toString(16).toUpperCase();
const uuid = '00000000-0000-0000-000' + xuid.slice(0, 1) + '-' + xuid.slice(1);
const embed = new EmbedBuilder()
.setTitle(`${name}のスキン`)
.setColor('#0099ff')
.setImage(`https://api.tydiumcraft.net/v1/players/skin?uuid=${uuid}&type=player`)
.setThumbnail(`https://api.tydiumcraft.net/v1/players/skin?uuid=${uuid}&type=skin`);
interaction.followUp({ embeds: [embed] });
} catch (error) {
interaction.followUp(embeds.defaultError);
}
}
2 changes: 0 additions & 2 deletions src/interactions/mcskin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { embeds } from '../embeds';
import { ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';

export async function mcskinCommand(interaction: ChatInputCommandInteraction) {
const name = interaction.options.getString('user');
if (!name) return interaction.reply(embeds.mcskinHelp);
const embed = new EmbedBuilder()
.setTitle(`${name}のスキン`)
.setColor('#0099ff')
Expand Down
3 changes: 1 addition & 2 deletions src/interactions/mcstatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';

export async function mcstatusCommand(interaction: ChatInputCommandInteraction) {
const mcServerIp = interaction.options.getString('address');
const mcServerPort = interaction.options.getString('port') ?? '25565';
const mcServerPort = interaction.options.getInteger('port') ?? 25565;
const url = `https://mcapi.us/server/status?ip=${mcServerIp}&port=${mcServerPort}`;
if (!mcServerIp) return interaction.reply(embeds.mcstatusHelp);
axios
.get(url)
.then((response) => {
Expand Down
1 change: 0 additions & 1 deletion src/interactions/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export async function roleCommand(interaction: ChatInputCommandInteraction) {
return interaction.reply(embeds.roleAddPermissionError);
const role = interaction.options.getRole('role') as Role;
const member = interaction.options.getMember('member') as GuildMember;
if (!role || !member) return interaction.reply(embeds.roleAddHelp);
member.roles
.add(role)
.then(() => {
Expand Down
13 changes: 13 additions & 0 deletions src/interactions/ticket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { EmbedBuilder, ChatInputCommandInteraction, ButtonBuilder, ButtonStyle, ActionRowBuilder } from 'discord.js';

export async function ticketCommand(interaction: ChatInputCommandInteraction) {
const title = interaction.options.getString('title') ?? 'お問い合わせ';
const description = interaction.options.getString('description') ?? 'ボタンを押してチケットを作成してください。';
const embed = new EmbedBuilder().setTitle(title).setDescription(description).setColor('#0099ff').setFooter({ text: 'Motcher v2.0' });

const button = new ButtonBuilder().setCustomId('createticket').setLabel('Create Ticket🎫').setStyle(ButtonStyle.Primary);

const row = new ActionRowBuilder<ButtonBuilder>().addComponents(button);
await interaction.channel?.send({ embeds: [embed], components: [row] });
await interaction.reply({ content: 'チケットを作成しました。', ephemeral: true });
}

0 comments on commit 7a74aac

Please sign in to comment.