diff --git a/src/commands/RemoveLink.ts b/src/commands/RemoveLink.ts new file mode 100644 index 0000000..eb39d06 --- /dev/null +++ b/src/commands/RemoveLink.ts @@ -0,0 +1,29 @@ +import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'; +import ConfigController from '../controller/ConfigController'; +import EcoController from '../controller/EcoController'; +import { Command } from '.'; + +export default { + data: new SlashCommandBuilder() + .setName('remove_link') + .setDescription('Remove link Discord and Game accaunt') + .setDescriptionLocalization("ru", "Связь Discord и Игрового аккаунта") + .addUserOption(opt => opt.setName("user").setDescription("Discord user").setRequired(true)), + async execute(interaction) { + var user = interaction.options.getUser('user') + + await interaction.deferReply({ ephemeral: true }) + + try { + if (!!user) { + global.config.users.delete(user.id) + global.config.authCodes.delete(user.id) + await interaction.followUp("Связь удалена") + } else + await interaction.followUp("Пользователь не указан") + } catch (error) { + await interaction.editReply("Ошибка удаления связи") + console.log(error) + } + }, +} as Command \ No newline at end of file diff --git a/src/commands/UserMessage.ts b/src/commands/UserMessage.ts index e8a2ea4..c733946 100644 --- a/src/commands/UserMessage.ts +++ b/src/commands/UserMessage.ts @@ -2,6 +2,7 @@ import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, S import ConfigController from '../controller/ConfigController'; import EcoController from '../controller/EcoController'; import { Command } from '.'; +import { userInfo } from 'os'; export default { data: new SlashCommandBuilder() @@ -20,7 +21,11 @@ export default { try { if (user !== undefined) { - if (!message) { + if (!global.config.usersInGame.filter(u => u.SlgId === user.SlgId || u.SteamId === user.SteamId).length) { + await interaction.followUp(`Ошибка отправки сообщения, повторите привязку аккаунта или повторите через 20 секунд`); + return + } + else if (!message) { await interaction.followUp(`Ошибка отправки сообщения`); return } diff --git a/src/commands/index.ts b/src/commands/index.ts index a99df02..ce528b2 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -8,6 +8,7 @@ import setChatChannelId from './setChatChannelId' import throwChatTimestamp from './throwChatTimestamp' import UserMessage from './UserMessage' import Link from './Link' +import RemoveLink from './RemoveLink' export type Command = { data: SlashCommandBuilder; @@ -26,5 +27,6 @@ commands.set(setChatChannelId.data.name, setChatChannelId) commands.set(throwChatTimestamp.data.name, throwChatTimestamp) commands.set(UserMessage.data.name, UserMessage) commands.set(Link.data.name, Link) +commands.set(RemoveLink.data.name, RemoveLink) export default commands