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