{
"version": 3,
"sources": ["../../../../server/chat-plugins/friends.ts"],
"sourcesContent": ["/**\n * Friends list plugin.\n * Allows for adding and removing friends, as well as seeing their activity.\n * Written by Mia.\n * @author mia-pi-git\n */\n\nimport {Utils} from '../../lib/utils';\nimport {MAX_REQUESTS, sendPM} from '../friends';\n\nconst STATUS_COLORS: {[k: string]: string} = {\n\tidle: '#ff7000',\n\tonline: '#009900',\n\tbusy: '#cc3838',\n};\n\nconst STATUS_TITLES: {[k: string]: string} = {\n\tonline: 'Online',\n\tidle: 'Idle',\n\tbusy: 'Busy',\n\toffline: 'Offline',\n};\n\n// once every 15 minutes\nconst LOGIN_NOTIFY_THROTTLE = 15 * 60 * 1000;\n\nexport const Friends = new class {\n\tasync notifyPending(user: User) {\n\t\tif (user.settings.blockFriendRequests) return;\n\t\tconst friendRequests = await Chat.Friends.getRequests(user);\n\t\tconst pendingCount = friendRequests.received.size;\n\t\tif (pendingCount < 1) return;\n\t\tif (pendingCount === 1) {\n\t\t\tconst sender = [...friendRequests.received][0];\n\t\t\tconst senderName = Users.getExact(sender)?.name || sender;\n\t\t\tlet buf = Utils.html`/uhtml sent, | `;\n\t\t\tbuf += Utils.html`
`;\n\t\t\tbuf += `(You can also stop this user from sending you friend requests with /ignore)`;\n\t\t\tsendPM(Utils.html`/raw ${senderName} sent you a friend request!`, user.id);\n\t\t\tsendPM(buf, user.id);\n\t\t\tsendPM(\n\t\t\t\t`/raw Note: If this request is accepted, your friend will be notified when you come online, ` +\n\t\t\t\t`and you will be notified when they do, unless you opt out of receiving them.`,\n\t\t\t\tuser.id\n\t\t\t);\n\t\t} else {\n\t\t\tsendPM(`/nonotify You have ${pendingCount} friend requests pending!`, user.id);\n\t\t\tsendPM(`/raw `, user.id);\n\t\t}\n\t}\n\tasync notifyConnection(user: User) {\n\t\tconst connected = await Chat.Friends.getLastLogin(user.id);\n\t\tif (connected && (Date.now() - connected) < LOGIN_NOTIFY_THROTTLE) {\n\t\t\treturn;\n\t\t}\n\t\tconst friends = await Chat.Friends.getFriends(user.id);\n\t\tconst message = `/nonotify Your friend
/friend add [username]./friend list - View current friends.`,\n\t\t\t\t`/friend add [name] OR /friend [name] - Send a friend request to [name], if you don't have them added.`,\n\t\t\t\t`/friend remove [username] OR /unfriend [username] - Unfriend the user.`,\n\t\t\t\t`/friend accept [username] - Accepts the friend request from [username], if it exists.`,\n\t\t\t\t`/friend reject [username] - Rejects the friend request from [username], if it exists.`,\n\t\t\t\t`/friend toggle [off/on] - Enable or disable receiving of friend requests.`,\n\t\t\t\t`/friend hidenotifications OR hidenotifs - Opts out of receiving friend notifications.`,\n\t\t\t\t`/friend viewnotifications OR viewnotifs - Opts into view friend notifications.`,\n\t\t\t\t`/friend listdisplay [on/off] - Opts [in/out] of letting others view your friends list.`,\n\t\t\t\t`/friend viewlist [user] - View the given [user]'s friend list, if they're allowing others to see.`,\n\t\t\t\t`/friends sharebattles [on|off] - Allow or disallow your friends from seeing your ongoing battles./friend add [username].`;\n\t\t\t\tbuf += `/friend list - View current friends.`,\n\t\t\t\t`/friend add [name] OR /friend [name] - Send a friend request to [name], if you don't have them added.`,\n\t\t\t\t`/friend remove [username] OR /unfriend [username] - Unfriend the user.`,\n\t\t\t\t`/friend accept [username] - Accepts the friend request from [username], if it exists.`,\n\t\t\t\t`/friend reject [username] - Rejects the friend request from [username], if it exists.`,\n\t\t\t\t`/friend toggle [off/on] - Enable or disable receiving of friend requests.`,\n\t\t\t\t`/friend hidenotifications OR hidenotifs - Opts out of receiving friend notifications.`,\n\t\t\t\t`/friend viewnotifications OR viewnotifs - Opts into view friend notifications.`,\n\t\t\t\t`/friend listdisplay [on/off] - Opts [in/out] of letting others view your friends list.`,\n\t\t\t\t`/friend viewlist [user] - View the given [user]'s friend list, if they're allowing others to see.`,\n\t\t\t\t`/friends sharebattles [on|off] - Allow or disallow your friends from seeing your ongoing battles.`,\n\t\t\t].join('