{
"version": 3,
"sources": ["../../../../server/chat-commands/avatars.tsx"],
"sourcesContent": ["/**\n * Avatar commands\n * Pokemon Showdown - http://pokemonshowdown.com/\n *\n * @license MIT\n * @author Zarel \n\t\t\t\t\t\tYou have a new custom avatar!\n\t\t\t\t\t \n\t\t\t\t\t\t{entry.allowed.map(avatar => avatar && [Avatars.img(avatar), ' '])}\n\t\t\t\t\t Custom avatars from account {id}: \n\t\t\t\t\t\t\t\t{hasButton ?\n\t\t\t\t\t\t\t\t\t :\n\t\t\t\t\t\t\t\t\tAvatars.img(avatar!)\n\t\t\t\t\t\t\t\t} {}\n\t\t\t\t\t\t\t\t User {toID(target)} doesn't have any custom avatars. Custom avatars require you to be a contributor/staff or win a tournament prize. \n\t\t\t\tYou can by clicking on it in the {}\n\t\t\t\t menu in the upper {}\n\t\t\t\tright.\n\t\t\t \n\t\t\t\tAvatars from generations other than 4-5 are hidden. You can find them in this {}\n\t\t\t\tfull list of avatars. {}\n\t\t\t\tYou can use them by typing {Avatars.img(target, true)} \n\t\t\t\t No users currently allowed to use this avatar{avatar};\n\t\treturn ;\n\t}\n\tgetDefault(userid: ID) {\n\t\tconst entry = customAvatars[userid];\n\t\tif (!entry) return null;\n\t\tconst DECEMBER = 11; // famous JavaScript issue\n\t\tif (new Date().getMonth() === DECEMBER && entry.allowed.some(avatar => avatar?.endsWith('xmas'))) {\n\t\t\treturn entry.allowed.find(avatar => avatar?.endsWith('xmas'));\n\t\t}\n\t\treturn entry.default === undefined ? entry.allowed[0] : entry.default;\n\t}\n\t/** does not include validation */\n\tsetDefault(userid: ID, avatar: AvatarID | null) {\n\t\tif (avatar === this.getDefault(userid)) return;\n\t\tif (!customAvatars[userid]) customAvatars[userid] = {allowed: [null]};\n\t\tconst entry = customAvatars[userid];\n\n\t\tif (avatar === entry.allowed[0]) {\n\t\t\tdelete entry.default;\n\t\t} else {\n\t\t\tentry.default = avatar;\n\t\t}\n\t\tsaveCustomAvatars();\n\t}\n\taddAllowed(userid: ID, avatar: AvatarID | null) {\n\t\tif (!customAvatars[userid]) customAvatars[userid] = {allowed: [null]};\n\n\t\tif (customAvatars[userid].allowed.includes(avatar)) return false;\n\n\t\tcustomAvatars[userid].allowed.push(avatar);\n\t\tcustomAvatars[userid].notNotified = true;\n\t\tthis.tryNotify(Users.get(userid));\n\t\treturn true;\n\t}\n\tremoveAllowed(userid: ID, avatar: AvatarID | null) {\n\t\tconst entry = customAvatars[userid];\n\t\tif (!entry?.allowed.includes(avatar)) return false;\n\n\t\tif (entry.allowed[0] === avatar) {\n\t\t\tentry.allowed[0] = null;\n\t\t} else {\n\t\t\tentry.allowed = entry.allowed.filter(a => a !== avatar) as any;\n\t\t}\n\t\tif (!entry.allowed.some(Boolean)) delete customAvatars[userid];\n\t\treturn true;\n\t}\n\taddPersonal(userid: ID, avatar: AvatarID | null) {\n\t\tif (!customAvatars[userid]) customAvatars[userid] = {allowed: [null]};\n\t\tconst entry = customAvatars[userid];\n\n\t\tif (entry.allowed.includes(avatar)) return false;\n\n\t\tentry.timeReceived ||= Date.now();\n\t\tentry.timeUpdated = Date.now();\n\t\tif (!entry.allowed[0]) {\n\t\t\tentry.allowed[0] = avatar;\n\t\t} else {\n\t\t\tentry.allowed.unshift(avatar);\n\t\t}\n\t\tdelete entry.default;\n\t\tentry.notNotified = true;\n\t\tthis.tryNotify(Users.get(userid));\n\t\treturn true;\n\t}\n\thandleLogin(user: User) {\n\t\tconst avatar = this.getDefault(user.id);\n\t\tif (avatar) user.avatar = avatar;\n\t\tthis.tryNotify(user);\n\t}\n\ttryNotify(user?: User | null) {\n\t\tif (!user) return;\n\n\t\tconst entry = customAvatars[user.id];\n\t\tif (entry?.notNotified) {\n\t\t\tuser.send(\n\t\t\t\t`|pm|&|${user.getIdentity()}|/raw ` +\n\t\t\t\tChat.html`${<>\n\t\t\t\t\t
/avatar {avatar!.replace('#', '')}\n\t\t\t\t\t\t\t/avatar [avatar's name] into any chat. For example, {}\n\t\t\t\t/avatar erika-gen2.\n\t\t\t
\n\t\t\tAdded to
\n\t\t\tAdded to
\n\t\t\t\tRemoved from
\n\t\t\t\tRemoved from {target}
\n\t\t\t\t{users ? listUsers(users) :
{Avatars.img(avatar, true)}
);\n\t\t\tout.push({avatar}