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