From e4af8f79426acd2fbb01869d4d0438042830af4c Mon Sep 17 00:00:00 2001 From: Matthew R Date: Thu, 9 Jul 2020 19:19:52 -0400 Subject: [PATCH 1/5] update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a2ae0aa..c5c91e1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,6 @@ build/config.yaml # Build/Distribution Files build dist + +# Storage/DB Files localstorage From 24dbbe7c815b2a11a7f4261563e0f086f0868ff7 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 12 Jul 2020 00:39:34 -0400 Subject: [PATCH 2/5] member cmd --- src/commands/ban.ts | 2 +- src/commands/index.ts | 1 + src/commands/members.ts | 92 +++++++++++++++++++++++++++++++++++++++++ src/commands/mute.ts | 90 ++++++++++++++++++++-------------------- src/commands/rank.ts | 1 + src/commands/unmute.ts | 68 +++++++++++++++--------------- 6 files changed, 174 insertions(+), 80 deletions(-) create mode 100644 src/commands/members.ts diff --git a/src/commands/ban.ts b/src/commands/ban.ts index f97de93..72bfaa3 100644 --- a/src/commands/ban.ts +++ b/src/commands/ban.ts @@ -1,5 +1,5 @@ import moment, { unitOfTime } from 'moment'; -import { Message, User, GuildTextableChannel } from 'eris'; +import { Message, User } from 'eris'; import { Client, Command } from '../class'; export default class Ban extends Command { diff --git a/src/commands/index.ts b/src/commands/index.ts index 8e33dd4..f31b84d 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -12,6 +12,7 @@ export { default as help } from './help'; export { default as info } from './info'; export { default as kick } from './kick'; export { default as listredirects } from './listredirects'; +export { default as members } from './members'; export { default as mute } from './mute'; export { default as npm } from './npm'; export { default as page } from './page'; diff --git a/src/commands/members.ts b/src/commands/members.ts new file mode 100644 index 0000000..0528e01 --- /dev/null +++ b/src/commands/members.ts @@ -0,0 +1,92 @@ +import { Message } from 'eris'; +import { createPaginationEmbed } from 'eris-pagination'; +import { Client, Command, RichEmbed } from '../class'; + +export default class extends Command { + constructor(client: Client) { + super(client); + this.name = 'members'; + this.description = 'Gets a list of members in the server or members in a specific role.'; + this.usage = `${this.client.config.prefix}members [role name]`; + this.guildOnly = true; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + await this.mainGuild.fetchAllMembers(); + if (!args[0]) { + const embed = new RichEmbed(); + const membersOnline = this.mainGuild.members.filter((member) => member.status === 'online'); + const membersIdle = this.mainGuild.members.filter((member) => member.status === 'idle'); + const membersDnd = this.mainGuild.members.filter((member) => member.status === 'dnd'); + const membersOffline = this.mainGuild.members.filter((member) => member.status === 'offline'); + const membersBots = this.mainGuild.members.filter((member) => member.user.bot === true); + const membersHuman = this.mainGuild.members.filter((member) => member.user.bot === false); + + embed.setTitle('Members'); + embed.addField('Total', `${this.mainGuild.members.size}`, true); + embed.addField('Humans', `${membersHuman.length}`, true); + embed.addField('Bots', `${membersBots.length}`, true); + embed.addBlankField(); + embed.addField('Online', `${membersOnline.length}`, true); + embed.addField('Idle', `${membersIdle.length}`, true); + embed.addField('Do Not Disturb', `${membersDnd.length}`, true); + embed.addField('Offline', `${membersOffline.length}`, true); + embed.setFooter(this.client.user.username, this.client.user.avatarURL); + embed.setTimestamp(); + + return message.channel.createMessage({ embed }); + } + + const role = this.client.util.resolveRole(args.join(' '), this.mainGuild); + if (!role) return this.error(message.channel, 'The role you specified doesn\'t exist.'); + const membersArray: [{name: string, value: string}?] = []; + const membersOnline: string[] = []; + const membersIdle: string[] = []; + const membersDnd: string[] = []; + const membersOffline: string[] = []; + for (const member of this.mainGuild.members.filter((m) => m.roles.includes(role.id)).sort((a, b) => a.username.localeCompare(b.username))) { + switch (member.status) { + case 'online': + membersOnline.push(`${member.user.username}#${member.user.discriminator} | <@${member.user.id}>`); + break; + case 'idle': + membersIdle.push(`${member.user.username}#${member.user.discriminator} | <@${member.user.id}>`); + break; + case 'dnd': + membersDnd.push(`${member.user.username}#${member.user.discriminator} | <@${member.user.id}>`); + break; + case 'offline': + membersOffline.push(`${member.user.username}#${member.user.discriminator} | <@${member.user.id}>`); + break; + case undefined: + membersOffline.push(`${member.user.username}#${member.user.discriminator} | <@${member.user.id}>`); + break; + default: + break; + } + } + if (membersOnline.length > 0) membersArray.push({ name: 'Online', value: membersOnline.join('\n') }); + if (membersIdle.length > 0) membersArray.push({ name: 'Idle', value: membersIdle.join('\n') }); + if (membersDnd.length > 0) membersArray.push({ name: 'Do Not Disturb', value: membersDnd.join('\n') }); + if (membersOffline.length > 0) membersArray.push({ name: 'Offline', value: membersOffline.join('\n') }); + const membersSplit = this.client.util.splitFields(membersArray); + const cmdPages: RichEmbed[] = []; + membersSplit.forEach((split) => { + const embed = new RichEmbed(); + embed.setTitle(`Members in ${role.name}`); + embed.setDescription(`Members in Role: ${membersOnline.length + membersIdle.length + membersDnd.length + membersOffline.length}`); + embed.setColor(role.color); + embed.setFooter(this.client.user.username, this.client.user.avatarURL); + embed.setTimestamp(); + split.forEach((c) => embed.addField(c.name, c.value)); + return cmdPages.push(embed); + }); + if (cmdPages.length === 1) return message.channel.createMessage({ embed: cmdPages[0] }); + return createPaginationEmbed(message, cmdPages); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} diff --git a/src/commands/mute.ts b/src/commands/mute.ts index 65d47a8..f33684b 100644 --- a/src/commands/mute.ts +++ b/src/commands/mute.ts @@ -1,45 +1,45 @@ -import moment, { unitOfTime } from 'moment'; -import { Message } from 'eris'; -import { Client, Command } from '../class'; - -export default class Mute extends Command { - constructor(client: Client) { - super(client); - this.name = 'mute'; - this.description = 'Mutes a member.'; - this.usage = 'mute [time] [reason]'; - this.permissions = 2; - this.guildOnly = true; - this.enabled = true; - } - - public async run(message: Message, args: string[]) { - try { - if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - const member = this.client.util.resolveMember(args[0], this.mainGuild); - if (!member) return this.error(message.channel, 'Cannot find user.'); - - try { - const res1 = await this.client.db.local.muted.get(`muted-${member.id}`); - if (res1 || this.mainGuild.members.get(member.id).roles.includes('478373942638149643')) return this.error(message.channel, 'This user is already muted.'); - } catch {} // eslint-disable-line no-empty - if (member && !this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.'); - message.delete(); - - let momentMilliseconds: number; - let reason: string; - if (args.length > 1) { - const lockLength = args[1].match(/[a-z]+|[^a-z]+/gi); - const length = Number(lockLength[0]); - const unit = lockLength[1] as unitOfTime.Base; - momentMilliseconds = moment.duration(length, unit).asMilliseconds(); - reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' '); - if (reason.length > 512) return this.error(message.channel, 'Mute reasons cannot be longer than 512 characters.'); - } - await this.client.util.moderation.mute(member.user, message.member, momentMilliseconds, reason); - return this.success(message.channel, `${member.user.username}#${member.user.discriminator} has been muted.`); - } catch (err) { - return this.client.util.handleError(err, message, this, false); - } - } -} +import moment, { unitOfTime } from 'moment'; +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class Mute extends Command { + constructor(client: Client) { + super(client); + this.name = 'mute'; + this.description = 'Mutes a member.'; + this.usage = 'mute [time] [reason]'; + this.permissions = 2; + this.guildOnly = true; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); + const member = this.client.util.resolveMember(args[0], this.mainGuild); + if (!member) return this.error(message.channel, 'Cannot find user.'); + + try { + const res1 = await this.client.db.local.muted.get(`muted-${member.id}`); + if (res1 || this.mainGuild.members.get(member.id).roles.includes('478373942638149643')) return this.error(message.channel, 'This user is already muted.'); + } catch {} // eslint-disable-line no-empty + if (member && !this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.'); + message.delete(); + + let momentMilliseconds: number; + let reason: string; + if (args.length > 1) { + const lockLength = args[1].match(/[a-z]+|[^a-z]+/gi); + const length = Number(lockLength[0]); + const unit = lockLength[1] as unitOfTime.Base; + momentMilliseconds = moment.duration(length, unit).asMilliseconds(); + reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' '); + if (reason.length > 512) return this.error(message.channel, 'Mute reasons cannot be longer than 512 characters.'); + } + await this.client.util.moderation.mute(member.user, message.member, momentMilliseconds, reason); + return this.success(message.channel, `${member.user.username}#${member.user.discriminator} has been muted.`); + } catch (err) { + return this.client.util.handleError(err, message, this, false); + } + } +} diff --git a/src/commands/rank.ts b/src/commands/rank.ts index 2fe7c1e..4409f55 100644 --- a/src/commands/rank.ts +++ b/src/commands/rank.ts @@ -42,6 +42,7 @@ export default class Rank extends Command { embed.setFooter(`Requested by: ${message.author.username}#${message.author.discriminator} | ${this.client.user.username}`, message.author.avatarURL); embed.setTimestamp(); split.forEach((c) => embed.addField(c.name, c.value)); + return cmdPages.push(embed); }); if (cmdPages.length === 1) return message.channel.createMessage({ embed: cmdPages[0] }); return createPaginationEmbed(message, cmdPages); diff --git a/src/commands/unmute.ts b/src/commands/unmute.ts index 170b245..f3d75c1 100644 --- a/src/commands/unmute.ts +++ b/src/commands/unmute.ts @@ -1,34 +1,34 @@ -import { Message } from 'eris'; -import { Client, Command } from '../class'; - -export default class Unmute extends Command { - constructor(client: Client) { - super(client); - this.name = 'unmute'; - this.description = 'Unmutes a member.'; - this.usage = 'unmute [reason]'; - this.permissions = 2; - this.guildOnly = true; - this.enabled = true; - } - - public async run(message: Message, args: string[]) { - try { - if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - const member = this.client.util.resolveMember(args[0], this.mainGuild); - if (!member) return this.error(message.channel, 'Cannot find user.'); - - try { - const res1 = await this.client.db.local.muted.get(`muted-${member.id}`); - if (!res1 || !this.mainGuild.members.get(member.id).roles.includes('478373942638149643')) return this.error(message.channel, 'This user is already unmuted.'); - } catch {} // eslint-disable-line no-empty - if (member && !this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.'); - message.delete(); - - await this.client.util.moderation.unmute(member.user.id, message.member, args.slice(1).join(' ')); - return this.success(message.channel, `${member.user.username}#${member.user.discriminator} has been unmuted.`); - } catch (err) { - return this.client.util.handleError(err, message, this, false); - } - } -} +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class Unmute extends Command { + constructor(client: Client) { + super(client); + this.name = 'unmute'; + this.description = 'Unmutes a member.'; + this.usage = 'unmute [reason]'; + this.permissions = 2; + this.guildOnly = true; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); + const member = this.client.util.resolveMember(args[0], this.mainGuild); + if (!member) return this.error(message.channel, 'Cannot find user.'); + + try { + const res1 = await this.client.db.local.muted.get(`muted-${member.id}`); + if (!res1 || !this.mainGuild.members.get(member.id).roles.includes('478373942638149643')) return this.error(message.channel, 'This user is already unmuted.'); + } catch {} // eslint-disable-line no-empty + if (member && !this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.'); + message.delete(); + + await this.client.util.moderation.unmute(member.user.id, message.member, args.slice(1).join(' ')); + return this.success(message.channel, `${member.user.username}#${member.user.discriminator} has been unmuted.`); + } catch (err) { + return this.client.util.handleError(err, message, this, false); + } + } +} From 2095ab773f9fc67eca6de877d1073e9e3a31ba15 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 12 Jul 2020 01:08:04 -0400 Subject: [PATCH 3/5] add dept pager --- src/intervals/departmentPager.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/intervals/departmentPager.ts b/src/intervals/departmentPager.ts index 554cc4d..962d924 100644 --- a/src/intervals/departmentPager.ts +++ b/src/intervals/departmentPager.ts @@ -70,6 +70,7 @@ async function setupDepartmentCodes(client: Client): Promise { } function logNewPager(client: Client, num: string, member: Member): void { + client.util.signale.log(`Pager Number '${num}' created for '${member.user.username}#${member.user.discriminator}'.`); const channel = client.guilds.get(client.config.guildID).channels.get('722636436716781619'); channel.createMessage(`__**'${member.user.username}#${member.user.discriminator}' assigned to pager number '${num}'.**__`); } @@ -81,29 +82,34 @@ export default function departmentPager(client: Client): NodeJS.Timeout { function resolveStaffInformation(id: string) { return acknowledgements.find((m) => m.id === id); } - // await client.guilds.get(client.config.guildID).fetchAllMembers(); + await client.guilds.get(client.config.guildID).fetchAllMembers(); const { members } = client.guilds.get(client.config.guildID); for (const member of members.values()) { const pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec(); if (!pager) continue; if (pager.num.startsWith('00') && !member.roles.includes('662163685439045632')) { - client.db.PagerNumber.deleteOne({ num: pager.num }); + await client.db.PagerNumber.deleteOne({ num: pager.num }); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); - } else if (pager.num.startsWith('01') && !member.roles.includes('701454855952138300')) { - client.db.PagerNumber.deleteOne({ num: pager.num }); + } + if (pager.num.startsWith('01') && !member.roles.includes('701454855952138300')) { + await client.db.PagerNumber.deleteOne({ num: pager.num }); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); - } else if (pager.num.startsWith('10') && !member.roles.includes('701454780828221450')) { - client.db.PagerNumber.deleteOne({ num: pager.num }); + } + if (pager.num.startsWith('10') && !member.roles.includes('701454780828221450')) { + await client.db.PagerNumber.deleteOne({ num: pager.num }); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); - } else if (pager.num.startsWith('20') && !member.roles.includes('455972169449734144')) { - client.db.PagerNumber.deleteOne({ num: pager.num }); + } + if (pager.num.startsWith('20') && !member.roles.includes('455972169449734144')) { + await client.db.PagerNumber.deleteOne({ num: pager.num }); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); - } else if (pager.num.startsWith('21') && !member.roles.includes('453689940140883988')) { - client.db.PagerNumber.deleteOne({ num: pager.num }); + } + if (pager.num.startsWith('21') && !member.roles.includes('453689940140883988')) { + await client.db.PagerNumber.deleteOne({ num: pager.num }); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); - } else if (pager.num.startsWith('22') && !member.roles.includes('701481967149121627')) { - client.db.PagerNumber.deleteOne({ num: pager.num }); + } + if (pager.num.startsWith('22') && !member.roles.includes('701481967149121627')) { + await client.db.PagerNumber.deleteOne({ num: pager.num }); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); } } @@ -353,6 +359,6 @@ export default function departmentPager(client: Client): NodeJS.Timeout { if (acknowledgement?.emailAddress) await directorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } }); } } - }, 300000); + }, 30000); return interval; } From 2e96cb94aa1ebc80253a371fc4d16a8eec8ffd7d Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 12 Jul 2020 01:09:09 -0400 Subject: [PATCH 4/5] add dept pager --- src/intervals/departmentPager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intervals/departmentPager.ts b/src/intervals/departmentPager.ts index 962d924..06d9c5f 100644 --- a/src/intervals/departmentPager.ts +++ b/src/intervals/departmentPager.ts @@ -359,6 +359,6 @@ export default function departmentPager(client: Client): NodeJS.Timeout { if (acknowledgement?.emailAddress) await directorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } }); } } - }, 30000); + }, 300000); return interval; } From 045d773475f0cfcd9f768b0d0915c614c531c846 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 12 Jul 2020 01:11:33 -0400 Subject: [PATCH 5/5] disable members cmd' --- src/commands/members.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/members.ts b/src/commands/members.ts index 0528e01..6261924 100644 --- a/src/commands/members.ts +++ b/src/commands/members.ts @@ -9,7 +9,7 @@ export default class extends Command { this.description = 'Gets a list of members in the server or members in a specific role.'; this.usage = `${this.client.config.prefix}members [role name]`; this.guildOnly = true; - this.enabled = true; + this.enabled = false; } public async run(message: Message, args: string[]) {