From 3f25cd8f3410061075435c44f6969d5646ea5bd7 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 23 Nov 2020 14:52:55 -0500 Subject: [PATCH] addcallback command --- src/commands/callback.ts | 62 +++++++++++++++++++++++++++++++++++ src/commands/index.ts | 1 + src/events/CallBackHandler.ts | 23 +++++++++++++ src/events/index.ts | 1 + 4 files changed, 87 insertions(+) create mode 100644 src/commands/callback.ts create mode 100644 src/events/CallBackHandler.ts diff --git a/src/commands/callback.ts b/src/commands/callback.ts new file mode 100644 index 0000000..4da387b --- /dev/null +++ b/src/commands/callback.ts @@ -0,0 +1,62 @@ +import PhoneNumber from 'awesome-phonenumber'; +import axios from 'axios'; +import { Message, TextChannel } from 'eris'; +import { Client, Command, RichEmbed } from '../class'; + +export default class Callback extends Command { + constructor(client: Client) { + super(client); + this.name = 'callback'; + this.description = 'Requests a Callback from a Technican.\nPlease use `-` to separate the number if needed. E.x. 202-750-2585.\nDo note, we are unable to dial international numbers outside of the US and Canada.'; + this.usage = 'callback '; + this.aliases = ['cb']; + this.permissions = 0; + this.guildOnly = false; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); + if (message.channel.type === 0) await message.delete(); + const member = this.mainGuild.members.get(message.author.id); + if (!member) return this.error(message.channel, 'Unable to fetch member.'); + const phone = new PhoneNumber(args.join(' '), 'US'); + if (!phone.isValid()) return this.error(message.channel, 'The number you have entered is invalid.'); + const embed = new RichEmbed(); + embed.setTitle('Callback Request'); + embed.setDescription('Please dial `9` first to reach an the external trunk. For example, to dial 202-750-2585 you would dial 92027502585 on your device.\n\n*Please react with <:modSuccess:578750988907970567> on this message if you are taking the call.*'); + embed.addField('Member', `${member.user.username}#${member.user.discriminator} | <@${member.user.id}>`, true); + embed.addField('Phone Number', phone.getNumber('national'), true); + embed.addField('Phone Number Type', phone.getType(), true); + const communityReport = await this.client.db.Score.findOne({ userID: message.author.id }).lean().exec(); + if (communityReport) { + await this.client.db.Score.updateOne({ userID: message.author.id }, { $addToSet: { softInquiries: { name: 'LIBRARY OF CODE SP-US | VOIP/PBX MEMBER SUPPORT SVCS', date: new Date() } } }); + const embed2 = new RichEmbed(); + embed2.setTitle('Inquiry Notification'); + embed2.setColor('#00FFFF'); + embed2.addField('Member', `${member.user.username}#${member.user.discriminator} | <@${member.user.id}>`, true); + embed2.addField('Type', 'SOFT', true); + embed2.addField('Department/Service', 'Library of Code sp-us | VOIP/PBX Member Support SVCS'.toUpperCase(), true); + embed2.setTimestamp(); + embed2.setFooter(this.client.user.username, this.client.user.avatarURL); + const log = this.mainGuild.channels.get('611584771356622849'); + log.createMessage({ embed: embed2 }).catch(() => {}); + embed.addField('PIN', `${communityReport.pin[0]}-${communityReport.pin[1]}-${communityReport.pin[2]}`, true); + } + try { + const d = await axios.get(`https://api.cloud.libraryofcode.org/wh/info/?id=${message.author.id}&authorization=${this.client.config.internalKey}`); + embed.addField('Email Address', d.data.emailAddress, true); + embed.addField('Support Key', d.data.supportKey, true); + } catch { + this.client.util.signale.warn('No CS Account found for user.'); + } + const chan = this.mainGuild.channels.get('780513128240382002'); + const msg = await chan.createMessage({ content: '<@&780519428873781298>', embed }); + await msg.addReaction('modSuccess:578750988907970567'); + return message.channel.createMessage('__**Callback Request**__\nYour callback request has been sent to our agents, you should receive a callback within 1-24 hours from the date of this request. The number you will be called from is listed below.\n\n**Callback Number:** +1 202-750-2585\n**Callback Region:** Washington, D.C., United States\n\n\n*Your number is never stored on our systems at any time, as soon as your call is taken by an agent your number is deleted from notification channels.*'); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} diff --git a/src/commands/index.ts b/src/commands/index.ts index 79f91b3..13cbf23 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -6,6 +6,7 @@ export { default as addredirect } from './addredirect'; export { default as apply } from './apply'; export { default as ban } from './ban'; export { default as billing } from './billing'; +export { default as callback } from './callback'; export { default as delitem } from './delitem'; export { default as delmerchant } from './delmerchant'; export { default as delnote } from './delnote'; diff --git a/src/events/CallBackHandler.ts b/src/events/CallBackHandler.ts new file mode 100644 index 0000000..2069fff --- /dev/null +++ b/src/events/CallBackHandler.ts @@ -0,0 +1,23 @@ +import { Emoji, Message, TextChannel } from 'eris'; +import { Client, Event } from '../class'; + +export default class CallBackHandler extends Event { + public client: Client; + + constructor(client: Client) { + super(client); + this.event = 'messageReactionAdd'; + } + + public async run(message: Message, emoji: Emoji, member: string) { + try { + if (emoji.id !== '578750988907970567' || message.channel.id !== '780513128240382002') return; + if (member === this.client.user.id) return; + const chan = this.client.guilds.get(this.client.config.guildID).channels.get('780513128240382002'); + const msg = await chan.getMessage(message.id); + await msg.delete(); + } catch (err) { + this.client.util.handleError(err); + } + } +} diff --git a/src/events/index.ts b/src/events/index.ts index ae21565..9caf386 100644 --- a/src/events/index.ts +++ b/src/events/index.ts @@ -1,3 +1,4 @@ +export { default as CallBackHandler } from './CallBackHandler'; export { default as CommandHandler } from './CommandHandler'; export { default as guildMemberAdd } from './guildMemberAdd'; export { default as ready } from './ready';