"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 += `
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 += `
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 = `