1
0
Fork 0

rewrite everything x2

refactor/models
Matthew 2020-06-29 02:50:26 -04:00
parent 89b8f0b9c9
commit cbb5c1585a
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
57 changed files with 60 additions and 438 deletions

View File

@ -1,138 +0,0 @@
import Eris from 'eris';
import Redis from 'ioredis';
import mongoose from 'mongoose';
import signale from 'signale';
import fs from 'fs-extra';
import config from './config.json';
import CSCLI from './cscli/main';
import { Server } from './api';
import { Account, AccountInterface, Moderation, ModerationInterface, Domain, DomainInterface, Tier, TierInterface } from './models';
import { emojis } from './stores';
import { Command, Util, Collection } from './class';
import * as commands from './commands';
export default class Client extends Eris.Client {
public config: { 'token': string; 'cloudflare': string; 'prefix': string; 'emailPass': string; 'mongoURL': string; 'port': number; 'keyPair': { 'publicKey': string; 'privateKey': string; }; };
public util: Util;
public commands: Collection<Command>;
public db: { Account: mongoose.Model<AccountInterface>; Domain: mongoose.Model<DomainInterface>; Moderation: mongoose.Model<ModerationInterface>; Tier: mongoose.Model<TierInterface>; };
public redis: Redis.Redis;
public stores: { emojis: { success: string, loading: string, error: string }; };
public functions: Collection<Function>;
public signale: signale.Signale;
public server: Server;
public updating: boolean;
public buildError: boolean
constructor() {
super(config.token, { getAllUsers: true, restMode: true, defaultImageFormat: 'png' });
process.title = 'cloudservices';
this.config = config;
this.util = new Util(this);
this.commands = new Collection<Command>();
this.functions = new Collection<Function>();
this.db = { Account, Domain, Moderation, Tier };
this.redis = new Redis();
this.stores = { emojis };
this.signale = signale;
this.signale.config({
displayDate: true,
displayTimestamp: true,
displayFilename: true,
});
this.updating = false;
this.buildError = false;
this.events();
this.loadFunctions();
this.init();
}
private async events() {
process.on('unhandledRejection', (error) => {
this.signale.error(error);
});
}
private async loadFunctions() {
const functions = await fs.readdir('./functions');
functions.forEach(async (func) => {
if (func === 'index.ts' || func === 'index.js') return;
try {
const funcRequire: Function = require(`./functions/${func}`).default;
this.functions.set(func.split('.')[0], funcRequire);
} catch (error) {
this.signale.error(`Error occured loading ${func}`);
await this.util.handleError(error);
}
});
}
public loadCommand(CommandFile: any) {
// eslint-disable-next-line no-useless-catch
try {
// eslint-disable-next-line
const command: Command = new CommandFile(this);
if (command.subcmds.length) {
command.subcmds.forEach((C) => {
const cmd: Command = new C(this);
command.subcommands.add(cmd.name, cmd);
});
}
delete command.subcmds;
this.commands.add(command.name, command);
this.signale.complete(`Loaded command ${command.name}`);
} catch (err) { throw err; }
}
public async init() {
const evtFiles = await fs.readdir('./events/');
Object.values(commands).forEach((c: Function) => this.loadCommand(c));
evtFiles.forEach((file) => {
const eventName = file.split('.')[0];
if (file === 'index.js') return;
// eslint-disable-next-line
const event = new (require(`./events/${file}`).default)(this);
this.signale.complete(`Loaded event ${eventName}`);
this.on(eventName, (...args) => event.run(...args));
delete require.cache[require.resolve(`./events/${file}`)];
});
await mongoose.connect(config.mongoURL, { useNewUrlParser: true, useUnifiedTopology: true });
await this.connect();
this.on('ready', () => {
this.signale.info(`Connected to Discord as ${this.user.username}#${this.user.discriminator}`);
});
const intervals = await fs.readdir('./intervals');
intervals.forEach((interval) => {
// eslint-disable-next-line
if (interval === 'index.js') return;
require(`./intervals/${interval}`).default(this);
this.signale.complete(`Loaded interval ${interval.split('.')[0]}`);
});
this.server = new Server(this, { port: this.config.port });
// eslint-disable-next-line no-new
new CSCLI(this);
const corepath = '/opt/CloudServices/dist';
const cmdFiles = await fs.readdir('/opt/CloudServices/dist/commands');
cmdFiles.forEach((f) => delete require.cache[`${corepath}/${f}`]);
delete require.cache[`${corepath}/config.json`];
delete require.cache[`${corepath}/class/Util`];
}
}
// eslint-disable-next-line
new Client();

View File

@ -1,77 +0,0 @@
/* eslint-disable no-underscore-dangle */
import crypto from 'crypto';
import { Request } from 'express';
import { Client } from '..';
import { AccountInterface } from '../models';
export default class Security {
public client: Client;
protected readonly keyBase: { key: string, iv: string };
constructor(client: Client) {
this.client = client;
this.keyBase = require(`${process.cwd()}/keys.json`);
}
get keys() {
return {
key: Buffer.from(this.keyBase.key, 'base64'),
iv: Buffer.from(this.keyBase.iv, 'base64'),
};
}
/**
* Creates a new Bearer token.
* @param _id The Mongoose Document property labeled ._id
*/
public async createBearer(_id: string): Promise<string> {
let account = await this.client.db.Account.findOne({ _id });
if (!account) throw new Error(`Account [${_id}] cannot be found.`);
const salt = crypto.randomBytes(50).toString('base64');
const cipher = crypto.createCipheriv('aes-256-gcm', this.keys.key, this.keys.iv);
await account.updateOne({ salt });
account = await this.client.db.Account.findOne({ _id });
let encrypted = cipher.update(JSON.stringify(account), 'utf8', 'base64');
encrypted += cipher.final('base64');
await account.updateOne({ authTag: cipher.getAuthTag() });
return `${salt}:${encrypted}`;
}
/**
* If the bearer token is valid, will return the Account, else will return null.
* @param bearer The bearer token provided.
*/
public async checkBearer(bearer: string): Promise<null | AccountInterface> {
const decipher = crypto.createDecipheriv('aes-256-gcm', this.keys.key, this.keys.iv);
try {
const salt = bearer.split(':')[0];
const saltCheck = await this.client.db.Account.findOne({ salt });
const encrypted = bearer.split(':')[1];
let decrypted = decipher.update(encrypted, 'base64', 'utf8');
decipher.setAuthTag(saltCheck.authTag);
decrypted += decipher.final('utf8');
const json = JSON.parse(decrypted);
const account = await this.client.db.Account.findOne({ username: json.username });
if (saltCheck.salt !== account.salt) return null;
return account;
} catch (error) {
this.client.util.handleError(error);
return null;
}
}
/**
* Returns the Bearer token, searches in headers and query.
* @param req The Request object from Express.
*/
public extractBearer(req: Request): string {
if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
return req.headers.authorization.split(' ')[1];
}
if (req.query && req.query.token) {
return req.query.token as string;
}
return '0000000000';
}
}

View File

@ -1,70 +0,0 @@
/* eslint-disable no-useless-return */
import express from 'express';
import bodyParser from 'body-parser';
import helmet from 'helmet';
import fs from 'fs-extra';
import { Client } from '..';
import { Security } from '.';
import { Collection, Route } from '../class';
export default class Server {
public routes: Collection<Route>
public client: Client;
public security: Security;
public app: express.Express;
public options: { port: number }
constructor(client: Client, options?: { port: number }) {
this.options = options;
this.routes = new Collection();
this.client = client;
this.security = new Security(this.client);
this.app = express();
this.connect();
this.loadRoutes();
}
private async loadRoutes(): Promise<void> {
const routes = await fs.readdir(`${__dirname}/routes`);
routes.forEach(async (routeFile) => {
if (routeFile === 'index.js') return;
try {
// eslint-disable-next-line new-cap
const route: Route = new (require(`${__dirname}/routes/${routeFile}`).default)(this);
if (route.conf.deprecated === true) {
route.deprecated();
} else if (route.conf.maintenance === true) {
route.maintenance();
} else {
route.bind();
}
this.routes.set(route.conf.path, route);
this.app.use(route.conf.path, route.router);
this.client.signale.success(`Successfully loaded route ${route.conf.path}`);
} catch (error) {
this.client.util.handleError(error);
}
});
}
private connect(): void {
this.app.set('trust proxy', 'loopback');
this.app.use(helmet({
hsts: false,
hidePoweredBy: false,
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
},
},
}));
this.app.use(bodyParser.json());
this.app.listen(this.options.port, () => {
this.client.signale.success(`API Server listening on port ${this.options.port}`);
});
}
}

View File

@ -66,11 +66,11 @@ export default class Client extends Eris.Client {
}
private async loadFunctions() {
const functions = await fs.readdir('./functions');
const functions = await fs.readdir('../functions');
functions.forEach(async (func) => {
if (func === 'index.ts' || func === 'index.js') return;
try {
const funcRequire: Function = require(`./functions/${func}`).default;
const funcRequire: Function = require(`../functions/${func}`).default;
this.functions.set(func.split('.')[0], funcRequire);
} catch (error) {
this.signale.error(`Error occured loading ${func}`);
@ -97,17 +97,17 @@ export default class Client extends Eris.Client {
}
public async init() {
const evtFiles = await fs.readdir('./events/');
const evtFiles = await fs.readdir('../events/');
Object.values(commands).forEach((c: Function) => this.loadCommand(c));
evtFiles.forEach((file) => {
const eventName = file.split('.')[0];
if (file === 'index.js') return;
// eslint-disable-next-line
const event = new (require(`./events/${file}`).default)(this);
const event = new (require(`../events/${file}`).default)(this);
this.signale.complete(`Loaded event ${eventName}`);
this.on(eventName, (...args) => event.run(...args));
delete require.cache[require.resolve(`./events/${file}`)];
delete require.cache[require.resolve(`../events/${file}`)];
});
await mongoose.connect(config.mongoURL, { useNewUrlParser: true, useUnifiedTopology: true });
@ -115,11 +115,11 @@ export default class Client extends Eris.Client {
this.on('ready', () => {
this.signale.info(`Connected to Discord as ${this.user.username}#${this.user.discriminator}`);
});
const intervals = await fs.readdir('./intervals');
const intervals = await fs.readdir('../intervals');
intervals.forEach((interval) => {
// eslint-disable-next-line
if (interval === 'index.js') return;
require(`./intervals/${interval}`).default(this);
require(`../intervals/${interval}`).default(this);
this.signale.complete(`Loaded interval ${interval.split('.')[0]}`);
});
this.server = new Server(this, { port: this.config.port });

View File

@ -1,6 +1,5 @@
import { Message, TextableChannel, Textable } from 'eris';
import { Client } from '..';
import { Collection } from '.';
import { Message, TextableChannel } from 'eris';
import { Client, Collection } from '.';
export default class Command {
name: string

View File

@ -1,6 +1,6 @@
/* eslint-disable consistent-return */
import { Request, Response, NextFunction, Router as router } from 'express';
import { Server } from '../api';
import { Server } from '.';
export default class Route {
public server: Server;

View File

@ -1,7 +1,7 @@
/* eslint-disable no-underscore-dangle */
import crypto from 'crypto';
import { Request } from 'express';
import { Client } from '..';
import { Client } from '.';
import { AccountInterface } from '../models';
export default class Security {

View File

@ -3,9 +3,9 @@ import express from 'express';
import bodyParser from 'body-parser';
import helmet from 'helmet';
import fs from 'fs-extra';
import { Client } from '..';
import { Client, Collection, Route } from '.';
import { Security } from '../api';
import { Collection, Route } from '.';
export default class Server {
public routes: Collection<Route>

View File

@ -7,9 +7,8 @@ import { Message, PrivateChannel, GroupChannel, Member, User } from 'eris';
import uuid from 'uuid/v4';
import moment from 'moment';
import fs from 'fs';
import { Client } from '..';
import { getUserByUid } from '../functions';
import { AccountUtil, Command, RichEmbed } from '.';
import { AccountUtil, Client, Command, RichEmbed } from '.';
import { ModerationInterface, AccountInterface, Account } from '../models';
export default class Util {

View File

@ -4,4 +4,6 @@ export { default as Collection } from './Collection';
export { default as Command } from './Command';
export { default as RichEmbed } from './RichEmbed';
export { default as Route } from './Route';
export { default as Security } from './Security';
export { default as Server } from './Server';
export { default as Util } from './Util';

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Announce extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Command } from '../class';
import { Client } from '..';
import { Client, Command } from '../class';
export default class Bearer extends Command {
constructor(client: Client) {

View File

@ -1,7 +1,6 @@
import axios from 'axios';
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Cloudflare extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message, PrivateChannel, GroupChannel } from 'eris';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
import { Client, Command } from '../class';
export default class CreateAccount extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Command } from '../class';
import { Client } from '..';
import { Client, Command } from '../class';
import Create from './cwg_create';
import Data from './cwg_data';
import Delete from './cwg_delete';

View File

@ -3,8 +3,7 @@ import axios from 'axios';
import { randomBytes } from 'crypto';
import { Message } from 'eris';
import { AccountInterface } from '../models';
import { Command, RichEmbed } from '../class';
import { Client } from '..';
import { Client, Command, RichEmbed } from '../class';
import { parseCertificate } from '../functions';
export default class CWG_Create extends Command {

View File

@ -3,8 +3,7 @@ import moment from 'moment';
import x509 from '@ghaiklor/x509';
import { createPaginationEmbed } from 'eris-pagination';
import { Message } from 'eris';
import { Command, RichEmbed } from '../class';
import { Client } from '..';
import { Client, Command, RichEmbed } from '../class';
export default class CWG_Data extends Command {
constructor(client: Client) {

View File

@ -1,8 +1,7 @@
import fs from 'fs-extra';
import axios from 'axios';
import { Message } from 'eris';
import { Command, RichEmbed } from '../class';
import { Client } from '..';
import { Client, Command, RichEmbed } from '../class';
export default class CWG_Delete extends Command {
constructor(client: Client) {

View File

@ -1,8 +1,7 @@
import { writeFile, unlink } from 'fs-extra';
import axios from 'axios';
import { Message } from 'eris';
import { Command } from '../class';
import { Client } from '..';
import { Client, Command } from '../class';
export default class CWG_UpdateCert extends Command {
constructor(client: Client) {

View File

@ -1,7 +1,6 @@
import { Message, PrivateChannel } from 'eris';
import uuid from 'uuid/v4';
import { Command } from '../class';
import { Client } from '..';
import { Client, Command } from '../class';
export default class DeleteAccount extends Command {
constructor(client: Client) {

View File

@ -1,7 +1,6 @@
import { randomBytes } from 'crypto';
import { Message } from 'eris';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
import { Client, Command } from '../class';
export default class EmailCode extends Command {
constructor(client: Client) {

View File

@ -2,8 +2,7 @@
import axios from 'axios';
import { Message } from 'eris';
import { inspect } from 'util';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Eval extends Command {
constructor(client: Client) {

View File

@ -1,7 +1,6 @@
import { Message } from 'eris';
import axios from 'axios';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Exec extends Command {
constructor(client: Client) {

View File

@ -1,7 +1,6 @@
import { Message } from 'eris';
import { createPaginationEmbed } from 'eris-pagination';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
import { Client, Command, RichEmbed } from '../class';
export default class Help extends Command {
constructor(client: Client) {

View File

@ -4,7 +4,6 @@ export { default as cloudflare } from './cloudflare';
export { default as createaccount } from './createaccount';
export { default as cwg } from './cwg';
export { default as deleteaccount } from './deleteaccount';
export { default as disk } from './disk';
export { default as emailcode } from './emailcode';
export { default as eval } from './eval';
export { default as exec } from './exec';
@ -14,13 +13,10 @@ export { default as load } from './load';
export { default as lock } from './lock';
export { default as modlogs } from './modlogs';
export { default as notify } from './notify';
export { default as parse } from './parse';
export { default as parseall } from './parseall';
export { default as ping } from './ping';
export { default as pull } from './pull';
export { default as resetpassword } from './resetpassword';
export { default as restart } from './restart';
export { default as securesign } from './securesign';
export { default as setlimit } from './setlimit';
export { default as sysinfo } from './sysinfo';
export { default as systemd } from './systemd';
@ -29,4 +25,3 @@ export { default as unban } from './unban';
export { default as unlock } from './unlock';
export { default as warn } from './warn';
export { default as whois } from './whois';
export { default as whoisold } from './whoisold';

View File

@ -1,8 +1,7 @@
import { Message } from 'eris';
import { Command, RichEmbed } from '../class';
import { Client, Command, RichEmbed } from '../class';
import { dataConversion } from '../functions';
import setRamNotification from './limits_setramnotification';
import { Client } from '..';
export default class Limits extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Command, RichEmbed } from '../class';
import { Client } from '..';
import { Client, Command } from '../class';
export default class Limits_SetRAMNotification extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Load extends Command {
constructor(client: Client) {

View File

@ -1,7 +1,6 @@
import moment, { unitOfTime } from 'moment';
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Lock extends Command {
constructor(client: Client) {

View File

@ -1,7 +1,6 @@
import { Message } from 'eris';
import { createPaginationEmbed } from 'eris-pagination';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
import { Client, Command, RichEmbed } from '../class';
export default class Modlogs extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
import { Client, Command, RichEmbed } from '../class';
export default class Notify extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Ping extends Command {
constructor(client: Client) {

View File

@ -1,7 +1,6 @@
import { Message } from 'eris';
import axios from 'axios';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Pull extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class ResetPassword extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Restart extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Command } from '../class';
import { Client } from '..';
import { Client, Command } from '../class';
import SetLimit_RAM from './setlimit_ram';
export default class SetLimit extends Command {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Command } from '../class';
import { Client } from '..';
import { Client, Command } from '../class';
export default class SetLimit_RAM extends Command {
constructor(client: Client) {

View File

@ -1,9 +1,8 @@
import moment from 'moment';
import { Message } from 'eris';
import os, { totalmem } from 'os';
import { Command, RichEmbed } from '../class';
import { Client, Command, RichEmbed } from '../class';
import { dataConversion } from '../functions';
import { Client } from '..';
export default class SysInfo extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Command } from '../class';
import { Client } from '..';
import { Client, Command } from '../class';
import SystemD_Linger from './systemd_linger';
export default class SystemD extends Command {

View File

@ -1,7 +1,6 @@
/* eslint-disable consistent-return */
import { Message } from 'eris';
import { Command } from '../class';
import { Client } from '..';
import { Client, Command } from '../class';
export default class SystemdD_Linger extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
import { Client, Command, RichEmbed } from '../class';
export default class Tier extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Unban extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Unlock extends Command {
constructor(client: Client) {

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
import { Client, Command } from '../class';
export default class Warn extends Command {
constructor(client: Client) {

View File

@ -1,7 +1,6 @@
import moment from 'moment';
import { Message, GuildTextableChannel, Member, Role } from 'eris';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
import { Client, Command, RichEmbed } from '../class';
import { dataConversion } from '../functions';
import { AccountInterface } from '../models';

View File

@ -3,7 +3,7 @@
import net from 'net';
import crypto from 'crypto';
import { promises as fs } from 'fs';
import Client from '../Client';
import Client from '../class/Client';
import { dataConversion } from '../functions';
export default class CSCLI {

View File

@ -1,6 +1,5 @@
import { Message, TextChannel } from 'eris';
import { Client } from '..';
import Command from '../class/Command';
import { Client } from '../class';
export default class {
public client: Client
@ -25,7 +24,6 @@ export default class {
if (resolved.cmd.permissions.roles) {
for (const role of resolved.cmd.permissions.roles) {
if (message.member && message.member.roles.includes(role)) {
// this.client.signale.debug(message.member.roles.includes(role));
hasRolePerms = true; break;
}
}

View File

@ -1,5 +1,5 @@
/* eslint-disable no-await-in-loop */
import { Client } from '..';
import { Client } from '../class';
export default async function existingLimitsSetup(client: Client): Promise<number> {
const tier1 = await client.db.Tier.findOne({ id: 1 });

View File

@ -1,4 +1,4 @@
import { Client } from '..';
import { Client } from '../class';
export default async function getUserByUid(client: Client, uid: number): Promise<string | null> {
const res = await client.util.exec(`${__dirname}/../bin/getUserByUid ${uid}`);

View File

@ -2,5 +2,4 @@ export { default as checkLock, clear as clearLock } from '../intervals/checkLock
export { default as dataConversion } from './dataConversion';
export { default as existingLimitsSetup } from './existingLimitsSetup';
export { default as getUserByUid } from './getUserByUid';
// export { default as checkSS, clear as clearSS } from './checkSS';
export { default as parseCertificate, Certificate } from './parseCertificate';

View File

@ -1,4 +1,4 @@
import { Client } from '..';
import { Client } from '../class';
export interface Certificate {
subject: {

View File

@ -1,4 +1,4 @@
export { default as Client } from './class/Client';
// export { default as Client } from './class/Client';
// eslint-disable-next-line import/no-unresolved
export { default as config } from './config.json';
export * from './class';

View File

@ -1,4 +1,4 @@
import { Client } from '..';
import { Client } from '../class';
let interval: NodeJS.Timeout;

View File

@ -1,49 +0,0 @@
/* eslint-disable consistent-return */
/* eslint-disable no-unreachable */
/* eslint-disable no-await-in-loop */
import axios from 'axios';
import { inspect } from 'util';
import { Client } from '..';
let interval: NodeJS.Timeout;
export default function checkSS(client: Client) {
return;
interval = setInterval(async () => {
try {
const accounts = await client.db.Account.find();
for (const { userID, homepath, hash } of accounts) {
try {
const Authorization = client.util.getAcctHash(homepath);
if (hash === null) throw new Error('Unable to locate auth file, homepath is probably incorrect');
await axios({
method: 'get',
url: 'https://api.securesign.org/account/details',
headers: { Authorization },
});
if (!hash) {
await client.db.Account.updateOne({ userID }, { $set: { hash: true } });
client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign account has been automatically initialized via the SecureSign CLI.')).catch();
}
} catch (error) {
if (!hash) return;
try {
const { status } = error.response;
if (status === 400 || status === 401 || status === 403 || status === 404) {
await client.db.Account.updateOne({ userID }, { $set: { hash: false } });
client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account. Run `=securesign init` for more information')).catch();
}
} catch (e) {
throw error;
}
}
}
} catch (error) {
client.util.handleError(error);
}
}, 60000);
return interval;
}
export function clear() {
clearTimeout(interval);
}

View File

@ -1,6 +1,5 @@
/* eslint-disable no-await-in-loop */
import { Client } from '..';
import { RichEmbed } from '../class';
import { Client, RichEmbed } from '../class';
export default function checkStaffStatus(client: Client) {
setInterval(async () => {

View File

@ -1,8 +1,7 @@
/* eslint-disable no-useless-escape */
/* eslint-disable no-continue */
/* eslint-disable no-await-in-loop */
import { Client } from '..';
import { RichEmbed } from '../class';
import { Client, RichEmbed } from '../class';
import { Tiers } from '../models';
const channelID = '691824484230889546';

View File

@ -1,7 +1,7 @@
/* eslint-disable no-await-in-loop */
// import fs from 'fs-extra';
import { spawn } from 'child_process';
import { Client } from '..';
import { Client } from '../class';
export default async function storage(client: Client) {
let storageGo = spawn(`${__dirname}/../bin/storage`, [], { cwd: __dirname });