diff --git a/src/commands/index.ts b/src/commands/index.ts index 4e449fc..77710cd 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -29,6 +29,7 @@ export { default as npm } from './npm'; export { default as offer } from './offer'; export { default as page } from './page'; export { default as ping } from './ping'; +export { default as profile } from './profile'; export { default as pulldata } from './pulldata'; export { default as rank } from './rank'; export { default as roleinfo } from './roleinfo'; diff --git a/src/commands/profile.ts b/src/commands/profile.ts index f4849ba..2e33716 100644 --- a/src/commands/profile.ts +++ b/src/commands/profile.ts @@ -1,17 +1,22 @@ import { Message } from 'eris'; import { Client, Command } from '../class'; +import Profile_Bio from './profile_bio'; +import Profile_GitHub from './profile_github'; +import Profile_Gitlab from './profile_gitlab'; + export default class Profile extends Command { constructor(client: Client) { super(client); this.name = 'profile'; - this.description = 'Manages your profile on CR'; - this.usage = 'profile '; + this.description = 'Manages your profile on CR.'; + this.usage = 'profile \n*Provide no value in subcommand to clear data.'; this.permissions = 0; this.enabled = true; + this.subcmds = [Profile_Bio, Profile_GitHub, Profile_Gitlab]; } - public async run(message: Message, args: string[]) { + public async run(message: Message) { if (!await this.client.db.Member.exists({ userID: message.author.id })) { await this.client.db.Member.create({ userID: message.author.id }); } diff --git a/src/commands/profile_bio.ts b/src/commands/profile_bio.ts index 5d0625c..f26cb76 100644 --- a/src/commands/profile_bio.ts +++ b/src/commands/profile_bio.ts @@ -15,16 +15,25 @@ export default class Profile_Bio extends Command { if (!await this.client.db.Member.exists({ userID: message.author.id })) { await this.client.db.Member.create({ userID: message.author.id }); } - if (!args[0]) return this.error(message.channel, 'No new bio content was provided.'); + const member = await this.client.db.Member.findOne({ userID: message.author.id }); + + if (!args[0]) { + await member.updateOne({ + additional: { + ...member.additional, + bio: null, + }, + }); + return message.addReaction('modSuccess:578750988907970567'); + } const bio = args.join(' '); if (bio.length >= 256) return this.error(message.channel, 'Bio too long. It must be less than or equal to 256 characters.'); - - const member = await this.client.db.Member.findOne({ userID: message.author.id }); await member.updateOne({ additional: { ...member.additional, bio, }, }); + return message.addReaction('modSuccess:578750988907970567'); } } diff --git a/src/commands/profile_github.ts b/src/commands/profile_github.ts index b5cc1f9..7989140 100644 --- a/src/commands/profile_github.ts +++ b/src/commands/profile_github.ts @@ -15,7 +15,16 @@ export default class Profile_GitHub extends Command { if (!await this.client.db.Member.exists({ userID: message.author.id })) { await this.client.db.Member.create({ userID: message.author.id }); } - if (!args[0]) return this.error(message.channel, 'No GitHub profile URL was provided.'); + const member = await this.client.db.Member.findOne({ userID: message.author.id }); + if (!args[0]) { + await member.updateOne({ + additional: { + ...member.additional, + github: null, + }, + }); + return message.addReaction('modSuccess:578750988907970567'); + } const urlRegex = new RegExp( '^(https?:\\/\\/)?' + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' @@ -27,12 +36,12 @@ export default class Profile_GitHub extends Command { ); if (!urlRegex.test(args[0]) || !args[0].startsWith('https://github.com/')) return this.error(message.channel, 'Invalid GitHub profile URL.'); - const member = await this.client.db.Member.findOne({ userID: message.author.id }); await member.updateOne({ additional: { ...member.additional, github: args[0], }, }); + return message.addReaction('modSuccess:578750988907970567'); } } diff --git a/src/commands/profile_gitlab.ts b/src/commands/profile_gitlab.ts index 284345d..7cb84eb 100644 --- a/src/commands/profile_gitlab.ts +++ b/src/commands/profile_gitlab.ts @@ -16,6 +16,16 @@ export default class Profile_GitLab extends Command { await this.client.db.Member.create({ userID: message.author.id }); } if (!args[0]) return this.error(message.channel, 'No GitLab profile URL was provided.'); + const member = await this.client.db.Member.findOne({ userID: message.author.id }); + if (!args[0]) { + await member.updateOne({ + additional: { + ...member.additional, + gitlab: null, + }, + }); + return message.addReaction('modSuccess:578750988907970567'); + } const urlRegex = new RegExp( '^(https?:\\/\\/)?' + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' @@ -25,14 +35,14 @@ export default class Profile_GitLab extends Command { + '(\\#[-a-z\\d_]*)?$', 'i', ); - if (!urlRegex.test(args[0]) || !args[0].startsWith('https://gitlab.com/')) return this.error(message.channel, 'Invalid GitLab profile URL.'); + if (!urlRegex.test(args[0])) return this.error(message.channel, 'Invalid GitLab profile URL.'); - const member = await this.client.db.Member.findOne({ userID: message.author.id }); await member.updateOne({ additional: { ...member.additional, gitlab: args[0], }, }); + return message.addReaction('modSuccess:578750988907970567'); } } diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 6680608..bf47cbf 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -56,7 +56,7 @@ export default class Whois extends Command { if (ackResolve?.extension) { description += `☎️ ${ackResolve.extension}\n`; } - const memberProfile = await this.client.db.Member.findOne({ userID: message.author.id }); + const memberProfile = await this.client.db.Member.findOne({ userID: message.author.id }).lean().exec(); if (memberProfile?.additional?.gitlab) { description += `${emotes.gitlab} ${memberProfile?.additional.gitlab}\n`; } diff --git a/src/models/Member.ts b/src/models/Member.ts index ccb6330..d6d635d 100644 --- a/src/models/Member.ts +++ b/src/models/Member.ts @@ -9,7 +9,6 @@ export interface MemberInterface extends Document { gitlab: string, bio: string, }, - bio: string, } const Member: Schema = new Schema({ @@ -21,7 +20,6 @@ const Member: Schema = new Schema({ gitlab: String, bio: String, }, - bio: String, }); export default model('Member', Member);