"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var smogtours_exports = {}; __export(smogtours_exports, { commands: () => commands, pages: () => pages, renderPageChooser: () => renderPageChooser, tours: () => tours }); module.exports = __toCommonJS(smogtours_exports); var import_lib = require("../../lib"); const tours = { official: { title: "Smogon Officials", // cap this one's dimensions icon: ["https://www.smogon.com/media/zracknel-beta.svg", 178, 200], tours: [], desc: "Tournaments run by Smogon staff." }, smogon: { title: "Open Sign-Ups", tours: [], desc: "Tournaments run by Smogon staff and regular users alike." }, ps: { title: "Pok\xE9mon Showdown!", icon: ["https://play.pokemonshowdown.com/pokemonshowdownbeta.png", 146, 44], tours: [], desc: "Tournaments run by the rooms of Pokemon Showdown." } }; try { const data = JSON.parse((0, import_lib.FS)("config/chat-plugins/smogtours.json").readSync()); const PRIO = ["title", "icon"]; for (const key in data) { const section = tours[key] || (tours[key] = data[key]); for (const k in data[key]) { if (PRIO.includes(k)) { if (!section[k]) section[k] = data[key][k]; } else { section[k] = data[key][k]; } } } } catch { } function saveTours() { (0, import_lib.FS)("config/chat-plugins/smogtours.json").writeUpdate(() => JSON.stringify(tours)); } function getTour(categoryID, id) { id = toID(id); return tours?.[categoryID].tours.find((f) => f.id === id) || null; } function checkWhitelisted(category, user) { return category ? tours[category].whitelist?.includes(user.id) : Object.values(tours).some((f) => f.whitelist?.includes(user.id)); } function checkCanEdit(user, context, category) { category = toID(category); if (!checkWhitelisted(category, user)) { context.checkCan("rangeban"); } } const commands = { smogtours: { ""() { return this.parse("/j view-tournaments-all"); }, edit: "add", async add(target, room, user, connection, cmd) { if (!toID(target).length) { return this.parse(`/help smogtours`); } const targets = target.split("|"); const isEdit = cmd === "edit"; const tourID = isEdit ? toID(targets.shift()) : null; const [ title, rawSection, url, rawImg, rawShort, rawDesc ] = import_lib.Utils.splitFirst(targets.join("|"), "|", 5).map((f) => f.trim()); const sectionID = toID(rawSection); if (!toID(title)) { return this.popupReply(`Invalid title. Must have at least one alphanumeric character.`); } const section = tours[sectionID]; if (!section) { return this.errorReply(`Invalid section ID: "${sectionID}"`); } if (!isEdit && section.tours.find((f) => toID(title) === f.id)) { return this.popupReply(`A tour with that ID already exists. Please choose another.`); } checkCanEdit(user, this, sectionID); if (!Chat.isLink(url)) { return this.popupReply(`Invalid info URL: "${url}"`); } let image; if (rawImg) { if (!Chat.isLink(rawImg)) { return this.popupReply(`Invalid image URL: ${rawImg}`); } try { const dimensions = await Chat.fitImage(rawImg, 300, 300); image = [rawImg, ...dimensions.slice(0, -1)]; } catch (e) { return this.popupReply(`Invalid image URL: ${rawImg}`); } } if (!rawShort?.length || !rawDesc?.length) { return this.popupReply(`Must provide both a short description and a full description.`); } const tour = { title: import_lib.Utils.escapeHTML(title), url, image, shortDesc: rawShort.replace(/ /g, "\n"), desc: rawDesc.replace(/ /g, "\n"), id: tourID || toID(title), date: Date.now() }; if (isEdit) { const index = section.tours.findIndex((t) => t.id === tour.id); if (index < 0) { return this.popupReply(`Tour not found. Create one first.`); } section.tours.splice(index, 1); } section.tours.push(tour); saveTours(); this.refreshPage(`tournaments-add`); }, end(target, room, user, connection) { const [sectionID, tourID] = target.split(",").map(toID).filter(Boolean); if (!sectionID || !tourID) { return this.parse(`/help smogtours`); } const section = tours[sectionID]; if (!section) return this.popupReply(`Invalid section: "${sectionID}"`); const idx = section.tours.findIndex((t) => t.id === tourID); const title = section.tours[idx].title; if (idx < 0) { return this.popupReply(`Tour with ID "${tourID}" not found.`); } section.tours.splice(idx, 1); this.refreshPage(`tournaments-view-${sectionID}-${tourID}`); this.popupReply(`Tour "${title}" ended.`); }, whitelist(target, room, user) { this.checkCan("rangeban"); const [sectionID, targetID] = target.split(",").map(toID).filter(Boolean); if (!sectionID || !targetID) { return this.parse(`/help smogtours`); } const section = tours[sectionID]; if (!section) { return this.errorReply(`Invalid section ID: "${sectionID}". Valid IDs: ${Object.keys(tours).join(", ")}`); } if (section.whitelist?.includes(targetID)) { return this.errorReply(`That user is already whitelisted on that section.`); } if (!section.whitelist) section.whitelist = []; section.whitelist.push(targetID); this.privateGlobalModAction( `${user.name} whitelisted ${targetID} to manage tours for the ${section.title} section` ); this.globalModlog("TOUR WHITELIST", targetID); saveTours(); }, unwhitelist(target, room, user) { this.checkCan("rangeban"); const [sectionID, targetID] = target.split(",").map(toID).filter(Boolean); if (!sectionID || !targetID) { return this.parse(`/help smogtours`); } const section = tours[sectionID]; if (!section) { return this.errorReply(`Invalid section ID: "${sectionID}". Valid IDs: ${Object.keys(tours).join(", ")}`); } const idx = section.whitelist?.indexOf(targetID) ?? -1; if (!section.whitelist || idx < 0) { return this.errorReply(`${targetID} is not whitelisted in that section.`); } section.whitelist.splice(idx, 1); if (!section.whitelist.length) { delete section.whitelist; } this.privateGlobalModAction( `${user.name} removed ${targetID} from the tour management whitelist for the ${section.title} section` ); this.globalModlog("TOUR UNWHITELIST", targetID); saveTours(); }, view() { return this.parse(`/join view-tournaments-all`); } }, smogtourshelp: [ `/smogtours view - View a list of ongoing forum tournaments.`, `/smogtours whitelist [section], [user] - Whitelists the given [user] to manage tournaments for the given [section].`, `Requires: &`, `/smogtours unwhitelist [section], [user] - Removes the given [user] from the [section]'s management whitelist.`, `Requires: &` ] }; function renderTab(inner, isTitle, isCur) { isTitle = false; let buf = ""; if (isCur) { buf += `
`; buf += `
`; buf += `
${inner}
`; } else { if (!isTitle) { inner = `
${inner}
`; } buf += `
${inner}
`; } return buf; } const refresh = (pageid) => ``; const back = (section) => ` Back`; function renderPageChooser(curPage, buffer, user) { let buf = `
`; buf += `
`; buf += `
`; const keys = Object.keys(tours); buf += keys.map((cat) => { let innerBuf = ""; const tourData = tours[cat]; innerBuf += renderTab( `${tourData.title}`, true, curPage === cat ); if (tourData.tours.length) { import_lib.Utils.sortBy(tourData.tours, (t) => -t.date); innerBuf += tourData.tours.map((t) => renderTab( `${t.title}`, false, curPage === `${cat}-${t.id}` )).join(""); } else { innerBuf += renderTab(`None`, false); } return innerBuf; }).join('
'); if (user && (checkWhitelisted("", user) || user?.can("rangeban"))) { buf += `
`; buf += renderTab( `Manage`, true, curPage === "manage" ); buf += renderTab( `Start new`, false, curPage === "start" ); buf += renderTab( `Edit existing`, false, curPage === "edit" ); if (user.can("rangeban")) { buf += renderTab( `Whitelist`, false, curPage === "whitelist" ); } } buf += `
`; buf += `${buffer}
`; return buf; } function error(page, message, user) { return renderPageChooser(page, `
${message}
`, user); } const pages = { tournaments: { all(query, user) { let buf = `${refresh(this.pageid)}
`; buf += `

Welcome!

`; const icon = tours.official.icon; if (icon) buf += `
`; buf += `
`; this.title = "[Tournaments] All"; buf += `

Smogon runs official tournaments across their metagames where the strongest and most `; buf += `experienced competitors duke it out for prizes and recognition!

`; buf += `You can see a listing of current official tournaments here; `; buf += `by clicking any hyperlink, you will be directed to the forum for any given tournament!

`; buf += `Be sure to sign up if you are eager to participate or `; buf += `check it out if you want to spectate the most hyped games out there.

`; buf += `For information on tournament rules and etiquette, check out this information thread.`; buf += `

`; buf += Object.keys(tours).map((catID) => ` ${tours[catID].title}`).join(" "); buf += `
`; return renderPageChooser("", buf, user); }, view(query, user) { const [categoryID, tourID] = query.map(toID); if (!categoryID || !tourID) { return error("", "You must specify a tour category and a tour ID.", user); } this.title = `[Tournaments] [${categoryID}] `; if (!tours[categoryID]) { return error("", `Invalid tour section: '${categoryID}'.`, user); } const tour = getTour(categoryID, tourID); if (!tour) { return error(categoryID, `Tour '${tourID}' not found.`, user); } this.title += `${tour.title}`.replace(/"/g, '"').replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&"); let buf = `${back(categoryID)}${refresh(this.pageid)}
`; buf += `

${tour.title}

`; if (tour.image) { buf += ``; } buf += `

`; buf += import_lib.Utils.escapeHTML(tour.desc).replace(/\n/ig, "
"); buf += `

View information and signups`; try { checkCanEdit(user, this, categoryID); buf += `

Manage`; buf += ``; buf += `
`; } catch { } return renderPageChooser(query.join("-"), buf, user); }, section(query, user) { const categoryID = toID(query.shift()); if (!categoryID) { return error("", `No section specified.`, user); } this.title = "[Tournaments] " + categoryID; const category = tours[categoryID]; if (!category) { return error("", import_lib.Utils.html`Invalid section specified: '${categoryID}'`, user); } let buf = `${back()}${refresh(this.pageid)}

${category.title}

`; if (category.icon) { buf += `
`; } buf += `
${category.desc}
`; if (!category.tours.length) { buf += `

There are currently no tournaments in this section with open signups.

`; buf += `

Check back later for new tours.

`; } else { buf += category.tours.map((tour) => { let innerBuf = `
`; innerBuf += `${tour.title}
`; innerBuf += import_lib.Utils.escapeHTML(tour.shortDesc); innerBuf += `
`; return innerBuf; }).join("
"); } return renderPageChooser(categoryID, buf, user); }, start(query, user) { checkCanEdit(user, this); let buf = `${refresh(this.pageid)}
`; this.title = "[Tournaments] Add"; buf += `

Add new tournament


`; buf += `
`; let possibleCategory = Object.keys(tours)[0]; for (const k in tours) { if (tours[k].whitelist?.includes(user.id)) { possibleCategory = k; break; } } buf += `Title:
`; buf += `Category:
`; buf += `Info link:
`; buf += `Image link (optional):
`; buf += `Short description:

`; buf += `Full description:

`; buf += `
`; return renderPageChooser("start", buf, user); }, // edit single edit(query, user) { this.title = "[Tournaments] Edit "; const [sectionID, tourID] = query.map(toID); if (!sectionID || !tourID) { return Chat.resolvePage(`view-tournaments-manage`, user, this.connection); } const section = tours[sectionID]; if (!section) return error("edit", `Invalid section: "${sectionID}"`, user); const tour = section.tours.find((t) => t.id === tourID); if (!tour) return error("edit", `Tour with ID "${tourID}" not found.`, user); let buf = `${refresh(this.pageid)}

Edit tournament "${tour.title}"


`; buf += `
`; buf += `Title:
`; buf += `Info link:
`; buf += `Image link (optional):
`; buf += `Short description:
`; buf += `
`; const desc = import_lib.Utils.escapeHTML(tour.desc).replace(/
/g, " "); buf += `Full description:

`; buf += ``; return renderPageChooser("edit", buf, user); }, // panel for all you have perms to edit manage(query, user) { checkCanEdit(user, this); this.title = "[Tournaments] Manage"; let buf = `${refresh(this.pageid)}

Manage ongoing tournaments


`; buf += Object.keys(tours).map((cat) => { let innerBuf = ""; try { checkCanEdit(user, this, toID(cat)); } catch { return ""; } const section = tours[cat]; innerBuf += `${section.title}:
`; innerBuf += section.tours.map( (t) => `• ${t.title}` ).join("
") || "None active."; return innerBuf; }).filter(Boolean).join("
"); return renderPageChooser("manage", buf, user); }, whitelists(query, user) { this.checkCan("rangeban"); let buf = `${refresh(this.pageid)}

Section whitelists
`; for (const k in tours) { buf += `${tours[k].title}
`; const whitelist = tours[k].whitelist || []; if (!whitelist.length) { buf += `None.
`; continue; } buf += import_lib.Utils.sortBy(whitelist).map((f) => `
  • ${f}
  • `).join(""); buf += `
    `; } return renderPageChooser("whitelist", buf, user); } } }; process.nextTick(() => { Chat.multiLinePattern.register("/smogtours (add|edit)"); }); //# sourceMappingURL=smogtours.js.map