@averagehelper/corde
Version:
A simple library for Discord bot tests. (Republished fork to demonstrate a bugfix)
104 lines (103 loc) • 3.03 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runtime = void 0;
const config_1 = require("./config");
const core_1 = require("../core");
const discord_js_1 = require("discord.js");
const errors_1 = require("../errors");
class Runtime {
constructor() {
this._configs = new config_1.Config();
}
get bot() {
return this._bot;
}
get configs() {
return this._configs;
}
get cordeTestToken() {
return this._configs.cordeTestToken;
}
get botTestId() {
return this._configs.botTestId;
}
get botTestToken() {
return this._configs.botTestToken;
}
get channelId() {
return this._configs.channelId;
}
get guildId() {
return this._configs.guildId;
}
get timeOut() {
return this._configs.timeOut;
}
get botPrefix() {
return this._configs.botPrefix;
}
get testFiles() {
return this._configs.testFiles;
}
set testFiles(path) {
this._configs.testFiles = path;
}
static getInstance() {
if (!Runtime._instance) {
Runtime._instance = new Runtime();
}
return Runtime._instance;
}
setConfigs(_configs) {
if (!_configs) {
throw new errors_1.ConfigError("Invalid _configs");
}
this._configs.setNoFiledConfigsOptions(_configs);
this.loadBot();
}
/**
* Shortcut for *bot.isLoggedIn*
*/
isBotLoggedIn() {
return this._bot && this._bot.isLoggedIn();
}
/**
* Shortcut for *bot.logout*
*/
logoffBot() {
if (this._bot) {
this._bot.logout();
}
}
/**
* Shortcut for *bot.onStart*
*/
onBotStart() {
return this._bot.onStart;
}
loginBot(token) {
return __awaiter(this, void 0, void 0, function* () {
return yield this._bot.login(token);
});
}
injectBot(fn) {
return fn(this._bot);
}
loadBot() {
this._bot = new core_1.CordeBot(this._configs.botPrefix, this._configs.guildId, this._configs.channelId, this._configs.timeOut, this._configs.botTestId, new discord_js_1.Client());
}
}
/**
* Singleton of Runtime.
*/
const runtime = Runtime.getInstance();
exports.runtime = runtime;