const ESMCommand = require("../esm_command"); const Steam = require("../../code/steam"); module.exports = class ESMCommand_Whois extends ESMCommand { constructor(bot) { super(bot); this.permissions = { disabled_in_player_mode: true, text_only: true }; this.commandParams = { user: { regex: /.+/ } }; this.information = { category: "system", params: "<@user | steam_uid | discord_id>", help: "Displays information about the user. The user **must** be a member of this Discord. This command can only be used in a text channel and is only available for a certain role." }; this.configuration = { permissions: { modifiable: true, default: {} }, allowedInTextChannels: { modifiable: false, default: true }, cooldown: { modifiable: false, default: [5, "seconds"] } }; } async fromDiscord() { if (this.util.regex.discordTag.only.test(this.params.user)) { this.processDiscord(); } else if (this.util.regex.steamUID.only.test(this.params.user)) { this.processSteamUID(); } else if (this.util.regex.discordID.only.test(this.params.user)) { this.processDiscord(); } else { return this.ESMBot.send(this.message.channel, `${this.message.author.toString()}, The provided user \`${this.params.user}\` is not in a format that I can process.\nPlease provide a @user, steamUID or Discord ID`); } } async processDiscord() { let steamInfo = null; let user = await this.ESMBot.getUser(this.params.user); if (await this.db.isRegistered(user.id)) { let steamUID = await this.db.getSteamUIDFromID(user.id); steamInfo = await this.getSteamInfo(steamUID); } let message = this.createMessage([user], steamInfo); this.ESMBot.send(this.message.channel, message); } async processSteamUID() { let steamInfo = await this.getSteamInfo(this.params.user); let discordIDs = await this.db.getDiscordIDsFromSteamUID(this.params.user); let users = []; for (let id of discordIDs) { let user = await this.ESMBot.getUser(id); users.push(user); } let message = this.createMessage(users, steamInfo); if (this.util.isEmpty(message)) { return this.ESMBot.send(this.message.channel, `I couldn't find ${this.params.user}`); } this.ESMBot.send(this.message.channel, message); } async getSteamInfo(steamUID) { try { let profileData = await Steam.getSteamUserData(steamUID); if (!profileData.response) throw false; return profileData.data; } catch (err) { return null; } } createMessage(users = null, steamInfo = null) { if (users == null && steamInfo == null) return ""; let embed = new this.ESMBot.discord.MessageEmbed() .setColor(this.ESMBot.colors.BLUE) .setTimestamp(); if (!this.util.isEmpty(users)) { embed.addField("\u200B", "__Discord Information__") .setAuthor(users[0].tag, users[0].avatarURL()) .setThumbnail(users[0].avatarURL()); for (let i = 0; i < users.length; i++) { let user = users[i]; if (i !== 0) { embed.addField("\u200B", "\u200B"); } embed.addField("Username", user.tag, true) .addField("ID", user.id, true) .addField("Status", _.capitalize(user.presence.status), true) .addField("Created", moment(user.createdAt).format("MMM Do YYYY, h:mm:ss a"), true); } } if (steamInfo != null) { embed.setThumbnail(steamInfo.avatar) .addField("\u200B", "__Steam Information__") .addField("Username", steamInfo.username, true) .addField("ID", steamInfo.steamid, true) .addField("Profile Visibility", { 1: "Private", 2: "Friends Only", 3: "Public" } [steamInfo.communityvisibilitystate], true) .addField("Profile", `[${steamInfo.username}'s Profile](${steamInfo.profileurl})`, true) .addField("Created", moment(new Date(steamInfo.timecreated * 1000)).format("MMM Do YYYY, h:mm:ss a"), true); } return embed; } }