From beecf13a0e96ccef868ce4a51117290bf70bc2ce Mon Sep 17 00:00:00 2001 From: MotiCAT Date: Wed, 3 Jan 2024 22:34:43 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20change=20command=20nam?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Events/onInteractionCreate.ts | 48 ++-------- src/Events/onMessageCreate.ts | 50 ++-------- src/commands/addrole.ts | 21 ----- src/commands/deletejoin.ts | 22 ----- src/commands/deleteleave.ts | 20 ---- src/commands/index.ts | 36 ++----- src/commands/join.ts | 53 +++++++++++ src/commands/joinmsg.ts | 27 ------ src/commands/leave.ts | 53 +++++++++++ src/commands/leavemsg.ts | 27 ------ src/commands/log.ts | 129 +++++++++++++++++++++++++ src/commands/memberlog.ts | 25 ----- src/commands/memberlogstop.ts | 22 ----- src/commands/msglog.ts | 24 ----- src/commands/msglogstop.ts | 22 ----- src/commands/remrole.ts | 20 ---- src/commands/resdelete.ts | 28 ------ src/commands/resnow.ts | 21 ----- src/commands/response.ts | 91 ++++++++++++++---- src/commands/role.ts | 47 ++++++++++ src/commands/rolelog.ts | 25 ----- src/commands/rolelogstop.ts | 22 ----- src/deploy-commands.ts | 130 ++++++++++++++++---------- src/embeds/index.ts | 75 +++++++++++---- src/interactions/addrole.ts | 20 ---- src/interactions/deletejoin.ts | 21 ----- src/interactions/deleteleave.ts | 21 ----- src/interactions/index.ts | 40 ++------ src/interactions/join.ts | 47 ++++++++++ src/interactions/joinmsg.ts | 26 ------ src/interactions/leave.ts | 47 ++++++++++ src/interactions/leavemsg.ts | 26 ------ src/interactions/log.ts | 125 +++++++++++++++++++++++++ src/interactions/memberlog.ts | 24 ----- src/interactions/memberlogstop.ts | 21 ----- src/interactions/msglog.ts | 23 ----- src/interactions/msglogstop.ts | 21 ----- src/interactions/remrole.ts | 21 ----- src/interactions/resdelete.ts | 27 ------ src/interactions/resnow.ts | 21 ----- src/interactions/response.ts | 90 +++++++++++++----- src/interactions/response_complete.ts | 32 +++---- src/interactions/role.ts | 40 ++++++++ src/interactions/rolelog.ts | 24 ----- src/interactions/rolelogstop.ts | 21 ----- 45 files changed, 870 insertions(+), 906 deletions(-) delete mode 100644 src/commands/addrole.ts delete mode 100644 src/commands/deletejoin.ts delete mode 100644 src/commands/deleteleave.ts create mode 100644 src/commands/join.ts delete mode 100644 src/commands/joinmsg.ts create mode 100644 src/commands/leave.ts delete mode 100644 src/commands/leavemsg.ts create mode 100644 src/commands/log.ts delete mode 100644 src/commands/memberlog.ts delete mode 100644 src/commands/memberlogstop.ts delete mode 100644 src/commands/msglog.ts delete mode 100644 src/commands/msglogstop.ts delete mode 100644 src/commands/remrole.ts delete mode 100644 src/commands/resdelete.ts delete mode 100644 src/commands/resnow.ts create mode 100644 src/commands/role.ts delete mode 100644 src/commands/rolelog.ts delete mode 100644 src/commands/rolelogstop.ts delete mode 100644 src/interactions/addrole.ts delete mode 100644 src/interactions/deletejoin.ts delete mode 100644 src/interactions/deleteleave.ts create mode 100644 src/interactions/join.ts delete mode 100644 src/interactions/joinmsg.ts create mode 100644 src/interactions/leave.ts delete mode 100644 src/interactions/leavemsg.ts create mode 100644 src/interactions/log.ts delete mode 100644 src/interactions/memberlog.ts delete mode 100644 src/interactions/memberlogstop.ts delete mode 100644 src/interactions/msglog.ts delete mode 100644 src/interactions/msglogstop.ts delete mode 100644 src/interactions/remrole.ts delete mode 100644 src/interactions/resdelete.ts delete mode 100644 src/interactions/resnow.ts create mode 100644 src/interactions/role.ts delete mode 100644 src/interactions/rolelog.ts delete mode 100644 src/interactions/rolelogstop.ts diff --git a/src/Events/onInteractionCreate.ts b/src/Events/onInteractionCreate.ts index 86018b6..a793970 100644 --- a/src/Events/onInteractionCreate.ts +++ b/src/Events/onInteractionCreate.ts @@ -43,9 +43,6 @@ export async function onInteractionCreate(interaction: BaseInteraction): Promise case 'about': interactions.about(interaction); break; - case 'addrole': - interactions.addrole(interaction); - break; case 'avatar': interactions.avatar(interaction); break; @@ -61,12 +58,6 @@ export async function onInteractionCreate(interaction: BaseInteraction): Promise case 'clear': interactions.clear(interaction); break; - case 'deletejoin': - interactions.deletejoin(interaction); - break; - case 'deleteleave': - interactions.deleteleave(interaction); - break; case 'help': interactions.help(interaction); break; @@ -76,14 +67,17 @@ export async function onInteractionCreate(interaction: BaseInteraction): Promise case 'invite': interactions.invite(interaction); break; - case 'joinmsg': - interactions.joinmsg(interaction); + case 'join': + interactions.join(interaction); break; case 'kick': interactions.kick(interaction); break; - case 'leavemsg': - interactions.leavemsg(interaction); + case 'leave': + interactions.leave(interaction); + break; + case 'log': + interactions.log(interaction); break; case 'mcskin': interactions.mcskin(interaction); @@ -91,38 +85,14 @@ export async function onInteractionCreate(interaction: BaseInteraction): Promise case 'mcstatus': interactions.mcstatus(interaction); break; - case 'memberlog': - interactions.memberlog(interaction); - break; - case 'memberlogstop': - interactions.memberlogstop(interaction); - break; - case 'msglog': - interactions.msglog(interaction); - break; - case 'msglogstop': - interactions.msglogstop(interaction); - break; case 'ping': interactions.ping(interaction); break; - case 'remrole': - interactions.remrole(interaction); - break; - case 'resdelete': - interactions.resdelete(interaction); - break; - case 'resnow': - interactions.resnow(interaction); - break; case 'response': interactions.response(interaction); break; - case 'rolelog': - interactions.rolelog(interaction); - break; - case 'rolelogstop': - interactions.rolelogstop(interaction); + case 'role': + interactions.role(interaction); break; case 'search': interactions.search(interaction); diff --git a/src/Events/onMessageCreate.ts b/src/Events/onMessageCreate.ts index 500487b..96dd527 100644 --- a/src/Events/onMessageCreate.ts +++ b/src/Events/onMessageCreate.ts @@ -7,7 +7,7 @@ import { readFileSync } from 'fs'; config(); -const prefix = 'mc!'; +const prefix = 'mt!'; export async function onMessageCreate(message: Message): Promise> { if (bannedUsers.includes(message.author.id)) return; @@ -62,9 +62,6 @@ export async function onMessageCreate(message: Message): Promise case 'about': commands.about(message); break; - case 'addrole': - commands.addrole(message); - break; case 'avatar': commands.avatar(message); break; @@ -80,12 +77,6 @@ export async function onMessageCreate(message: Message): Promise case 'clear': commands.clear(message); break; - case 'deletejoin': - commands.deletejoin(message); - break; - case 'deleteleave': - commands.deleteleave(message); - break; case 'help': commands.help(message); break; @@ -95,14 +86,17 @@ export async function onMessageCreate(message: Message): Promise case 'invite': commands.invite(message); break; - case 'joinmsg': - commands.joinmsg(message); + case 'join': + commands.join(message); break; case 'kick': commands.kick(message); break; - case 'leavemsg': - commands.leavemsg(message); + case 'leave': + commands.leave(message); + break; + case 'log': + commands.log(message); break; case 'mcskin': commands.mcskin(message); @@ -110,21 +104,9 @@ export async function onMessageCreate(message: Message): Promise case 'mcstatus': commands.mcstatus(message); break; - case 'memberlog': - commands.memberlog(message); - break; - case 'memberlogstop': - commands.memberlogstop(message); - break; case 'minvite': commands.botinvite(message); break; - case 'msglog': - commands.msglog(message); - break; - case 'msglogstop': - commands.msglogstop(message); - break; case 'ping': commands.ping(message); break; @@ -134,23 +116,11 @@ export async function onMessageCreate(message: Message): Promise case 'restart': commands.restart(message); break; - case 'remrole': - commands.remrole(message); - break; - case 'resdelete': - commands.resdelete(message); - break; - case 'resnow': - commands.resnow(message); - break; case 'response': commands.response(message); break; - case 'rolelog': - commands.rolelog(message); - break; - case 'rolelogstop': - commands.rolelogstop(message); + case 'role': + commands.role(message); break; case 'run': commands.run(message); diff --git a/src/commands/addrole.ts b/src/commands/addrole.ts deleted file mode 100644 index 77fa9da..0000000 --- a/src/commands/addrole.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { embeds } from '../embeds'; -import { Message, PermissionsBitField } from 'discord.js'; - -export async function addroleCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageRoles)) - return message.reply(embeds.PermissionError); - if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) - return message.reply(embeds.roleAddPermissionError); - const role = message.mentions.roles.first(); - const member = message.mentions.members?.first(); - if (!role || !member) return message.reply(embeds.roleAddHelp); - member.roles - .add(role) - .then(() => { - message.reply(embeds.roleAddSuccess); - }) - .catch(() => { - message.reply(embeds.roleAddError); - }); - return; -} diff --git a/src/commands/deletejoin.ts b/src/commands/deletejoin.ts deleted file mode 100644 index e80382b..0000000 --- a/src/commands/deletejoin.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ServerJoinData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, Message, PermissionsBitField } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function deletejoinCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator)) - return message.reply(embeds.PermissionError); - const guild = message.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/join_messages.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - delete data[serverId]; - writeFile('./database/join_messages.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - console.error(err); - } else { - message.reply(embeds.deleteSuccess); - } - }); -} diff --git a/src/commands/deleteleave.ts b/src/commands/deleteleave.ts deleted file mode 100644 index c3df1d7..0000000 --- a/src/commands/deleteleave.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { embeds } from '../embeds'; -import { Guild, Message, PermissionsBitField } from 'discord.js'; -import { writeFile } from 'fs'; - -export async function deleteleaveCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator)) - return message.reply(embeds.PermissionError); - const guild = message.guild as Guild; - const serverId = guild.id; - const data = JSON.parse('./database/leave_messages.json'); - delete data[serverId]; - writeFile('./database/leave_messages.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - console.error(err); - } else { - message.reply(embeds.deleteSuccess); - } - }); -} diff --git a/src/commands/index.ts b/src/commands/index.ts index 9941bea..534b747 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,34 +1,24 @@ import { aboutCommand } from './about'; -import { addroleCommand } from './addrole'; import { avatarCommand } from './avatar'; import { banCommand } from './ban'; import { banlistCommand } from './banlist'; import { bannerCommand } from './banner'; import { botinviteCommand } from './botinvite'; import { clearCommand } from './clear'; -import { deletejoinCommand } from './deletejoin'; -import { deleteleaveCommand } from './deleteleave'; import { helpCommand } from './help'; import { inlistCommand } from './inlist'; import { inviteCommand } from './invite'; -import { joinmsgCommand } from './joinmsg'; +import { joinCommand } from './join'; import { kickCommand } from './kick'; -import { leavemsgCommand } from './leavemsg'; +import { leaveCommand } from './leave'; +import { logCommand } from './log'; import { mcskinCommand } from './mcskin'; import { mcstatusCommand } from './mcstatus'; -import { memberlogCommand } from './memberlog'; -import { memberlogstopCommand } from './memberlogstop'; -import { msglogCommand } from './msglog'; -import { msglogstopCommand } from './msglogstop'; import { pingCommand } from './ping'; import { pollCommand } from './poll'; -import { remroleCommand } from './remrole'; -import { resdeleteCommand } from './resdelete'; -import { resnowCommand } from './resnow'; import { responseCommand } from './response'; import { restartCommand } from './restart'; -import { rolelogCommand } from './rolelog'; -import { rolelogstopCommand } from './rolelogstop'; +import { roleCommand } from './role'; import { runCommand } from './run'; import { scriptCommand } from './script'; import { searchCommand } from './search'; @@ -41,35 +31,25 @@ import { userCommand } from './user'; export const commands = { help: helpCommand, about: aboutCommand, - addrole: addroleCommand, avatar: avatarCommand, ban: banCommand, banlist: banlistCommand, banner: bannerCommand, botinvite: botinviteCommand, clear: clearCommand, - deletejoin: deletejoinCommand, - deleteleave: deleteleaveCommand, inlist: inlistCommand, invite: inviteCommand, - joinmsg: joinmsgCommand, + join: joinCommand, kick: kickCommand, - leavemsg: leavemsgCommand, + leave: leaveCommand, + log: logCommand, mcskin: mcskinCommand, mcstatus: mcstatusCommand, - memberlog: memberlogCommand, - memberlogstop: memberlogstopCommand, - msglog: msglogCommand, - msglogstop: msglogstopCommand, ping: pingCommand, poll: pollCommand, - remrole: remroleCommand, - resdelete: resdeleteCommand, - resnow: resnowCommand, response: responseCommand, restart: restartCommand, - rolelog: rolelogCommand, - rolelogstop: rolelogstopCommand, + role: roleCommand, run: runCommand, script: scriptCommand, search: searchCommand, diff --git a/src/commands/join.ts b/src/commands/join.ts new file mode 100644 index 0000000..60358e0 --- /dev/null +++ b/src/commands/join.ts @@ -0,0 +1,53 @@ +import { ServerJoinData } from '../Utils/ServerData'; +import { embeds } from '../embeds'; +import { Message, Guild, TextBasedChannel } from 'discord.js'; +import { writeFile, readFileSync } from 'fs'; + +export async function joinCommand(message: Message) { + const args = message.content.split(' '); + const subcommand = args[1] as string | undefined; + switch (subcommand) { + case 'message': + { + const detail = args[2]; + const channel = message.channel as TextBasedChannel; + const guild = message.guild as Guild; + const serverId = guild.id; + if (!detail) return message.reply(embeds.joinmsgHelp); + const rawData = readFileSync('./database/join_messages.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + data[serverId] = { + joinMessage: detail, + channelId: channel.id + }; + writeFile('./database/join_messages.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + } else { + message.reply(embeds.saveSuccess); + } + }); + } + break; + case 'remove': + { + const guild = message.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/join_messages.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + delete data[serverId]; + writeFile('./database/join_messages.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + console.error(err); + } else { + message.reply(embeds.deleteSuccess); + } + }); + } + break; + default: + message.reply(embeds.joinHelp); + break; + } +} diff --git a/src/commands/joinmsg.ts b/src/commands/joinmsg.ts deleted file mode 100644 index 69b3acf..0000000 --- a/src/commands/joinmsg.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { ServerJoinData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, Message, PermissionsBitField } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function joinmsgCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator)) - return message.reply(embeds.PermissionError); - const detail = message.content.slice('mc!joinmsg'.length).trim(); - const channel = message.channel; - const guild = message.guild as Guild; - const serverId = guild.id; - if (!detail) return message.reply(embeds.joinmsgHelp); - const rawData = readFileSync('./database/join_messages.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - data[serverId] = { - joinMessage: detail, - channelId: channel.id - }; - writeFile(`./database/join_messages.json`, JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - } else { - message.reply(embeds.saveSuccess); - } - }); -} diff --git a/src/commands/leave.ts b/src/commands/leave.ts new file mode 100644 index 0000000..8147bee --- /dev/null +++ b/src/commands/leave.ts @@ -0,0 +1,53 @@ +import { ServerJoinData } from '../Utils/ServerData'; +import { embeds } from '../embeds'; +import { Message, Guild, TextBasedChannel } from 'discord.js'; +import { writeFile, readFileSync } from 'fs'; + +export async function leaveCommand(message: Message) { + const args = message.content.split(' '); + const subcommand = args[1] as string | undefined; + switch (subcommand) { + case 'message': + { + const detail = args[2]; + const channel = message.channel as TextBasedChannel; + const guild = message.guild as Guild; + const serverId = guild.id; + if (!detail) return message.reply(embeds.leavemsgHelp); + const rawData = readFileSync('./database/leave_messages.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + data[serverId] = { + joinMessage: detail, + channelId: channel.id + }; + writeFile('./database/leave_messages.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + } else { + message.reply(embeds.saveSuccess); + } + }); + } + break; + case 'remove': + { + const guild = message.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/leave_messages.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + delete data[serverId]; + writeFile('./database/leave_messages.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + console.error(err); + } else { + message.reply(embeds.deleteSuccess); + } + }); + } + break; + default: + message.reply(embeds.leaveHelp); + break; + } +} diff --git a/src/commands/leavemsg.ts b/src/commands/leavemsg.ts deleted file mode 100644 index 9e42482..0000000 --- a/src/commands/leavemsg.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { ServerLeaveData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, Message, PermissionsBitField } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function leavemsgCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator)) - return message.reply(embeds.PermissionError); - const detail = message.content.slice('mc!leavemsg'.length).trim(); - const channel = message.channel; - const guild = message.guild as Guild; - const serverId = guild.id; - if (!detail) message.reply(embeds.leavemsgHelp); - const rawData = readFileSync('./database/leave_messages.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - data[serverId] = { - leaveMessage: detail, - channelId: channel.id - }; - writeFile('./database/leave_messages.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - } else { - message.reply(embeds.saveSuccess); - } - }); -} diff --git a/src/commands/log.ts b/src/commands/log.ts new file mode 100644 index 0000000..40f08b6 --- /dev/null +++ b/src/commands/log.ts @@ -0,0 +1,129 @@ +import { ServerMemberData, ServerMsgData, ServerRoleData } from '../Utils/ServerData'; +import { embeds } from '../embeds'; +import { Message, Guild, TextBasedChannel } from 'discord.js'; +import { writeFile, readFileSync } from 'fs'; + +export async function logCommand(message: Message) { + const args = message.content.split(' '); + const subcommand = args[1]; + switch (subcommand) { + case 'member': + { + const channel = message.channel as TextBasedChannel; + const guild = message.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/memberlogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + data[serverId] = { + channelId: channel.id + }; + writeFile('./database/memberlogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + console.error(err); + } else { + message.reply(embeds.saveSuccess); + } + }); + } + break; + case 'message': + { + const channel = message.channel as TextBasedChannel; + const guild = message.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/msglogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + data[serverId] = { + channelId: channel.id + }; + writeFile('./database/msglogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + } else { + message.reply(embeds.saveSuccess); + } + }); + } + break; + case 'role': + { + const channel = message.channel as TextBasedChannel; + const guild = message.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/rolelogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + data[serverId] = { + channelId: channel.id + }; + writeFile('./database/rolelogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + console.error(err); + } else { + message.reply(embeds.saveSuccess); + } + }); + } + break; + case 'stop': { + const types = args[2]; + switch (types) { + case 'member': + { + const guild = message.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/memberlogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + delete data[serverId]; + writeFile('./database/memberlogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + console.error(err); + } else { + message.reply(embeds.saveSuccess); + } + }); + } + break; + case 'message': + { + const guild = message.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/msglogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + delete data[serverId]; + writeFile('./database/msglogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + } else { + message.reply(embeds.saveSuccess); + } + }); + } + break; + case 'role': + { + const guild = message.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/rolelogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + delete data[serverId]; + writeFile('./database/rolelogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + console.error(err); + } else { + message.reply(embeds.saveSuccess); + } + }); + } + break; + } + break; + } + default: + message.reply(embeds.logHelp); + break; + } +} diff --git a/src/commands/memberlog.ts b/src/commands/memberlog.ts deleted file mode 100644 index 5ba0137..0000000 --- a/src/commands/memberlog.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ServerMemberData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, Message, PermissionsBitField } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function memberlogCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageChannels)) - return message.reply(embeds.PermissionError); - const channel = message.channel; - const guild = message.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/memberlogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - data[serverId] = { - channelId: channel.id - }; - writeFile('./database/memberlogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - console.error(err); - } else { - message.reply(embeds.saveSuccess); - } - }); -} diff --git a/src/commands/memberlogstop.ts b/src/commands/memberlogstop.ts deleted file mode 100644 index b8aba2c..0000000 --- a/src/commands/memberlogstop.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ServerMemberData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, Message, PermissionsBitField } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function memberlogstopCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageChannels)) - return message.reply(embeds.PermissionError); - const guild = message.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/memberlogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - delete data[serverId]; - writeFile('./database/memberlogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - console.error(err); - } else { - message.reply(embeds.deleteSuccess); - } - }); -} diff --git a/src/commands/msglog.ts b/src/commands/msglog.ts deleted file mode 100644 index 6e0d627..0000000 --- a/src/commands/msglog.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { ServerMsgData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, Message, PermissionsBitField } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function msglogCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageChannels)) - return message.reply(embeds.PermissionError); - const channel = message.channel; - const guild = message.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/msglogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - data[serverId] = { - channelId: channel.id - }; - writeFile('./database/msglogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - } else { - message.reply(embeds.saveSuccess); - } - }); -} diff --git a/src/commands/msglogstop.ts b/src/commands/msglogstop.ts deleted file mode 100644 index efecc94..0000000 --- a/src/commands/msglogstop.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ServerMsgData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, Message, PermissionsBitField } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function msglogstopCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageChannels)) - return message.reply(embeds.PermissionError); - const guild = message.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/msglogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - delete data[serverId]; - writeFile('./database/msglogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - console.error(err); - } else { - message.reply(embeds.deleteSuccess); - } - }); -} diff --git a/src/commands/remrole.ts b/src/commands/remrole.ts deleted file mode 100644 index 76cd40d..0000000 --- a/src/commands/remrole.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { embeds } from '../embeds'; -import { Message, PermissionsBitField } from 'discord.js'; - -export async function remroleCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageRoles)) - return message.reply(embeds.PermissionError); - if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) - return message.reply(embeds.remrolePermissionError); - const role = message.mentions.roles.first(); - const member = message.mentions.members?.first(); - if (!role || !member) return message.reply(embeds.remroleHelp); - member.roles - .remove(role) - .then(() => { - message.reply(embeds.remroleSuccess); - }) - .catch(() => { - message.reply(embeds.remroleError); - }); -} diff --git a/src/commands/resdelete.ts b/src/commands/resdelete.ts deleted file mode 100644 index 0f230e2..0000000 --- a/src/commands/resdelete.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { ServerResponseData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { PermissionsBitField, Message, Guild } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function resdeleteCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageMessages)) - return message.reply('貴方にはこのコマンドを使用する権限がありません。'); - const keyword = message.content.slice('mc!resdelete'.length).trim(); - const guild = message.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/responses.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - const serverData = data[serverId]; - if (!serverData || !serverData[keyword]) - return message.reply(`キーワード 「${keyword}」 のレスポンスは登録されていません。`); - if (!keyword) return message.reply(embeds.resdeleteHelp); - delete serverData[keyword]; - - writeFile('./database/responses.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - console.error(err); - } else { - message.reply(embeds.deleteSuccess); - } - }); -} diff --git a/src/commands/resnow.ts b/src/commands/resnow.ts deleted file mode 100644 index f772b5e..0000000 --- a/src/commands/resnow.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ServerResponseData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, Message } from 'discord.js'; -import { readFileSync } from 'fs'; - -export async function resnowCommand(message: Message) { - const guild = message.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/responses.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - const serverData = data[serverId]; - if (!serverData || Object.keys(serverData).length === 0) { - message.reply(embeds.resnowEmpty); - return; - } - let responseList = '登録されているレスポンス一覧\n'; - for (const keyword in serverData) { - responseList += `${keyword}: ${serverData[keyword]}\n`; - } - message.reply(responseList); -} diff --git a/src/commands/response.ts b/src/commands/response.ts index 59347eb..a813fc7 100644 --- a/src/commands/response.ts +++ b/src/commands/response.ts @@ -6,25 +6,76 @@ import { writeFile, readFileSync } from 'fs'; export async function responseCommand(message: Message) { if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageMessages)) return message.reply(embeds.PermissionError); - const arggs = message.content.slice('mc!response'.length).trim().split(/ +/); - const keyword = message.content.split(' ')[1]; - const response = arggs.slice(1).join(' '); - const guild = message.guild as Guild; - const serverId = guild.id; - if (!keyword || !response) return message.reply(embeds.responseHelp); - const rawData = readFileSync('./database/responses.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - let serverData = data[serverId]; - if (!serverData) { - serverData = {}; - data[serverId] = serverData; + const args = message.content.split(' '); + const subcommand = args[1] as string | undefined; + switch (subcommand) { + case 'add': + { + const guild = message.guild as Guild; + const serverId = guild.id; + const keyword = args[2]; + const response = args[3]; + if (!keyword || !response) return message.reply(embeds.responseAddHelp); + const rawData = readFileSync('./database/responses.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + let serverData = data[serverId]; + if (!serverData) { + serverData = {}; + data[serverId] = serverData; + } + serverData[keyword] = response; + writeFile('./database/responses.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + } else { + message.reply(embeds.saveSuccess); + } + }); + } + break; + case 'remove': + { + const keyword = args[2]; + const guild = message.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/responses.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + const serverData = data[serverId]; + if (!keyword) return message.reply(embeds.responseRemoveHelp); + if (!serverData || !serverData[keyword]) + return message.reply(`キーワード 「${keyword}」 のレスポンスは登録されていません。`); + delete serverData[keyword]; + + writeFile('./database/responses.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + message.reply(embeds.defaultError); + console.error(err); + } else { + message.reply(embeds.deleteSuccess); + } + }); + } + break; + case 'list': + { + const guild = message.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/responses.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + const serverData = data[serverId]; + if (!serverData || Object.keys(serverData).length === 0) { + message.reply(embeds.resnowEmpty); + return; + } + let responseList = '登録されているレスポンス一覧\n'; + for (const keyword in serverData) { + responseList += `${keyword} => ${serverData[keyword]}\n`; + } + message.reply(responseList); + } + break; + default: + message.reply(embeds.responseHelp); + break; } - serverData[keyword] = response; - writeFile('./database/responses.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - } else { - message.reply(embeds.saveSuccess); - } - }); } diff --git a/src/commands/role.ts b/src/commands/role.ts new file mode 100644 index 0000000..a86235e --- /dev/null +++ b/src/commands/role.ts @@ -0,0 +1,47 @@ +import { embeds } from '../embeds'; +import { Message, PermissionsBitField } from 'discord.js'; + +export async function roleCommand(message: Message) { + if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageRoles)) + return message.reply(embeds.PermissionError); + const subcommand = message.content.split(' ')[1]; + switch (subcommand) { + case 'add': + { + if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) + return message.reply(embeds.roleAddPermissionError); + const role = message.mentions.roles.first(); + const member = message.mentions.members?.first(); + if (!role || !member) return message.reply(embeds.roleAddHelp); + member.roles + .add(role) + .then(() => { + message.reply(embeds.roleAddSuccess); + }) + .catch(() => { + message.reply(embeds.roleAddError); + }); + } + break; + case 'remove': + { + if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) + return message.reply(embeds.remrolePermissionError); + const role = message.mentions.roles.first(); + const member = message.mentions.members?.first(); + if (!role || !member) return message.reply(embeds.remroleHelp); + member.roles + .remove(role) + .then(() => { + message.reply(embeds.remroleSuccess); + }) + .catch(() => { + message.reply(embeds.remroleError); + }); + } + break; + default: + message.reply(embeds.roleHelp); + break; + } +} diff --git a/src/commands/rolelog.ts b/src/commands/rolelog.ts deleted file mode 100644 index 43e0f04..0000000 --- a/src/commands/rolelog.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ServerRoleData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Message, PermissionsBitField, Guild } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function rolelogCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageChannels)) - return message.reply(embeds.PermissionError); - const channel = message.channel; - const guild = message.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/rolelogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - data[serverId] = { - channelId: channel.id - }; - writeFile('./database/rolelogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - console.error(err); - } else { - message.reply(embeds.saveSuccess); - } - }); -} diff --git a/src/commands/rolelogstop.ts b/src/commands/rolelogstop.ts deleted file mode 100644 index 4df5da0..0000000 --- a/src/commands/rolelogstop.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ServerRoleData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Message, PermissionsBitField, Guild } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function rolelogstopCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageChannels)) - return message.reply(embeds.PermissionError); - const guild = message.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/rolelogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - delete data[serverId]; - writeFile('./database/rolelogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - message.reply(embeds.defaultError); - console.error(err); - } else { - message.reply(embeds.deleteSuccess); - } - }); -} diff --git a/src/deploy-commands.ts b/src/deploy-commands.ts index d9e9cbc..5a8a38f 100644 --- a/src/deploy-commands.ts +++ b/src/deploy-commands.ts @@ -5,12 +5,6 @@ config(); const commands = [ new SlashCommandBuilder().setName('about').setDescription('このBotについて'), - new SlashCommandBuilder() - .setName('addrole') - .setDescription('ロールを付与します') - .addRoleOption((option) => option.setName('role').setDescription('付与するロール').setRequired(true)) - .addUserOption((option) => option.setName('member').setDescription('ロールを付与するメンバー').setRequired(true)) - .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles), new SlashCommandBuilder() .setName('avatar') .setDescription('ユーザーのアバターを表示します') @@ -33,34 +27,61 @@ const commands = [ .addIntegerOption((option) => option.setName('amount').setDescription('削除するメッセージの数').setRequired(true)) .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages), new SlashCommandBuilder() - .setName('deletejoin') - .setDescription('入室メッセージを削除します') + .setName('join') + .setDescription('入室メッセージの設定') + .addSubcommand((subcommand) => + subcommand + .setName('message') + .setDescription('入室メッセージを設定します') + .addStringOption((option) => option.setName('message').setDescription('設定するメッセージ').setRequired(true)) + ) + .addSubcommand((subcommand) => subcommand.setName('remove').setDescription('入室メッセージを削除します')) .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator), new SlashCommandBuilder() - .setName('deleteleave') - .setDescription('退室メッセージを削除します') + .setName('leave') + .setDescription('退室メッセージの設定') + .addSubcommand((subcommand) => + subcommand + .setName('message') + .setDescription('退室メッセージを設定します') + .addStringOption((option) => option.setName('message').setDescription('設定するメッセージ').setRequired(true)) + ) + .addSubcommand((subcommand) => subcommand.setName('remove').setDescription('退室メッセージを削除します')) .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator), + new SlashCommandBuilder() + .setName('log') + .setDescription('ログの設定を行います') + .addSubcommand((subcommand) => subcommand.setName('member').setDescription('メンバーログの設定を行います')) + .addSubcommand((subcommand) => subcommand.setName('message').setDescription('メッセージログの設定を行います')) + .addSubcommand((subcommand) => subcommand.setName('role').setDescription('ロールログの設定を行います')) + .addSubcommand((subcommand) => + subcommand + .setName('stop') + .setDescription('ログの設定を削除します') + .addStringOption((option) => + option + .setName('type') + .setDescription('削除するログの種類') + .addChoices( + { name: 'member', value: 'member' }, + { name: 'message', value: 'message' }, + { name: 'role', value: 'role' } + ) + .setRequired(true) + ) + ) + .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageChannels), new SlashCommandBuilder().setName('help').setDescription('ヘルプを表示します'), new SlashCommandBuilder().setName('inlist').setDescription('管理者限定コマンド'), new SlashCommandBuilder() .setName('invite') .setDescription('サーバーのの招待リンクを表示します') .setDefaultMemberPermissions(PermissionsBitField.Flags.CreateInstantInvite), - new SlashCommandBuilder() - .setName('joinmsg') - .setDescription('入室メッセージを設定します') - .addStringOption((option) => option.setName('detail').setDescription('入室メッセージ').setRequired(true)) - .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator), new SlashCommandBuilder() .setName('kick') .setDescription('ユーザーをキックします') .addUserOption((option) => option.setName('member').setDescription('キックするユーザー').setRequired(true)) .setDefaultMemberPermissions(PermissionsBitField.Flags.KickMembers), - new SlashCommandBuilder() - .setName('leavemsg') - .setDescription('退室メッセージを設定します') - .addStringOption((option) => option.setName('detail').setDescription('退室メッセージ').setRequired(true)) - .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator), new SlashCommandBuilder() .setName('mcskin') .setDescription('Minecraftのスキンを表示します') @@ -70,41 +91,52 @@ const commands = [ .setDescription('Minecraftサーバーのステータスを表示します') .addStringOption((option) => option.setName('address').setDescription('サーバーアドレス').setRequired(true)) .addIntegerOption((option) => option.setName('port').setDescription('ポート番号').setRequired(false)), - new SlashCommandBuilder() - .setName('memberlog') - .setDescription('メンバーログを設定します') - .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageChannels), - new SlashCommandBuilder() - .setName('memberlogstop') - .setDescription('メンバーログを停止します') - .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageChannels), - new SlashCommandBuilder() - .setName('msglog') - .setDescription('メッセージログを設定します') - .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageChannels), - new SlashCommandBuilder() - .setName('msglogstop') - .setDescription('メッセージログを停止します') - .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageChannels), new SlashCommandBuilder().setName('ping').setDescription('BotのPingを表示します'), - new SlashCommandBuilder() - .setName('remrole') - .setDescription('ロールを剥奪します') - .addRoleOption((option) => option.setName('role').setDescription('剥奪するロール').setRequired(true)) - .addUserOption((option) => option.setName('member').setDescription('ロールを剥奪するメンバー').setRequired(true)) - .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles), - new SlashCommandBuilder() - .setName('resdelete') - .setDescription('レスポンスを削除します') - .addStringOption((option) => option.setName('keyword').setDescription('削除するレスポンス').setRequired(true).setAutocomplete(true)) - .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages), new SlashCommandBuilder().setName('resnow').setDescription('レスポンスを表示します'), new SlashCommandBuilder() .setName('response') .setDescription('レスポンスを設定します') - .addStringOption((option) => option.setName('keyword').setDescription('レスポンスのキーワード').setRequired(true)) - .addStringOption((option) => option.setName('response').setDescription('レスポンス').setRequired(true)) + .addSubcommand((subcommand) => + subcommand + .setName('add') + .setDescription('レスポンスを追加します') + .addStringOption((option) => + option.setName('keyword').setDescription('レスポンスのキーワード').setRequired(true) + ) + .addStringOption((option) => option.setName('response').setDescription('レスポンス').setRequired(true)) + ) + .addSubcommand((subcommand) => + subcommand + .setName('remove') + .setDescription('レスポンスを削除します') + .addStringOption((option) => + option.setName('keyword').setDescription('レスポンスのキーワード').setRequired(true) + ) + ) + .addSubcommand((subcommand) => subcommand.setName('list').setDescription('レスポンスの一覧を表示します')) .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages), + new SlashCommandBuilder() + .setName('role') + .setDescription('ロールの設定を行います') + .addSubcommand((subcommand) => + subcommand + .setName('add') + .setDescription('ロールを追加します') + .addRoleOption((option) => option.setName('role').setDescription('追加するロール').setRequired(true)) + .addUserOption((option) => + option.setName('member').setDescription('ロールを追加するメンバー').setRequired(true) + ) + ) + .addSubcommand((subcommand) => + subcommand + .setName('remove') + .setDescription('ロールを削除します') + .addRoleOption((option) => option.setName('role').setDescription('削除するロール').setRequired(true)) + .addUserOption((option) => + option.setName('member').setDescription('ロールを削除するメンバー').setRequired(true) + ) + ) + .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles), new SlashCommandBuilder() .setName('search') .setDescription('Googleで検索します') diff --git a/src/embeds/index.ts b/src/embeds/index.ts index 64ea623..05657ac 100644 --- a/src/embeds/index.ts +++ b/src/embeds/index.ts @@ -11,17 +11,16 @@ export const embeds = { iconURL: 'https://i.imgur.com/fEtyr1I.png', url: 'https://discord.gg/2QnCs2yqWu' }) - .setDescription('Created By MotiCAT') + .setDescription('Created By CatHouse Products') .addFields( { name: 'Bot', value: '`help`, `about`, `ping`, `status`' }, - { name: 'Commands', value: '`server`, `user`, `list`, `invite`, `janken`, `search`' }, + { name: 'Commands', value: '`server`, `user`, `list`, `invite`, `search`' }, { name: 'Server', - value: '`joinmsg`, `leavemsg`, `deletejoin`, `deleteleave`, `response`, `resdelete`, `resnow`' + value: '`join`, `leave`, `response`, `log`' }, { name: 'Minecraft', value: '`mcskin`, `mcstatus`' }, - { name: 'Moderation', value: '`ban`, `unban`, `kick`, `addrole`, `remrole`, `clear`, `timeout`, `untimeout`' }, - { name: 'Logs', value: '`msglog`, `msglogstop`, `rolelog`, `rolelogstop`, `memberlog`, `memberlogstop`' } + { name: 'Moderation', value: '`ban`, `unban`, `kick`, `role`, `clear`, `timeout`, `untimeout`' }, ) .setTimestamp() .setFooter({ text: 'Motcher v2.0', iconURL: 'https://i.imgur.com/fEtyr1I.png' }) @@ -71,7 +70,7 @@ export const embeds = { .setTitle('addroleコマンド') .setDescription('指定したユーザーに特定のロールを付与するコマンド') .setColor('#0099ff') - .addFields({ name: '使い方', value: 'mc!addrole @ユーザー @ロール' }) + .addFields({ name: '使い方', value: 'mc!role add @ユーザー @ロール' }) .setFooter({ text: 'Motcher v2.0' }) .build(), roleAddSuccess: new Builder() @@ -220,11 +219,18 @@ export const embeds = { .addFields({ name: '使い方', value: 'mc!poll 題名 選択肢1 選択肢2 選択肢3 ...\n選択肢は6つまで' }) .setFooter({ text: 'Motcher v2.0' }) .build(), + roleHelp: new Builder() + .setTitle('roleコマンド') + .setDescription('指定したユーザーにロールを付与するコマンド') + .setColor('#0099ff') + .addFields({ name: '使い方', value: 'mc!role `add|remove`' }) + .setFooter({ text: 'Motcher v2.0' }) + .build(), remroleHelp: new Builder() .setTitle('remroleコマンド') .setDescription('指定したユーザーからロールを剥奪するコマンド') .setColor('#0099ff') - .addFields({ name: '使い方', value: 'mc!remrole @ロール @ユーザー' }) + .addFields({ name: '使い方', value: 'mc!role remove @ロール @ユーザー' }) .setFooter({ text: 'Motcher v2.0' }) .build(), remrolePermissionError: new Builder() @@ -301,6 +307,13 @@ export const embeds = { .addFields({ name: 'Success', value: '設定を削除しました。' }) .setColor('#0099ff') .build(), + joinHelp: new Builder() + .setTitle('joinコマンド') + .setDescription('参加時のメッセージを設定するコマンド') + .setColor('#0099ff') + .addFields({ name: '使い方', value: 'mc!join `message|remove`' }) + .setFooter({ text: 'Motcher v2.0' }) + .build(), joinmsgHelp: new Builder() .setTitle('joinmsgコマンド') .setDescription('参加時のメッセージを設定するコマンド') @@ -308,10 +321,17 @@ export const embeds = { .addFields({ name: '使い方', value: - 'mc!joinmsg 送信したいメッセージ\nコマンドを実行したチャンネルに送信されます。\n 送信メッセージに `{user}` を加えると参加ユーザーをメンションします。 ' + 'mc!join message 送信したいメッセージ\nコマンドを実行したチャンネルに送信されます。\n 送信メッセージに `{user}` を加えると参加ユーザーをメンションします。 ' }) .setFooter({ text: 'Motcher v2.0' }) .build(), + leaveHelp: new Builder() + .setTitle('leaveコマンド') + .setDescription('退出時のメッセージを設定するコマンド') + .setColor('#0099ff') + .addFields({ name: '使い方', value: 'mc!leave `message|remove`' }) + .setFooter({ text: 'Motcher v2.0' }) + .build(), leavemsgHelp: new Builder() .setTitle('leavemsgコマンド') .setDescription('退出時のメッセージを設定するコマンド') @@ -319,32 +339,51 @@ export const embeds = { .addFields({ name: '使い方', value: - 'mc!leavemsg 送信したいメッセージ\nコマンドを実行したチャンネルに送信されます。\n 送信メッセージに `{user}` を加えると退出ユーザーをメンションします。 ' + 'mc!leave message 送信したいメッセージ\nコマンドを実行したチャンネルに送信されます。\n 送信メッセージに `{user}` を加えると退出ユーザーをメンションします。 ' }) .setFooter({ text: 'Motcher v2.0' }) .build(), + logHelp: new Builder() + .setTitle('logコマンド') + .setDescription('ログを設定するコマンド') + .setColor('#0099ff') + .addFields({ name: '使い方', value: 'mc!log (stop) `message|member|role`' }) + .setFooter({ text: 'Motcher v2.0' }) + .build(), responseHelp: new Builder() .setTitle('responseコマンド') .setDescription('キーワードに対して反応する言葉を設定するコマンド') .setColor('#0099ff') .addFields({ name: '使い方', - value: 'mc!response ○○ ××\n○○には反応させたいキーワード、××には応答 を入れてください' + value: 'mc!response `add|remove|list`' }) .setFooter({ text: 'Motcher v2.0' }) .build(), - resnowEmpty: new Builder() - .addFields({ name: 'Error', value: 'まだレスポンスが登録されていません。' }) - .setColor('#ff0000') + responseAddHelp: new Builder() + .setTitle('Addコマンド') + .setDescription('キーワードに対して反応する言葉を設定するコマンド') + .setColor('#0099ff') + .addFields({ + name: '使い方', + value: 'mc!response add キーワード レスポンス\nキーワード、レスポンスには半角スペースを含めることができません。' + }) + .setFooter({ text: 'Motcher v2.0' }) .build(), - resdeleteHelp: new Builder() - .setTitle('resdeleteコマンド') - .setDescription('指定したレスポンスを削除するコマンド') + responseRemoveHelp: new Builder() + .setTitle('Removeコマンド') + .setDescription('キーワードに対して反応する言葉を削除するコマンド') .setColor('#0099ff') - .addFields({ name: '使い方', value: 'mc!resnowで表示された「○○:××」のうちの○○を使い、\nmc!resdelete ○○' }) + .addFields({ + name: '使い方', + value: 'mc!response remove キーワード' + }) .setFooter({ text: 'Motcher v2.0' }) .build(), - + resnowEmpty: new Builder() + .addFields({ name: 'Error', value: 'まだレスポンスが登録されていません。' }) + .setColor('#ff0000') + .build(), PermissionError: new Builder() .addFields({ name: 'Error', diff --git a/src/interactions/addrole.ts b/src/interactions/addrole.ts deleted file mode 100644 index c17603c..0000000 --- a/src/interactions/addrole.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { embeds } from '../embeds'; -import { ChatInputCommandInteraction, GuildMember, PermissionsBitField, Role } from 'discord.js'; - -export async function addroleCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) - 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(() => { - interaction.reply(embeds.roleAddSuccess); - }) - .catch(() => { - interaction.reply(embeds.roleAddError); - }); - return; -} diff --git a/src/interactions/deletejoin.ts b/src/interactions/deletejoin.ts deleted file mode 100644 index d237a03..0000000 --- a/src/interactions/deletejoin.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ServerJoinData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, ChatInputCommandInteraction, GuildMember } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function deletejoinCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const guild = interaction.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/join_messages.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - delete data[serverId]; - writeFile('./database/join_messages.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - console.error(err); - } else { - interaction.reply(embeds.deleteSuccess); - } - }); -} diff --git a/src/interactions/deleteleave.ts b/src/interactions/deleteleave.ts deleted file mode 100644 index 9710241..0000000 --- a/src/interactions/deleteleave.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ServerLeaveData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, ChatInputCommandInteraction, GuildMember } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function deleteleaveCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const guild = interaction.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/leave_messages.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - delete data[serverId]; - writeFile('./database/leave_messages.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - console.error(err); - } else { - interaction.reply(embeds.deleteSuccess); - } - }); -} diff --git a/src/interactions/index.ts b/src/interactions/index.ts index 1ef8db7..759d5ba 100644 --- a/src/interactions/index.ts +++ b/src/interactions/index.ts @@ -1,5 +1,4 @@ import { aboutCommand } from './about'; -import { addroleCommand } from './addrole'; import { avatarCommand } from './avatar'; import { banCommand } from './ban'; import { banlistCommand } from './banlist'; @@ -7,28 +6,20 @@ import { bannerCommand } from './banner'; import { clearCommand } from './clear'; import { closeticketCommand } from './closeticket'; import { createticketCommand } from './createticket'; -import { deletejoinCommand } from './deletejoin'; -import { deleteleaveCommand } from './deleteleave'; import { helpCommand } from './help'; import { inlistCommand } from './inlist'; import { inviteCommand } from './invite'; -import { joinmsgCommand } from './joinmsg'; +import { joinCommand } from './join'; import { kickCommand } from './kick'; -import { leavemsgCommand } from './leavemsg'; +import { leaveCommand } from './leave'; +import { logCommand } from './log'; import { mcskinCommand } from './mcskin'; import { mcstatusCommand } from './mcstatus'; -import { memberlogCommand } from './memberlog'; -import { memberlogstopCommand } from './memberlogstop'; -import { msglogCommand } from './msglog'; -import { msglogstopCommand } from './msglogstop'; import { noCommand } from './no'; import { pingCommand } from './ping'; -import { remroleCommand } from './remrole'; -import { resdeleteCommand } from './resdelete'; -import { resnowCommand } from './resnow'; import { responseCommand } from './response'; -import { rolelogCommand } from './rolelog'; -import { rolelogstopCommand } from './rolelogstop'; +import { responseComplete } from './response_complete'; +import { roleCommand } from './role'; import { searchCommand } from './search'; import { serverCommand } from './server'; import { statusCommand } from './status'; @@ -36,37 +27,26 @@ import { timeoutCommand } from './timeout'; import { untimeoutCommand } from './untimeout'; import { userCommand } from './user'; import { yesCommand } from './yes'; -import { responseComplete } from './response_complete'; export const interactions = { help: helpCommand, about: aboutCommand, - addrole: addroleCommand, avatar: avatarCommand, ban: banCommand, banlist: banlistCommand, banner: bannerCommand, clear: clearCommand, - deletejoin: deletejoinCommand, - deleteleave: deleteleaveCommand, inlist: inlistCommand, invite: inviteCommand, - joinmsg: joinmsgCommand, + join: joinCommand, kick: kickCommand, - leavemsg: leavemsgCommand, + leave: leaveCommand, mcskin: mcskinCommand, mcstatus: mcstatusCommand, - memberlog: memberlogCommand, - memberlogstop: memberlogstopCommand, - msglog: msglogCommand, - msglogstop: msglogstopCommand, ping: pingCommand, - remrole: remroleCommand, - resdelete: resdeleteCommand, - resnow: resnowCommand, + role: roleCommand, response: responseCommand, - rolelog: rolelogCommand, - rolelogstop: rolelogstopCommand, + log: logCommand, search: searchCommand, server: serverCommand, status: statusCommand, @@ -77,5 +57,5 @@ export const interactions = { closeticket: closeticketCommand, yes: yesCommand, no: noCommand, - responseComplete: responseComplete, + responseComplete: responseComplete }; diff --git a/src/interactions/join.ts b/src/interactions/join.ts new file mode 100644 index 0000000..956f2ce --- /dev/null +++ b/src/interactions/join.ts @@ -0,0 +1,47 @@ +import { ServerJoinData } from '../Utils/ServerData'; +import { embeds } from '../embeds'; +import { ChatInputCommandInteraction, Guild, TextBasedChannel } from 'discord.js'; +import { writeFile, readFileSync } from 'fs'; + +export async function joinCommand(interaction: ChatInputCommandInteraction) { + const subcommand = interaction.options.getSubcommand(true); + switch (subcommand) { + case 'message': + { + const detail = interaction.options.getString('detail'); + const channel = interaction.channel as TextBasedChannel; + const guild = interaction.guild as Guild; + const serverId = guild.id; + if (!detail) return interaction.reply(embeds.joinmsgHelp); + const rawData = readFileSync('./database/join_messages.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + data[serverId] = { + joinMessage: detail, + channelId: channel.id + }; + writeFile('./database/join_messages.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + } else { + interaction.reply(embeds.saveSuccess); + } + }); + } + break; + case 'remove': { + const guild = interaction.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/join_messages.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + delete data[serverId]; + writeFile('./database/join_messages.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + console.error(err); + } else { + interaction.reply(embeds.deleteSuccess); + } + }); + } + } +} diff --git a/src/interactions/joinmsg.ts b/src/interactions/joinmsg.ts deleted file mode 100644 index 7494d88..0000000 --- a/src/interactions/joinmsg.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { ServerJoinData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, ChatInputCommandInteraction, GuildMember, TextBasedChannel } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function joinmsgCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const detail = interaction.options.getString('detail'); - const channel = interaction.channel as TextBasedChannel; - const guild = interaction.guild as Guild; - const serverId = guild.id; - if (!detail) return interaction.reply(embeds.joinmsgHelp); - const rawData = readFileSync('./database/join_messages.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - data[serverId] = { - joinMessage: detail, - channelId: channel.id - }; - writeFile('./', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - } else { - interaction.reply(embeds.saveSuccess); - } - }); -} diff --git a/src/interactions/leave.ts b/src/interactions/leave.ts new file mode 100644 index 0000000..2851681 --- /dev/null +++ b/src/interactions/leave.ts @@ -0,0 +1,47 @@ +import { ServerLeaveData } from '../Utils/ServerData'; +import { embeds } from '../embeds'; +import { ChatInputCommandInteraction, Guild, TextBasedChannel } from 'discord.js'; +import { writeFile, readFileSync } from 'fs'; + +export async function leaveCommand(interaction: ChatInputCommandInteraction) { + const subcommand = interaction.options.getSubcommand(true); + switch (subcommand) { + case 'message': + { + const detail = interaction.options.getString('detail'); + const channel = interaction.channel as TextBasedChannel; + const guild = interaction.guild as Guild; + const serverId = guild.id; + if (!detail) return interaction.reply(embeds.leavemsgHelp); + const rawData = readFileSync('./database/leave_messages.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + data[serverId] = { + leaveMessage: detail, + channelId: channel.id + }; + writeFile('./database/leave_messages.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + } else { + interaction.reply(embeds.saveSuccess); + } + }); + } + break; + case 'remove': { + const guild = interaction.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/leave_messages.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + delete data[serverId]; + writeFile('./database/leave_messages.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + console.error(err); + } else { + interaction.reply(embeds.deleteSuccess); + } + }); + } + } +} diff --git a/src/interactions/leavemsg.ts b/src/interactions/leavemsg.ts deleted file mode 100644 index 91d4e01..0000000 --- a/src/interactions/leavemsg.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { ServerLeaveData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, ChatInputCommandInteraction, GuildMember, TextBasedChannel } from 'discord.js'; -import { readFileSync, writeFile } from 'fs'; - -export async function leavemsgCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const detail = interaction.options.getString('detail') as string; - const channel = interaction.channel as TextBasedChannel; - const guild = interaction.guild as Guild; - const serverId = guild.id; - if (!detail) interaction.reply(embeds.leavemsgHelp); - const rawData = readFileSync('./database/leave_messages.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - data[serverId] = { - leaveMessage: detail, - channelId: channel.id - }; - writeFile('./database/leave_messages.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - } else { - interaction.reply(embeds.saveSuccess); - } - }); -} diff --git a/src/interactions/log.ts b/src/interactions/log.ts new file mode 100644 index 0000000..22a8ab2 --- /dev/null +++ b/src/interactions/log.ts @@ -0,0 +1,125 @@ +import { ServerMemberData, ServerMsgData, ServerRoleData } from '../Utils/ServerData'; +import { embeds } from '../embeds'; +import { ChatInputCommandInteraction, Guild, TextBasedChannel } from 'discord.js'; +import { writeFile, readFileSync } from 'fs'; + +export async function logCommand(interaction: ChatInputCommandInteraction) { + const subcommand = interaction.options.getSubcommand(); + switch (subcommand) { + case 'member': + { + const channel = interaction.channel as TextBasedChannel; + const guild = interaction.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/memberlogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + data[serverId] = { + channelId: channel.id + }; + writeFile('./database/memberlogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + console.error(err); + } else { + interaction.reply(embeds.saveSuccess); + } + }); + } + break; + case 'message': + { + const channel = interaction.channel as TextBasedChannel; + const guild = interaction.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/msglogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + data[serverId] = { + channelId: channel.id + }; + writeFile('./database/msglogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + } else { + interaction.reply(embeds.saveSuccess); + } + }); + } + break; + case 'role': + { + const channel = interaction.channel as TextBasedChannel; + const guild = interaction.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/rolelogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + data[serverId] = { + channelId: channel.id + }; + writeFile('./database/rolelogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + console.error(err); + } else { + interaction.reply(embeds.saveSuccess); + } + }); + } + break; + case 'stop': { + const types = interaction.options.getString('type', true); + switch (types) { + case 'member': + { + const guild = interaction.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/memberlogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + delete data[serverId]; + writeFile('./database/memberlogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + console.error(err); + } else { + interaction.reply(embeds.saveSuccess); + } + }); + } + break; + case 'message': + { + const guild = interaction.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/msglogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + delete data[serverId]; + writeFile('./database/msglogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + } else { + interaction.reply(embeds.saveSuccess); + } + }); + } + break; + case 'role': + { + const guild = interaction.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/rolelogs.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + delete data[serverId]; + writeFile('./database/rolelogs.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + console.error(err); + } else { + interaction.reply(embeds.saveSuccess); + } + }); + } + break; + } + break; + } + } +} diff --git a/src/interactions/memberlog.ts b/src/interactions/memberlog.ts deleted file mode 100644 index f8544b9..0000000 --- a/src/interactions/memberlog.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { ServerMemberData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, ChatInputCommandInteraction, GuildMember, TextBasedChannel } from 'discord.js'; -import { readFileSync, writeFile } from 'fs'; - -export async function memberlogCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const channel = interaction.channel as TextBasedChannel; - const guild = interaction.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/memberlogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - data[serverId] = { - channelId: channel.id - }; - writeFile('./database/memberlogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - console.error(err); - } else { - interaction.reply(embeds.saveSuccess); - } - }); -} diff --git a/src/interactions/memberlogstop.ts b/src/interactions/memberlogstop.ts deleted file mode 100644 index 58017e4..0000000 --- a/src/interactions/memberlogstop.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ServerMemberData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, ChatInputCommandInteraction, GuildMember } from 'discord.js'; -import { readFileSync, writeFile } from 'fs'; - -export async function memberlogstopCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const guild = interaction.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/memberlogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - delete data[serverId]; - writeFile('./database/memberlogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - console.error(err); - } else { - interaction.reply(embeds.deleteSuccess); - } - }); -} diff --git a/src/interactions/msglog.ts b/src/interactions/msglog.ts deleted file mode 100644 index 0f13f93..0000000 --- a/src/interactions/msglog.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ServerMsgData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, ChatInputCommandInteraction, GuildMember, TextBasedChannel } from 'discord.js'; -import { readFileSync, writeFile } from 'fs'; - -export async function msglogCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const channel = interaction.channel as TextBasedChannel; - const guild = interaction.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/msglogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - data[serverId] = { - channelId: channel.id - }; - writeFile('./database/msglogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - } else { - interaction.reply(embeds.saveSuccess); - } - }); -} diff --git a/src/interactions/msglogstop.ts b/src/interactions/msglogstop.ts deleted file mode 100644 index 9ea8370..0000000 --- a/src/interactions/msglogstop.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ServerMsgData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, ChatInputCommandInteraction, GuildMember } from 'discord.js'; -import { readFileSync, writeFile } from 'fs'; - -export async function msglogstopCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const guild = interaction.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/msglogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - delete data[serverId]; - writeFile('./database/msglogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - console.error(err); - } else { - interaction.reply(embeds.deleteSuccess); - } - }); -} diff --git a/src/interactions/remrole.ts b/src/interactions/remrole.ts deleted file mode 100644 index ee3fb16..0000000 --- a/src/interactions/remrole.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { embeds } from '../embeds'; -import { ChatInputCommandInteraction, GuildMember, PermissionsBitField, Role } from 'discord.js'; - -export async function remroleCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - if (!interaction.member?.permissions.has(PermissionsBitField.Flags.ManageRoles)) - return interaction.reply(embeds.PermissionError); - if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) - return interaction.reply(embeds.remrolePermissionError); - const role = interaction.options.getRole('role') as Role; - const member = interaction.options.getMember('member') as GuildMember; - if (!role || !member) return interaction.reply(embeds.remroleHelp); - member.roles - .remove(role) - .then(() => { - interaction.reply(embeds.remroleSuccess); - }) - .catch(() => { - interaction.reply(embeds.remroleError); - }); -} diff --git a/src/interactions/resdelete.ts b/src/interactions/resdelete.ts deleted file mode 100644 index bd54d6f..0000000 --- a/src/interactions/resdelete.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { ServerResponseData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { ChatInputCommandInteraction, Guild, GuildMember } from 'discord.js'; -import { writeFile } from 'fs'; -import { readFileSync } from 'fs'; - -export async function resdeleteCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const keyword = interaction.options.getString('keyword') as string; - const guild = interaction.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/responses.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - const serverData = data[serverId]; - if (!serverData || !serverData[keyword]) - return interaction.reply(`キーワード 「${keyword}」 のレスポンスは登録されていません。`); - delete serverData[keyword]; - - writeFile('./database/responses.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - console.error(err); - } else { - interaction.reply(embeds.deleteSuccess); - } - }); -} diff --git a/src/interactions/resnow.ts b/src/interactions/resnow.ts deleted file mode 100644 index 9089ea6..0000000 --- a/src/interactions/resnow.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ServerResponseData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { Guild, ChatInputCommandInteraction } from 'discord.js'; -import { readFileSync } from 'fs'; - -export async function resnowCommand(interaction: ChatInputCommandInteraction) { - const guild = interaction.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/responses.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - const serverData = data[serverId]; - if (!serverData || Object.keys(serverData).length === 0) { - interaction.reply(embeds.resnowEmpty); - return; - } - let responseList = '登録されているレスポンス一覧\n'; - for (const keyword in serverData) { - responseList += `${keyword}: ${serverData[keyword]}\n`; - } - interaction.reply(responseList); -} diff --git a/src/interactions/response.ts b/src/interactions/response.ts index b40a4b3..639e30b 100644 --- a/src/interactions/response.ts +++ b/src/interactions/response.ts @@ -1,28 +1,74 @@ import { ServerResponseData } from '../Utils/ServerData'; import { embeds } from '../embeds'; -import { Guild, ChatInputCommandInteraction, GuildMember } from 'discord.js'; -import { readFileSync, writeFile } from 'fs'; +import { ChatInputCommandInteraction, Guild } from 'discord.js'; +import { writeFile, readFileSync } from 'fs'; export async function responseCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const keyword = interaction.options.getString('keyword') as string; - const response = interaction.options.getString('response') as string; - const guild = interaction.guild as Guild; - const serverId = guild.id; - if (!keyword || !response) return interaction.reply(embeds.responseHelp); - const rawData = readFileSync('./database/responses.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - let serverData = data[serverId]; - if (!serverData) { - serverData = {}; - data[serverId] = serverData; + const subcommand = interaction.options.getSubcommand(true); + switch (subcommand) { + case 'add': + { + const keyword = interaction.options.getString('keyword') as string; + const response = interaction.options.getString('response') as string; + const guild = interaction.guild as Guild; + const serverId = guild.id; + if (!keyword || !response) return interaction.reply(embeds.responseHelp); + const rawData = readFileSync('./database/responses.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + let serverData = data[serverId]; + if (!serverData) { + serverData = {}; + data[serverId] = serverData; + } + serverData[keyword] = response; + writeFile('./database/responses.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + } else { + interaction.reply(embeds.saveSuccess); + } + }); + } + break; + case 'remove': + { + const keyword = interaction.options.getString('keyword') as string; + const guild = interaction.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/responses.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + const serverData = data[serverId]; + if (!serverData || !serverData[keyword]) + return interaction.reply(`キーワード 「${keyword}」 のレスポンスは登録されていません。`); + delete serverData[keyword]; + + writeFile('./database/responses.json', JSON.stringify(data, null, 2), (err) => { + if (err) { + interaction.reply(embeds.defaultError); + console.error(err); + } else { + interaction.reply(embeds.deleteSuccess); + } + }); + } + break; + case 'list': + { + const guild = interaction.guild as Guild; + const serverId = guild.id; + const rawData = readFileSync('./database/responses.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + const serverData = data[serverId]; + if (!serverData || Object.keys(serverData).length === 0) { + interaction.reply(embeds.resnowEmpty); + return; + } + let responseList = '登録されているレスポンス一覧\n'; + for (const keyword in serverData) { + responseList += `${keyword} => ${serverData[keyword]}\n`; + } + interaction.reply(responseList); + } + break; } - serverData[keyword] = response; - writeFile('./database/responses.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - } else { - interaction.reply(embeds.saveSuccess); - } - }); } diff --git a/src/interactions/response_complete.ts b/src/interactions/response_complete.ts index 0266681..821ab05 100644 --- a/src/interactions/response_complete.ts +++ b/src/interactions/response_complete.ts @@ -1,19 +1,17 @@ -import { AutocompleteInteraction, Guild } from "discord.js"; -import { readFileSync } from "fs"; -import { ServerResponseData } from "../Utils/ServerData"; +import { ServerResponseData } from '../Utils/ServerData'; +import { AutocompleteInteraction, Guild } from 'discord.js'; +import { readFileSync } from 'fs'; export async function responseComplete(interaction: AutocompleteInteraction) { - const focusedValue = interaction.options.getFocused(); - const rawData = readFileSync('./database/responses.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - const choices = [] as string[]; - const serverData = data[(interaction.guild as Guild).id]; - if (!serverData || Object.keys(serverData).length === 0) return; - Object.keys(data[(interaction.guild as Guild).id]).forEach(key => { - choices.push(key); - }); - const filtered = choices.filter(choice => choice.startsWith(focusedValue)); - await interaction.respond( - filtered.map(choice => ({ name: choice, value: choice })), - ); -} \ No newline at end of file + const focusedValue = interaction.options.getFocused(); + const rawData = readFileSync('./database/responses.json', 'utf-8'); + const data: Record = JSON.parse(rawData); + const choices = [] as string[]; + const serverData = data[(interaction.guild as Guild).id]; + if (!serverData || Object.keys(serverData).length === 0) return; + Object.keys(data[(interaction.guild as Guild).id]).forEach((key) => { + choices.push(key); + }); + const filtered = choices.filter((choice) => choice.startsWith(focusedValue)); + await interaction.respond(filtered.map((choice) => ({ name: choice, value: choice }))); +} diff --git a/src/interactions/role.ts b/src/interactions/role.ts new file mode 100644 index 0000000..5f9422e --- /dev/null +++ b/src/interactions/role.ts @@ -0,0 +1,40 @@ +import { embeds } from '../embeds'; +import { ChatInputCommandInteraction, GuildMember, PermissionsBitField, Role } from 'discord.js'; + +export async function roleCommand(interaction: ChatInputCommandInteraction) { + const subcommand = interaction.options.getSubcommand(true); + switch (subcommand) { + case 'add': { + if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) + 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(() => { + interaction.reply(embeds.roleAddSuccess); + }) + .catch(() => { + interaction.reply(embeds.roleAddError); + }); + break; + } + case 'remove': { + if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) + return interaction.reply(embeds.remrolePermissionError); + const role = interaction.options.getRole('role') as Role; + const member = interaction.options.getMember('member') as GuildMember; + if (!role || !member) return interaction.reply(embeds.remroleHelp); + member.roles + .remove(role) + .then(() => { + interaction.reply(embeds.remroleSuccess); + }) + .catch(() => { + interaction.reply(embeds.remroleError); + }); + break; + } + } +} diff --git a/src/interactions/rolelog.ts b/src/interactions/rolelog.ts deleted file mode 100644 index 14e3102..0000000 --- a/src/interactions/rolelog.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { ServerRoleData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { ChatInputCommandInteraction, Guild, GuildMember, TextBasedChannel } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function rolelogCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const channel = interaction.channel as TextBasedChannel; - const guild = interaction.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('./database/rolelogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - data[serverId] = { - channelId: channel.id - }; - writeFile('./database/rolelogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - console.error(err); - } else { - interaction.reply(embeds.saveSuccess); - } - }); -} diff --git a/src/interactions/rolelogstop.ts b/src/interactions/rolelogstop.ts deleted file mode 100644 index 5db7136..0000000 --- a/src/interactions/rolelogstop.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ServerRoleData } from '../Utils/ServerData'; -import { embeds } from '../embeds'; -import { ChatInputCommandInteraction, Guild, GuildMember } from 'discord.js'; -import { writeFile, readFileSync } from 'fs'; - -export async function rolelogstopCommand(interaction: ChatInputCommandInteraction) { - if (!(interaction.member instanceof GuildMember)) return; - const guild = interaction.guild as Guild; - const serverId = guild.id; - const rawData = readFileSync('/database/rolelogs.json', 'utf-8'); - const data: Record = JSON.parse(rawData); - delete data[serverId]; - writeFile('../database/rolelogs.json', JSON.stringify(data, null, 2), (err) => { - if (err) { - interaction.reply(embeds.defaultError); - console.error(err); - } else { - interaction.reply(embeds.deleteSuccess); - } - }); -} From 31762e5fdc60bcf08183a361b4040e72c00b160e Mon Sep 17 00:00:00 2001 From: MotiCAT Date: Wed, 3 Jan 2024 22:37:32 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=B9=20format=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- src/embeds/index.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4be00f4..4cc92fa 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Motcher + (多分)便利Bot -動作確認中 \ No newline at end of file +動作確認中 diff --git a/src/embeds/index.ts b/src/embeds/index.ts index 05657ac..62fa05b 100644 --- a/src/embeds/index.ts +++ b/src/embeds/index.ts @@ -20,7 +20,7 @@ export const embeds = { value: '`join`, `leave`, `response`, `log`' }, { name: 'Minecraft', value: '`mcskin`, `mcstatus`' }, - { name: 'Moderation', value: '`ban`, `unban`, `kick`, `role`, `clear`, `timeout`, `untimeout`' }, + { name: 'Moderation', value: '`ban`, `unban`, `kick`, `role`, `clear`, `timeout`, `untimeout`' } ) .setTimestamp() .setFooter({ text: 'Motcher v2.0', iconURL: 'https://i.imgur.com/fEtyr1I.png' })