procs
parent
7fe1516ef8
commit
6a3bf66f28
|
@ -1,147 +1,148 @@
|
||||||
import Stripe from 'stripe';
|
import Stripe from 'stripe';
|
||||||
import eris from 'eris';
|
import eris from 'eris';
|
||||||
import pluris from 'pluris';
|
import pluris from 'pluris';
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { Collection, Command, LocalStorage, Queue, Util, ServerManagement, Event } from '.';
|
import { Collection, Command, LocalStorage, Queue, Util, ServerManagement, Event } from '.';
|
||||||
import {
|
import {
|
||||||
Customer, CustomerInterface,
|
Customer, CustomerInterface,
|
||||||
CustomerPortal, CustomerPortalInterface,
|
CustomerPortal, CustomerPortalInterface,
|
||||||
ExecutiveOrder, ExecutiveOrderInterface,
|
ExecutiveOrder, ExecutiveOrderInterface,
|
||||||
File, FileInterface,
|
File, FileInterface,
|
||||||
Member, MemberInterface,
|
Member, MemberInterface,
|
||||||
Merchant, MerchantInterface,
|
Merchant, MerchantInterface,
|
||||||
Moderation, ModerationInterface,
|
Moderation, ModerationInterface,
|
||||||
Motion, MotionInterface,
|
Motion, MotionInterface,
|
||||||
NNTrainingData, NNTrainingDataInterface,
|
NNTrainingData, NNTrainingDataInterface,
|
||||||
Note, NoteInterface,
|
Note, NoteInterface,
|
||||||
PagerNumber, PagerNumberInterface,
|
PagerNumber, PagerNumberInterface,
|
||||||
Promo, PromoInterface,
|
Proclamation, ProclamationInterface,
|
||||||
Rank, RankInterface,
|
Promo, PromoInterface,
|
||||||
Redirect, RedirectInterface,
|
Rank, RankInterface,
|
||||||
Resolution, ResolutionInterface,
|
Redirect, RedirectInterface,
|
||||||
Score, ScoreInterface,
|
Resolution, ResolutionInterface,
|
||||||
ScoreHistorical, ScoreHistoricalInterface,
|
Score, ScoreInterface,
|
||||||
Staff, StaffInterface,
|
ScoreHistorical, ScoreHistoricalInterface,
|
||||||
Stat, StatInterface,
|
Staff, StaffInterface,
|
||||||
} from '../models';
|
Stat, StatInterface,
|
||||||
import { Config } from '../../types'; // eslint-disable-line
|
} from '../models';
|
||||||
|
import { Config } from '../../types'; // eslint-disable-line
|
||||||
pluris(eris);
|
|
||||||
|
pluris(eris);
|
||||||
export default class Client extends eris.Client {
|
|
||||||
public config: Config;
|
export default class Client extends eris.Client {
|
||||||
|
public config: Config;
|
||||||
public commands: Collection<Command>;
|
|
||||||
|
public commands: Collection<Command>;
|
||||||
public events: Collection<Event>;
|
|
||||||
|
public events: Collection<Event>;
|
||||||
public intervals: Collection<NodeJS.Timeout>;
|
|
||||||
|
public intervals: Collection<NodeJS.Timeout>;
|
||||||
public util: Util;
|
|
||||||
|
public util: Util;
|
||||||
public serverManagement: ServerManagement;
|
|
||||||
|
public serverManagement: ServerManagement;
|
||||||
public queue: Queue;
|
|
||||||
|
public queue: Queue;
|
||||||
public stripe: Stripe;
|
|
||||||
|
public stripe: Stripe;
|
||||||
public db: {
|
|
||||||
Customer: mongoose.Model<CustomerInterface>,
|
public db: {
|
||||||
CustomerPortal: mongoose.Model<CustomerPortalInterface>,
|
Customer: mongoose.Model<CustomerInterface>,
|
||||||
ExecutiveOrder: mongoose.Model<ExecutiveOrderInterface>,
|
CustomerPortal: mongoose.Model<CustomerPortalInterface>,
|
||||||
File: mongoose.Model<FileInterface>,
|
ExecutiveOrder: mongoose.Model<ExecutiveOrderInterface>,
|
||||||
Member: mongoose.Model<MemberInterface>,
|
File: mongoose.Model<FileInterface>,
|
||||||
Merchant: mongoose.Model<MerchantInterface>,
|
Member: mongoose.Model<MemberInterface>,
|
||||||
Moderation: mongoose.Model<ModerationInterface>,
|
Merchant: mongoose.Model<MerchantInterface>,
|
||||||
Motion: mongoose.Model<MotionInterface>,
|
Moderation: mongoose.Model<ModerationInterface>,
|
||||||
NNTrainingData: mongoose.Model<NNTrainingDataInterface>,
|
Motion: mongoose.Model<MotionInterface>,
|
||||||
Note: mongoose.Model<NoteInterface>,
|
NNTrainingData: mongoose.Model<NNTrainingDataInterface>,
|
||||||
PagerNumber: mongoose.Model<PagerNumberInterface>,
|
Note: mongoose.Model<NoteInterface>,
|
||||||
Promo: mongoose.Model<PromoInterface>,
|
PagerNumber: mongoose.Model<PagerNumberInterface>,
|
||||||
Rank: mongoose.Model<RankInterface>,
|
Promo: mongoose.Model<PromoInterface>,
|
||||||
Redirect: mongoose.Model<RedirectInterface>,
|
Rank: mongoose.Model<RankInterface>,
|
||||||
Resolution: mongoose.Model<ResolutionInterface>,
|
Redirect: mongoose.Model<RedirectInterface>,
|
||||||
Score: mongoose.Model<ScoreInterface>,
|
Resolution: mongoose.Model<ResolutionInterface>,
|
||||||
ScoreHistorical: mongoose.Model<ScoreHistoricalInterface>,
|
Score: mongoose.Model<ScoreInterface>,
|
||||||
Staff: mongoose.Model<StaffInterface>,
|
ScoreHistorical: mongoose.Model<ScoreHistoricalInterface>,
|
||||||
Stat: mongoose.Model<StatInterface>,
|
Staff: mongoose.Model<StaffInterface>,
|
||||||
local: { muted: LocalStorage }
|
Stat: mongoose.Model<StatInterface>,
|
||||||
};
|
local: { muted: LocalStorage }
|
||||||
|
};
|
||||||
constructor(token: string, options?: eris.ClientOptions) {
|
|
||||||
super(token, options);
|
constructor(token: string, options?: eris.ClientOptions) {
|
||||||
this.commands = new Collection<Command>();
|
super(token, options);
|
||||||
this.events = new Collection<Event>();
|
this.commands = new Collection<Command>();
|
||||||
this.intervals = new Collection<NodeJS.Timeout>();
|
this.events = new Collection<Event>();
|
||||||
this.queue = new Queue(this);
|
this.intervals = new Collection<NodeJS.Timeout>();
|
||||||
this.db = { Customer, CustomerPortal, ExecutiveOrder, File, Member, Merchant, Moderation, Motion, NNTrainingData, Note, PagerNumber, Promo, Rank, Redirect, Resolution, Score, ScoreHistorical, Staff, Stat, local: { muted: new LocalStorage('muted') } };
|
this.queue = new Queue(this);
|
||||||
}
|
this.db = { Customer, CustomerPortal, ExecutiveOrder, File, Member, Merchant, Moderation, Motion, NNTrainingData, Note, PagerNumber, Promo, Rank, Redirect, Resolution, Score, ScoreHistorical, Staff, Stat, local: { muted: new LocalStorage('muted') } };
|
||||||
|
}
|
||||||
public async loadDatabase() {
|
|
||||||
await mongoose.connect(this.config.mongoDB, { useNewUrlParser: true, useUnifiedTopology: true, poolSize: 50 });
|
public async loadDatabase() {
|
||||||
|
await mongoose.connect(this.config.mongoDB, { useNewUrlParser: true, useUnifiedTopology: true, poolSize: 50 });
|
||||||
const statMessages = await this.db.Stat.findOne({ name: 'messages' });
|
|
||||||
const statCommands = await this.db.Stat.findOne({ name: 'commands' });
|
const statMessages = await this.db.Stat.findOne({ name: 'messages' });
|
||||||
const statPages = await this.db.Stat.findOne({ name: 'pages' });
|
const statCommands = await this.db.Stat.findOne({ name: 'commands' });
|
||||||
const statRequests = await this.db.Stat.findOne({ name: 'requests' });
|
const statPages = await this.db.Stat.findOne({ name: 'pages' });
|
||||||
|
const statRequests = await this.db.Stat.findOne({ name: 'requests' });
|
||||||
if (!statMessages) {
|
|
||||||
await (new this.db.Stat({ name: 'messages', value: 0 }).save());
|
if (!statMessages) {
|
||||||
}
|
await (new this.db.Stat({ name: 'messages', value: 0 }).save());
|
||||||
if (!statCommands) {
|
}
|
||||||
await (new this.db.Stat({ name: 'commands', value: 0 }).save());
|
if (!statCommands) {
|
||||||
}
|
await (new this.db.Stat({ name: 'commands', value: 0 }).save());
|
||||||
if (!statPages) {
|
}
|
||||||
await (new this.db.Stat({ name: 'pages', value: 0 }).save());
|
if (!statPages) {
|
||||||
}
|
await (new this.db.Stat({ name: 'pages', value: 0 }).save());
|
||||||
if (!statRequests) {
|
}
|
||||||
await (new this.db.Stat({ name: 'requests', value: 0 }).save());
|
if (!statRequests) {
|
||||||
}
|
await (new this.db.Stat({ name: 'requests', value: 0 }).save());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public loadPlugins() {
|
|
||||||
this.util = new Util(this);
|
public loadPlugins() {
|
||||||
this.serverManagement = new ServerManagement(this);
|
this.util = new Util(this);
|
||||||
this.stripe = new Stripe(this.config.stripeKey, { apiVersion: null, typescript: true });
|
this.serverManagement = new ServerManagement(this);
|
||||||
}
|
this.stripe = new Stripe(this.config.stripeKey, { apiVersion: null, typescript: true });
|
||||||
|
}
|
||||||
public async loadIntervals() {
|
|
||||||
const intervalFiles = await fs.readdir(`${__dirname}/../intervals`);
|
public async loadIntervals() {
|
||||||
intervalFiles.forEach((file) => {
|
const intervalFiles = await fs.readdir(`${__dirname}/../intervals`);
|
||||||
const intervalName = file.split('.')[0];
|
intervalFiles.forEach((file) => {
|
||||||
if (file === 'index.js') return;
|
const intervalName = file.split('.')[0];
|
||||||
const interval: NodeJS.Timeout = (require(`${__dirname}/../intervals/${file}`).default)(this);
|
if (file === 'index.js') return;
|
||||||
this.intervals.add(intervalName, interval);
|
const interval: NodeJS.Timeout = (require(`${__dirname}/../intervals/${file}`).default)(this);
|
||||||
this.util.signale.success(`Successfully loaded interval: ${intervalName}`);
|
this.intervals.add(intervalName, interval);
|
||||||
});
|
this.util.signale.success(`Successfully loaded interval: ${intervalName}`);
|
||||||
}
|
});
|
||||||
|
}
|
||||||
public async loadEvents(eventFiles: { [s: string]: typeof Event; } | ArrayLike<typeof Event>) {
|
|
||||||
const evtFiles = Object.entries<typeof Event>(eventFiles);
|
public async loadEvents(eventFiles: { [s: string]: typeof Event; } | ArrayLike<typeof Event>) {
|
||||||
for (const [name, Ev] of evtFiles) {
|
const evtFiles = Object.entries<typeof Event>(eventFiles);
|
||||||
const event = new Ev(this);
|
for (const [name, Ev] of evtFiles) {
|
||||||
this.events.add(event.event, event);
|
const event = new Ev(this);
|
||||||
this.on(event.event, event.run);
|
this.events.add(event.event, event);
|
||||||
this.util.signale.success(`Successfully loaded event: ${name}`);
|
this.on(event.event, event.run);
|
||||||
delete require.cache[require.resolve(`${__dirname}/../events/${name}`)];
|
this.util.signale.success(`Successfully loaded event: ${name}`);
|
||||||
}
|
delete require.cache[require.resolve(`${__dirname}/../events/${name}`)];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public async loadCommands(commandFiles: { [s: string]: typeof Command; } | ArrayLike<typeof Command>) {
|
|
||||||
const cmdFiles = Object.values<typeof Command>(commandFiles);
|
public async loadCommands(commandFiles: { [s: string]: typeof Command; } | ArrayLike<typeof Command>) {
|
||||||
for (const Cmd of cmdFiles) {
|
const cmdFiles = Object.values<typeof Command>(commandFiles);
|
||||||
const command = new Cmd(this);
|
for (const Cmd of cmdFiles) {
|
||||||
if (command.subcmds.length) {
|
const command = new Cmd(this);
|
||||||
command.subcmds.forEach((C) => {
|
if (command.subcmds.length) {
|
||||||
const cmd: Command = new C(this);
|
command.subcmds.forEach((C) => {
|
||||||
command.subcommands.add(cmd.name, cmd);
|
const cmd: Command = new C(this);
|
||||||
this.util.signale.success(`Successfully loaded subcommand ${cmd.name} under ${command.name}`);
|
command.subcommands.add(cmd.name, cmd);
|
||||||
});
|
this.util.signale.success(`Successfully loaded subcommand ${cmd.name} under ${command.name}`);
|
||||||
}
|
});
|
||||||
delete command.subcmds;
|
}
|
||||||
this.commands.add(command.name, command);
|
delete command.subcmds;
|
||||||
this.util.signale.success(`Successfully loaded command: ${command.name}`);
|
this.commands.add(command.name, command);
|
||||||
}
|
this.util.signale.success(`Successfully loaded command: ${command.name}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue