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('link') .setDescription('Link Discord and Game accaunt') .setDescriptionLocalization("ru", "Связь Discord и Игрового аккаунта") .addStringOption(opt => opt.setName("id").setDescription("SteamID64 or SLGID").setDescriptionLocalization("ru", "SteamID64 или SLGID").setRequired(true)) .addStringOption(opt => opt.setName("code").setDescription("Confirmation code").setDescriptionLocalization("ru", "Код подтверждения").setRequired(false)), async execute(interaction) { var id = interaction.options.getString('id') var codeConfirmation = interaction.options.getString('code') const ecoController = new EcoController() const user = global.config.users.get(interaction.user.id) const userCode = global.config.authCodes.get(interaction.user.id) const userG = global.config.usersInGame.filter(u => u.SlgId === id || u.SteamId === id).length > 0 ? global.config.usersInGame.filter(u => u.SlgId === id || u.SteamId === id)[0] : null await interaction.deferReply({ ephemeral: true }) const code = Math.floor(1000 + Math.random() * 9000).toString(); const codeUser = Math.floor(1000 + Math.random() * 9000).toString(); try { if (!!codeConfirmation && !!userG) { if (userCode === codeConfirmation && !id) { global.config.users.set(interaction.user.id, userG) global.config.authCodes.set(interaction.user.id, "-") await interaction.followUp(`Аккаунт успешно привязан`) } else { await interaction.followUp(`Ошибка привязки аккаунта, проверьте введённые данные`) } return } else if (user === undefined && !!userG && user === undefined) { const status = await ecoController.Message(`Для связи аккаунтов введите код ${code}, иначе проигнорируйте данное сообщение`, `ChatLink${codeUser}`, `@${userG.Name}`) if (!!status && status.Success) { await interaction.followUp(`Код отправлен в личные сообщения от пользователя \`ChatLink${codeUser}\`, для продолжения введите эту команду, указав код полученный в игре`) } else { await interaction.followUp("Ошибка отправки кода") } global.config.authCodes.set(interaction.user.id, code) return } else if (user !== undefined) { await interaction.followUp("Ваш аккаунт уже привязан, для отвязки свяжитесь с администрацией") } else if (!userG) { await interaction.followUp("Такой пользователь не найден на сервере") } else { await interaction.followUp("Вы уже воспользовались данной функцией, обратитесь к администрации в случае возникновения проблемы") } } catch (error) { await interaction.editReply("Ошибка отправки кода") console.log(error) } }, } as Command