msg.ts
Version:
MSG is the framework for make discord bot easily
63 lines • 2.18 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ContextHeader_1 = __importDefault(require("./ContextHeader"));
const Bot_1 = __importDefault(require("./Bot"));
function currentUpdate(ctx) {
ctx.header.currentCommand =
ctx.ex?.args?.[ctx.header.getDepth() - 1] ?? null;
ctx.ex.currentArgs = ctx.ex?.args?.slice(ctx.header.getDepth());
return ctx;
}
class Context {
constructor(msg) {
this.msg = msg;
this.header = new ContextHeader_1.default();
this.ex = {};
this.bot = msg.client;
}
copy() {
const newCtx = new Context(this.msg);
newCtx.ex = { ...this.ex };
const copiedHeader = new ContextHeader_1.default({
depth: this.header.getDepth(),
});
if (this.header.getIsFinished())
copiedHeader.setFinish();
if (this.header.getIsHit())
copiedHeader.setHit();
copiedHeader.currentCommand = this.header.currentCommand;
if (this.header.getHitCommand() !== null)
copiedHeader.setHitCommand(this.header.getHitCommand());
newCtx.header = copiedHeader;
return newCtx;
}
copyAndIncrease() {
const ctxCopy = this.copy();
ctxCopy.header.increaseDepth();
return currentUpdate(ctxCopy);
}
copyAndDiminish() {
const ctxCopy = this.copy();
ctxCopy.header.diminishDepth();
return currentUpdate(ctxCopy);
}
send(content) {
return this?.msg?.channel?.send(content || '[Empty]');
}
reply(content) {
return this?.msg?.reply(content);
}
finish() {
this.header.setFinish();
if (this.bot instanceof Bot_1.default) {
this.bot.emit('finish', this);
}
return this;
}
}
Context.copy = (originalCtx) => Context.prototype.copy.call(originalCtx);
exports.default = Context;
//# sourceMappingURL=../../src/dist/class/Context.js.map