"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 permalocks_exports = {};
__export(permalocks_exports, {
Nominations: () => Nominations,
Smogon: () => Smogon,
commands: () => commands,
getIPData: () => getIPData,
pages: () => pages
});
module.exports = __toCommonJS(permalocks_exports);
var import_lib = require("../../lib");
function getIPData(ip) {
try {
return (0, import_lib.Net)("https://miapi.dev/api/ip/" + ip).get().then(JSON.parse);
} catch {
return null;
}
}
const Smogon = new class {
async post(threadNum, postText) {
if (!Config.smogon)
return null;
try {
const raw = await (0, import_lib.Net)(`https://www.smogon.com/forums/api/posts`).get({
method: "POST",
body: new URLSearchParams({
thread_id: threadNum,
message: postText
}).toString(),
headers: {
"XF-Api-Key": Config.smogon,
"Content-Type": "application/x-www-form-urlencoded"
}
});
const data = JSON.parse(raw);
if (data.errors?.length) {
const errData = data.errors.pop();
throw new Error(errData.message);
}
return data;
} catch (e) {
if (e.message.includes("Not Found")) {
throw new Error("WHO DELETED THE PERMA THREAD");
}
return { error: e.message };
}
}
}();
const Nominations = new class {
constructor() {
this.noms = [];
this.icons = {};
this.load();
}
load() {
try {
let data = JSON.parse((0, import_lib.FS)("config/chat-plugins/permas.json").readSync());
if (Array.isArray(data)) {
data = { noms: data, icons: {} };
(0, import_lib.FS)("config/chat-plugins/permas.json").writeSync(JSON.stringify(data));
}
this.noms = data.noms;
this.icons = data.icons;
} catch {
}
}
fetchModlog(id) {
return Rooms.Modlog.search("global", {
user: [{ search: id, isExact: true }],
note: [],
ip: [],
action: [],
actionTaker: []
}, void 0, true);
}
save() {
(0, import_lib.FS)("config/chat-plugins/permas.json").writeUpdate(() => JSON.stringify({ noms: this.noms, icons: this.icons }));
}
notifyStaff() {
const usRoom = Rooms.get("upperstaff");
if (!usRoom)
return;
usRoom.send(`|uhtml|permanoms|${this.getDisplayButton()}`);
Chat.refreshPageFor("permalocks", usRoom);
}
async add(target, connection) {
const user = connection.user;
const [primary, rawAlts, rawIps, type, details] = import_lib.Utils.splitFirst(target, "|", 4).map((f) => f.trim());
const primaryID = toID(primary);
const alts = rawAlts.split(",").map(toID).filter(Boolean);
const ips = rawIps.split(",").map((f) => f.trim()).filter(Boolean);
for (const ip of ips) {
if (!IPTools.ipRegex.test(ip))
this.error(`Invalid IP: ${ip}`, connection);
}
const standings = this.getStandings();
if (!standings[type]) {
this.error(`Invalid standing: ${type}.`, connection);
}
if (!details) {
this.error("Details must be provided. Explain why this user should be permalocked.", connection);
}
if (!primaryID) {
this.error("A primary username must be provided. Use one of their alts if necessary.", connection);
}
for (const nom of this.noms) {
if (nom.primaryID === primaryID) {
this.error(`'${primaryID}' was already nominated for permalock by ${nom.by}.`, connection);
}
}
const ipTable = new Set(ips);
const altTable = /* @__PURE__ */ new Set([...alts]);
for (const alt of [primaryID, ...alts]) {
const modlog = await this.fetchModlog(alt);
if (!modlog?.results.length)
continue;
for (const entry of modlog.results) {
if (entry.ip)
ipTable.add(entry.ip);
if (entry.autoconfirmedID)
altTable.add(entry.autoconfirmedID);
if (entry.alts) {
for (const id of entry.alts)
altTable.add(id);
}
}
}
altTable.delete(primaryID);
this.noms.push({
by: user.id,
alts: [...altTable],
ips: import_lib.Utils.sortBy([...ipTable], (z) => -(IPTools.ipToNumber(z) || Infinity)),
info: details,
primaryID,
standing: type,
date: Date.now()
});
import_lib.Utils.sortBy(this.noms, (nom) => -nom.date);
this.save();
this.notifyStaff();
Rooms.get("staff")?.addByUser(user, `${user.name} submitted a perma nomination for ${primaryID}`);
}
find(id) {
return this.noms.find((f) => f.primaryID === id);
}
error(message, conn) {
conn.popup(message);
throw new Chat.Interruption();
}
close(target, context) {
const entry = this.find(target);
if (!entry) {
this.error(`There is no nomination pending for '${toID(target)}'.`, context.connection);
}
this.noms.splice(this.noms.findIndex((f) => f.primaryID === entry.primaryID), 1);
this.save();
this.notifyStaff();
return context.closePage(`permalocks-view-${entry.primaryID}`);
}
display(nom, canEdit) {
let buf = `
`;
let title = nom.primaryID;
if (canEdit) {
title = `${nom.primaryID}`;
}
buf += `${title} (submitted by ${nom.by}) `;
buf += `Submitted ${Chat.toTimestamp(new Date(nom.date), { human: true })} `;
buf += `${Chat.count(nom.alts, "alts")}, ${Chat.count(nom.ips, "IPs")}`;
buf += `
`;
return buf;
}
displayModlog(results) {
if (!results)
return "";
let curDate = "";
return results.map((result) => {
const date = new Date(result.time || Date.now());
const entryRoom = result.visualRoomID || result.roomID || "global";
let [dateString, timestamp] = Chat.toTimestamp(date, { human: true }).split(" ");
let line = `[${timestamp}] (${entryRoom}) ${result.action}`;
if (result.userid) {
line += `: [${result.userid}]`;
if (result.autoconfirmedID)
line += ` ac: [${result.autoconfirmedID}]`;
if (result.alts.length)
line += ` alts: [${result.alts.join("], [")}]`;
if (result.ip)
line += ` [${result.ip}]`;
}
if (result.loggedBy)
line += `: by ${result.loggedBy}`;
if (result.note)
line += import_lib.Utils.html`: ${result.note}`;
if (dateString !== curDate) {
curDate = dateString;
dateString = `