changes to queue system
parent
436f29e73e
commit
2e83cb7d55
|
@ -2,7 +2,7 @@ import eris from 'eris';
|
|||
import pluris from 'pluris';
|
||||
import mongoose from 'mongoose';
|
||||
import { promises as fs } from 'fs';
|
||||
import { Collection, Command, LocalStorage, Util, ServerManagement, Event } from '.';
|
||||
import { Collection, Command, LocalStorage, Queue, Util, ServerManagement, Event } from '.';
|
||||
import { File, FileInterface, Member, MemberInterface, Merchant, MerchantInterface, Moderation, ModerationInterface, NNTrainingData, NNTrainingDataInterface, Note, NoteInterface, PagerNumber, PagerNumberInterface, Rank, RankInterface, Redirect, RedirectInterface, Score, ScoreInterface, Staff, StaffInterface, Stat, StatInterface } from '../models';
|
||||
import { Config } from '../../types'; // eslint-disable-line
|
||||
|
||||
|
@ -21,6 +21,8 @@ export default class Client extends eris.Client {
|
|||
|
||||
public serverManagement: ServerManagement;
|
||||
|
||||
public queue: { main: Queue };
|
||||
|
||||
public db: { File: mongoose.Model<FileInterface>, Member: mongoose.Model<MemberInterface>, Merchant: mongoose.Model<MerchantInterface>, Moderation: mongoose.Model<ModerationInterface>, NNTrainingData: mongoose.Model<NNTrainingDataInterface>, Note: mongoose.Model<NoteInterface>, PagerNumber: mongoose.Model<PagerNumberInterface>, Rank: mongoose.Model<RankInterface>, Redirect: mongoose.Model<RedirectInterface>, Score: mongoose.Model<ScoreInterface>, Staff: mongoose.Model<StaffInterface>, Stat: mongoose.Model<StatInterface>, local: { muted: LocalStorage } };
|
||||
|
||||
constructor(token: string, options?: eris.ClientOptions) {
|
||||
|
@ -28,6 +30,9 @@ export default class Client extends eris.Client {
|
|||
this.commands = new Collection<Command>();
|
||||
this.events = new Collection<Event>();
|
||||
this.intervals = new Collection<NodeJS.Timeout>();
|
||||
this.queue = {
|
||||
main: new Queue(this, 'main'),
|
||||
};
|
||||
this.db = { File, Member, Merchant, Moderation, NNTrainingData, Note, PagerNumber, Rank, Redirect, Score, Staff, Stat, local: { muted: new LocalStorage('muted') } };
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
import { EventEmitter } from 'events';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { Client, Collection } from '.';
|
||||
|
||||
export type QueueID = string;
|
||||
|
||||
export interface QueueEntry {
|
||||
readonly id?: QueueID,
|
||||
readonly enteredDate?: Date,
|
||||
readonly submittedBy: string,
|
||||
func: Function,
|
||||
}
|
||||
|
||||
export default class Queue extends EventEmitter {
|
||||
public queueName: string;
|
||||
|
||||
public client: Client;
|
||||
|
||||
protected set: Collection<QueueEntry>;
|
||||
|
||||
constructor(client: Client, queueName: string) {
|
||||
super();
|
||||
this.client = client;
|
||||
this.queueName = queueName;
|
||||
this.set = new Collection();
|
||||
}
|
||||
|
||||
public postListeners() {
|
||||
this.on('newEntry', (data: QueueEntry) => {
|
||||
this.client.util.signale.info(`New Entry in Queue ${this.queueName}\nEntered Date: ${data.enteredDate} | Submitted by: ${data.submittedBy}`);
|
||||
});
|
||||
this.on('processing', (data: QueueEntry) => {
|
||||
this.client.util.signale.pending(`Processing Entry in Queue ${this.queueName}\nEntered Date: ${data.enteredDate} | Submitted by: ${data.submittedBy}`);
|
||||
});
|
||||
this.on('done', (data: QueueEntry) => {
|
||||
this.client.util.signale.success(`Finished Entry in Queue ${this.queueName}\nEntered Date: ${data.enteredDate} | Submitted by: ${data.submittedBy}`);
|
||||
});
|
||||
}
|
||||
|
||||
public add(entry: QueueEntry) {
|
||||
const data = this.set.add(uuid(), { enteredDate: new Date(), submittedBy: entry.submittedBy, func: entry.func });
|
||||
this.emit('newEntry', data);
|
||||
this.do(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
protected async do(entry: QueueEntry) {
|
||||
try {
|
||||
this.emit('processing', entry);
|
||||
await entry.func(this.client);
|
||||
} finally {
|
||||
this.set.delete(entry.id);
|
||||
this.emit('done', entry);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ export { default as Command } from './Command';
|
|||
export { default as Event } from './Event';
|
||||
export { default as LocalStorage } from './LocalStorage';
|
||||
export { default as Moderation } from './Moderation';
|
||||
export { default as Queue } from './Queue';
|
||||
export { default as RichEmbed } from './RichEmbed';
|
||||
export { default as Route } from './Route';
|
||||
export { default as Server } from './Server';
|
||||
|
|
|
@ -22,6 +22,11 @@ export default class Whois extends Command {
|
|||
if (!args[0]) member = message.member;
|
||||
else {
|
||||
member = this.client.util.resolveMember(args.join(' '), this.mainGuild);
|
||||
try {
|
||||
if (!member) member = await this.mainGuild.getRESTMember(args[0]);
|
||||
} catch {
|
||||
return this.error(message.channel, 'Member not found.');
|
||||
}
|
||||
}
|
||||
|
||||
if (!member) {
|
||||
|
@ -75,6 +80,7 @@ export default class Whois extends Command {
|
|||
embed.addField('Created At', `${moment(new Date(member.user.createdAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true);
|
||||
const score = await this.client.db.Score.findOne({ userID: member.id });
|
||||
if (score) {
|
||||
await this.client.db.Score.updateOne({ userID: member.id }, { $addToSet: { softInquiries: { name: 'Library of Code sp-us | Bureau of Community Reports', date: new Date() } } });
|
||||
let totalScore = '0';
|
||||
if (score.total < 200) totalScore = '---';
|
||||
else if (score.total > 800) totalScore = '800';
|
||||
|
|
|
@ -162,10 +162,20 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
|
|||
|
||||
total = Math.floor(((total + activity + roles + moderation + cloudServices + staff + other) * 5.13) * 1.87);
|
||||
|
||||
await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, other, staff, lastUpdate: new Date() } });
|
||||
/* await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, other, staff, lastUpdate: new Date() } });
|
||||
if (!score.pin || score.pin?.length < 1) {
|
||||
await client.db.Score.updateOne({ userID: member.id }, { $set: { pin: [client.util.randomNumber(100, 999), client.util.randomNumber(10, 99), client.util.randomNumber(1000, 9999)] } });
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
client.queue.main.add({ submittedBy: 'intervals::score',
|
||||
func: async (cl: Client) => {
|
||||
await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, other, staff, lastUpdate: new Date() } });
|
||||
if (!score.pin || score.pin?.length < 1) {
|
||||
await cl.db.Score.updateOne({ userID: member.id }, { $set: { pin: [cl.util.randomNumber(100, 999), cl.util.randomNumber(10, 99), cl.util.randomNumber(1000, 9999)] } });
|
||||
}
|
||||
} });
|
||||
// client.util.signale.debug(`SCORE SET - ${member.username}\nTotal: ${total}\nActivity: ${activity}\nRoles: ${roles}\nModeration: ${moderation}\nCloud Services: ${cloudServices}\nStaff: ${staff}`);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -11,7 +11,7 @@ import { Config } from '../types'; // eslint-disable-line
|
|||
async function main(): Promise<void> {
|
||||
const read = await fs.readFile('../config.yaml', 'utf8');
|
||||
const config: Config = parse(read);
|
||||
const client = new Client(config.token, { defaultImageFormat: 'png', restMode: true });
|
||||
const client = new Client(config.token, { defaultImageFormat: 'png', restMode: true, intents: ['guildBans', 'guildEmojis', 'guildInvites', 'guildMembers', 'guildMessageReactions', 'guildMessages', 'guildPresences', 'guildWebhooks', 'guilds', 'directMessages'] });
|
||||
client.config = config;
|
||||
await client.loadDatabase();
|
||||
client.loadPlugins();
|
||||
|
|
Loading…
Reference in New Issue