@koishijs/plugin-market
Version:
Manage your bots and plugins with console
64 lines (62 loc) • 2.21 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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);
// src/shared/index.ts
var shared_exports = {};
__export(shared_exports, {
MarketProvider: () => MarketProvider
});
module.exports = __toCommonJS(shared_exports);
var import_koishi = require("koishi");
var import_console = require("@koishijs/console");
var logger = new import_koishi.Logger("market");
var MarketProvider = class extends import_console.DataService {
static {
__name(this, "MarketProvider");
}
_task;
_timestamp = 0;
_error;
constructor(ctx) {
super(ctx, "market", { authority: 4 });
ctx.console.addListener("market/refresh", () => this.start(true), { authority: 4 });
ctx.on("console/connection", async (client) => {
if (!ctx.console.clients[client.id]) return;
if (Date.now() - this._timestamp <= import_koishi.Time.hour * 12) return;
if (await this.ctx.serial("console/intercept", client, { authority: 4 })) return;
this.start();
});
}
start(refresh = false) {
this._task = null;
this._error = null;
this._timestamp = Date.now();
this.refresh();
}
async prepare() {
return this._task ||= this.collect().catch((error) => {
logger.warn(error);
this._error = error;
});
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MarketProvider
});
//# sourceMappingURL=index.js.map