${targetUserid}'s last ${Chat.count(count, \"teams\")}
`;\n\t\t\tbuf += refresh(this);\n\t\t\tbuf += `
Search your teams `;\n\t\t\tbuf += `
Browse public teams`;\n\t\t\tif (targetUserid === user.id) {\n\t\t\t\tbuf += `
Upload new`;\n\t\t\t}\n\t\t\tbuf += `
`;\n\t\t\tfor (const team of teams) {\n\t\t\t\tbuf += TeamsHandler.preview(team, user);\n\t\t\t\tbuf += `
`;\n\t\t\t}\n\t\t\tconst total = await TeamsHandler.count(user.id);\n\t\t\tif (total > count) {\n\t\t\t\tbuf += `
`;\n\t\t\t}\n\t\t\treturn buf;\n\t\t},\n\t\tasync filtered(query, user, connection) {\n\t\t\tif (!user.named) return Rooms.RETRY_AFTER_LOGIN;\n\t\t\tconst type = query.shift() || \"\";\n\t\t\tTeamsHandler.validateAccess(connection);\n\t\t\tlet count = Number(query.shift()) || 50;\n\t\t\tif (count > MAX_TEAMS) count = MAX_TEAMS;\n\t\t\tlet teams: StoredTeam[] = [], title = '';\n\t\t\tconst buttons: {[k: string]: string} = {\n\t\t\t\tviews: `
`,\n\t\t\t\tlatest: `
`,\n\t\t\t};\n\t\t\tswitch (type) {\n\t\t\tcase 'views':\n\t\t\t\tthis.title = `[Most Viewed Teams]`;\n\t\t\t\tteams = await TeamsHandler.query(\n\t\t\t\t\t`SELECT * FROM teams WHERE private IS NULL ORDER BY views DESC LIMIT $1`, [count]\n\t\t\t\t);\n\t\t\t\ttitle = `Most viewed teams:`;\n\t\t\t\tdelete buttons.views;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.title = `[Latest Teams]`;\n\t\t\t\tteams = await TeamsHandler.query(\n\t\t\t\t\t`SELECT * FROM teams WHERE private IS NULL ORDER BY date DESC LIMIT $1`, [count]\n\t\t\t\t);\n\t\t\t\ttitle = `Recently uploaded teams:`;\n\t\t\t\tdelete buttons.latest;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlet buf = `
${title}
${refresh(this)}`;\n\t\t\tbuf += Object.values(buttons).join('
');\n\t\t\tbuf += `
`;\n\t\t\tbuf += teams.map(team => TeamsHandler.preview(team, user)).join('
');\n\t\t\tbuf += ``;\n\t\t\treturn buf;\n\t\t},\n\t\tasync view(query, user, connection) {\n\t\t\tif (!user.named) return Rooms.RETRY_AFTER_LOGIN;\n\t\t\tTeamsHandler.validateAccess(connection);\n\t\t\tconst rawTeamid = toID(query.shift() || \"\");\n\t\t\tconst password = toID(query.shift());\n\t\t\tthis.title = `[View Team]`;\n\t\t\tconst teamid = Number(rawTeamid);\n\t\t\tif (isNaN(teamid)) {\n\t\t\t\tthrow new Chat.ErrorMessage(`Invalid team ID.`);\n\t\t\t}\n\t\t\tconst team = await TeamsHandler.get(teamid);\n\t\t\tif (!team) {\n\t\t\t\tthis.title = `[Invalid Team]`;\n\t\t\t\treturn this.errorReply(`No team with the ID ${teamid} was found.`);\n\t\t\t}\n\t\t\tif (team?.private && user.id !== team.ownerid && password !== team.private) {\n\t\t\t\tthis.title = `[Private Team]`;\n\t\t\t\treturn this.errorReply(`That team is private.`);\n\t\t\t}\n\t\t\tthis.title = `[Team] ${team.teamid}`;\n\t\t\tif (user.id !== team.ownerid && team.views >= 0) {\n\t\t\t\tvoid TeamsHandler.updateViews(team.teamid);\n\t\t\t}\n\t\t\treturn `
` + TeamsHandler.renderTeam(team, user) + \"
\";\n\t\t},\n\t\tupload(query, user, connection) {\n\t\t\tif (!user.named) return Rooms.RETRY_AFTER_LOGIN;\n\t\t\tTeamsHandler.validateAccess(connection);\n\t\t\tthis.title = `[Upload Team]`;\n\t\t\tlet buf = `
Upload a team
${refresh(this)}
`;\n\t\t\t// let [teamName, formatid, rawPrivacy, rawTeam] = Utils.splitFirst(target, ',', 4);\n\t\t\tbuf += ``;\n\t\t\treturn buf;\n\t\t},\n\t\tasync edit(query, user, connection) {\n\t\t\tif (!user.named) return Rooms.RETRY_AFTER_LOGIN;\n\t\t\tTeamsHandler.validateAccess(connection);\n\t\t\tconst teamID = toID(query.shift() || \"\");\n\t\t\tif (!teamID.length) {\n\t\t\t\treturn this.errorReply(`Invalid team ID.`);\n\t\t\t}\n\t\t\tthis.title = `[Edit Team] ${teamID}`;\n\t\t\tconst data = await TeamsHandler.get(teamID);\n\t\t\tif (!data) {\n\t\t\t\treturn this.errorReply(`Team ${teamID} not found.`);\n\t\t\t}\n\t\t\tlet buf = `
Edit team ${teamID}
${refresh(this)}
`;\n\t\t\t// let [teamName, formatid, rawPrivacy, rawTeam] = Utils.splitFirst(target, ',', 4);\n\t\t\tbuf += ``;\n\t\t\treturn buf;\n\t\t},\n\t\tasync searchpublic(query, user, connection) {\n\t\t\tif (!user.named) return Rooms.RETRY_AFTER_LOGIN;\n\t\t\tTeamsHandler.validateAccess(connection, true);\n\t\t\tthis.title = '[Teams] Search';\n\t\t\tlet buf = '
';\n\t\t\tbuf += refresh(this);\n\t\t\tbuf += '
Search all teams';\n\t\t\tconst type = this.pageid.split('-')[2];\n\t\t\tconst isPersonal = type === 'searchpersonal';\n\t\t\tquery = query.join('-').split('--');\n\t\t\tif (!query.map(toID).filter(Boolean).length || (isPersonal && query.length === 1)) {\n\t\t\t\tbuf += `
`;\n\t\t\t\tbuf += `