From 5a2ce235b741c419e2ec93774cdb2ee4ba648bf4 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 17 Aug 2020 23:49:57 -0400 Subject: [PATCH] switch from json to mongodb for ack --- src/api/loc.sh/routes/internal.ts | 3 ++- src/class/Client.ts | 6 +++--- src/commands/whois.ts | 7 ++++--- src/models/Staff.ts | 29 +++++++++++++++++++++++++++++ src/models/index.ts | 1 + 5 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 src/models/Staff.ts diff --git a/src/api/loc.sh/routes/internal.ts b/src/api/loc.sh/routes/internal.ts index dd60478..3836e58 100644 --- a/src/api/loc.sh/routes/internal.ts +++ b/src/api/loc.sh/routes/internal.ts @@ -1,5 +1,5 @@ import { Route, Server } from '../../../class'; -import acknowledgements from '../../../configs/acknowledgements.json'; +// import acknowledgements from '../../../configs/acknowledgements.json'; export default class Internal extends Route { constructor(server: Server) { @@ -22,6 +22,7 @@ export default class Internal extends Route { if (member.roles.includes('446104438969466890') || member.roles.includes('701481967149121627')) status = true; return res.status(200).json({ staff: status, username: member.user.username, discriminator: member.user.discriminator, nick: member.nick, avatarURL: member.user.avatarURL, pager: pagerNumber?.num }); } + const acknowledgements = await this.server.client.db.Staff.find().lean().exec(); return res.status(200).json(acknowledgements); } catch (err) { return this.handleError(err, res); diff --git a/src/class/Client.ts b/src/class/Client.ts index 417b747..a8117cd 100644 --- a/src/class/Client.ts +++ b/src/class/Client.ts @@ -3,7 +3,7 @@ import pluris from 'pluris'; import mongoose from 'mongoose'; import { promises as fs } from 'fs'; import { Collection, Command, LocalStorage, Util, ServerManagement, Event } from '.'; -import { File, FileInterface, Member, MemberInterface, Moderation, ModerationInterface, Note, NoteInterface, PagerNumber, PagerNumberInterface, Rank, RankInterface, Redirect, RedirectInterface, Stat, StatInterface } from '../models'; +import { File, FileInterface, Member, MemberInterface, Moderation, ModerationInterface, Note, NoteInterface, PagerNumber, PagerNumberInterface, Rank, RankInterface, Redirect, RedirectInterface, Staff, StaffInterface, Stat, StatInterface } from '../models'; import { Config } from '../../types'; // eslint-disable-line pluris(eris); @@ -21,14 +21,14 @@ export default class Client extends eris.Client { public serverManagement: ServerManagement; - public db: { File: mongoose.Model, Member: mongoose.Model, Moderation: mongoose.Model, Note: mongoose.Model, PagerNumber: mongoose.Model, Rank: mongoose.Model, Redirect: mongoose.Model, Stat: mongoose.Model, local: { muted: LocalStorage } }; + public db: { File: mongoose.Model, Member: mongoose.Model, Moderation: mongoose.Model, Note: mongoose.Model, PagerNumber: mongoose.Model, Rank: mongoose.Model, Redirect: mongoose.Model, Staff: mongoose.Model, Stat: mongoose.Model, local: { muted: LocalStorage } }; constructor(token: string, options?: eris.ClientOptions) { super(token, options); this.commands = new Collection(); this.events = new Collection(); this.intervals = new Collection(); - this.db = { File, Member, Moderation, Note, PagerNumber, Rank, Redirect, Stat, local: { muted: new LocalStorage('muted') } }; + this.db = { File, Member, Moderation, Note, PagerNumber, Rank, Redirect, Staff, Stat, local: { muted: new LocalStorage('muted') } }; } public async loadDatabase() { diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 9e2a608..245ef69 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -2,7 +2,7 @@ import moment from 'moment'; import { Message, Member } from 'eris'; import { Client, Command, RichEmbed } from '../class'; -import acknowledgements from '../configs/acknowledgements.json'; +// import acknowledgements from '../configs/acknowledgements.json'; import { whois as emotes } from '../configs/emotes.json'; export default class Whois extends Command { @@ -29,7 +29,8 @@ export default class Whois extends Command { } const embed = new RichEmbed(); embed.setThumbnail(member.avatarURL); - const ackResolve = this.resolveStaffInformation(member.id); + // const ackResolve = this.resolveStaffInformation(member.id); + const ackResolve = await this.client.db.Staff.findOne({ userID: member.id }).lean().exec(); let title = `${member.user.username}#${member.user.discriminator}`; if (ackResolve?.pn?.length > 0) title += `, ${ackResolve.pn.join(', ')}`; embed.setAuthor(title, member.user.avatarURL); @@ -189,7 +190,7 @@ export default class Whois extends Command { } public resolveStaffInformation(id: string) { - return acknowledgements.find((m) => m.id === id); + return null; // acknowledgements.find((m) => m.id === id); } public capsFirstLetter(string?: string): string | void { diff --git a/src/models/Staff.ts b/src/models/Staff.ts new file mode 100644 index 0000000..d114559 --- /dev/null +++ b/src/models/Staff.ts @@ -0,0 +1,29 @@ +import { Document, Schema, model } from 'mongoose'; + +export interface StaffInterface extends Document { + name: string, + userID: string, + title: string, + dept: string, + pn: string[], + emailAddress: string, + gitlab: string, + github: string, + bio: string, + acknowledgements: string[], +} + +const Staff: Schema = new Schema({ + name: String, + userID: String, + title: String, + dept: String, + pn: Array, + emailAddress: String, + gitlab: String, + github: String, + bio: String, + acknowledgements: Array, +}); + +export default model('Staff', Staff); diff --git a/src/models/index.ts b/src/models/index.ts index d5ee1b9..09e88fe 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -5,4 +5,5 @@ export { default as Note, NoteInterface } from './Note'; export { default as PagerNumber, PagerNumberInterface, PagerNumberRaw } from './PagerNumber'; export { default as Rank, RankInterface } from './Rank'; export { default as Redirect, RedirectInterface, RedirectRaw } from './Redirect'; +export { default as Staff, StaffInterface } from './Staff'; export { default as Stat, StatInterface } from './Stat';