diff --git a/src/commands/profile.ts b/src/commands/profile.ts new file mode 100644 index 0000000..f4849ba --- /dev/null +++ b/src/commands/profile.ts @@ -0,0 +1,21 @@ +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +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.permissions = 0; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + if (!await this.client.db.Member.exists({ userID: message.author.id })) { + await this.client.db.Member.create({ userID: message.author.id }); + } + + this.error(message.channel, `Please specify a valid option to change. Choose from \`github\`, \`bio\` and \`gitlab\`. You can view your profile with \`${this.client.config.prefix}whois\`.`); + } +} diff --git a/src/commands/profile_bio.ts b/src/commands/profile_bio.ts new file mode 100644 index 0000000..5d0625c --- /dev/null +++ b/src/commands/profile_bio.ts @@ -0,0 +1,30 @@ +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class Profile_Bio extends Command { + constructor(client: Client) { + super(client); + this.name = 'bio'; + this.description = 'Updates your bio on your profile.'; + this.usage = `${this.client.config.prefix}bio `; + this.permissions = 0; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + 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 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, + }, + }); + } +} diff --git a/src/commands/profile_github.ts b/src/commands/profile_github.ts new file mode 100644 index 0000000..b5cc1f9 --- /dev/null +++ b/src/commands/profile_github.ts @@ -0,0 +1,38 @@ +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class Profile_GitHub extends Command { + constructor(client: Client) { + super(client); + this.name = 'github'; + this.description = 'Updates your GitHub information on your profile.'; + this.usage = `${this.client.config.prefix}github `; + this.permissions = 0; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + 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 urlRegex = new RegExp( + '^(https?:\\/\\/)?' + + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + + '((\\d{1,3}\\.){3}\\d{1,3}))' + + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + + '(\\?[;&a-z\\d%_.~+=-]*)?' + + '(\\#[-a-z\\d_]*)?$', + 'i', + ); + 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], + }, + }); + } +} diff --git a/src/commands/profile_gitlab.ts b/src/commands/profile_gitlab.ts new file mode 100644 index 0000000..284345d --- /dev/null +++ b/src/commands/profile_gitlab.ts @@ -0,0 +1,38 @@ +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class Profile_GitLab extends Command { + constructor(client: Client) { + super(client); + this.name = 'gitlab'; + this.description = 'Updates your GitLab information on your profile.'; + this.usage = `${this.client.config.prefix}gitlab `; + this.permissions = 0; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + 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 GitLab profile URL was provided.'); + const urlRegex = new RegExp( + '^(https?:\\/\\/)?' + + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + + '((\\d{1,3}\\.){3}\\d{1,3}))' + + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + + '(\\?[;&a-z\\d%_.~+=-]*)?' + + '(\\#[-a-z\\d_]*)?$', + 'i', + ); + if (!urlRegex.test(args[0]) || !args[0].startsWith('https://gitlab.com/')) 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], + }, + }); + } +} diff --git a/src/commands/whois.ts b/src/commands/whois.ts index ca29c3d..5cc5379 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -58,14 +58,15 @@ export default class Whois extends Command { if (ackResolve?.extension) { description += `☎️ ${ackResolve.extension}\n`; } - if (ackResolve?.gitlab) { - description += `${emotes.gitlab} ${ackResolve?.gitlab}\n`; + const memberProfile = await this.client.db.Member.findOne({ userID: message.author.id }); + if (memberProfile?.additional?.gitlab) { + description += `${emotes.gitlab} ${memberProfile?.additional.gitlab}\n`; } - if (ackResolve?.github) { - description += `${emotes.github} ${ackResolve?.github}\n`; + if (memberProfile?.additional?.github) { + description += `${emotes.github} ${memberProfile?.additional.github}\n`; } - if (ackResolve?.bio) { - description += `${emotes.bio} *${ackResolve?.bio}*\n`; + if (memberProfile?.additional?.bio) { + description += `${emotes.bio} *${memberProfile?.additional.bio}*\n`; } description += `\n<@${member.id}>`; embed.setDescription(description); diff --git a/src/models/Member.ts b/src/models/Member.ts index e7023b5..fcd6aaa 100644 --- a/src/models/Member.ts +++ b/src/models/Member.ts @@ -5,6 +5,9 @@ export interface MemberInterface extends Document { additional: { langs: ['js', 'py', 'rb', 'ts', 'rs', 'go', 'cfam', 'csharp', 'swift', 'java', 'kt', 'asm'], operatingSystems: ['arch', 'deb', 'cent', 'fedora', 'manjaro', 'mdarwin', 'redhat', 'ubuntu', 'win'], + github: string, + gitlab: string, + bio: string, }, } @@ -13,6 +16,9 @@ const Member: Schema = new Schema({ additional: { langs: Array, operatingSystems: Array, + github: String, + gitlab: String, + bio: String, }, }); diff --git a/src/models/Staff.ts b/src/models/Staff.ts index 6bb6ad4..ec22b56 100644 --- a/src/models/Staff.ts +++ b/src/models/Staff.ts @@ -9,9 +9,6 @@ export interface StaffInterface extends Document { emailAddress: string, extension: string, acknowledgements: string[], - github: string, - gitlab: string, - bio: string, } const Staff: Schema = new Schema({ @@ -23,9 +20,6 @@ const Staff: Schema = new Schema({ emailAddress: String, extension: String, acknowledgements: Array, - github: String, - gitlab: String, - bio: String, }); export default model('Staff', Staff);