fix hiro's fuckups

merge-requests/21/merge
Matthew 2021-03-05 23:20:42 -05:00
parent 0961729a1d
commit f40dae8b4d
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
7 changed files with 45 additions and 13 deletions

View File

@ -29,6 +29,7 @@ export { default as npm } from './npm';
export { default as offer } from './offer'; export { default as offer } from './offer';
export { default as page } from './page'; export { default as page } from './page';
export { default as ping } from './ping'; export { default as ping } from './ping';
export { default as profile } from './profile';
export { default as pulldata } from './pulldata'; export { default as pulldata } from './pulldata';
export { default as rank } from './rank'; export { default as rank } from './rank';
export { default as roleinfo } from './roleinfo'; export { default as roleinfo } from './roleinfo';

View File

@ -1,17 +1,22 @@
import { Message } from 'eris'; import { Message } from 'eris';
import { Client, Command } from '../class'; 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 { export default class Profile extends Command {
constructor(client: Client) { constructor(client: Client) {
super(client); super(client);
this.name = 'profile'; this.name = 'profile';
this.description = 'Manages your profile on CR'; this.description = 'Manages your profile on CR.';
this.usage = 'profile <bio/github/gitlab> <new value>'; this.usage = 'profile <bio/github/gitlab> <new value>\n*Provide no value in subcommand to clear data.';
this.permissions = 0; this.permissions = 0;
this.enabled = true; 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 })) { if (!await this.client.db.Member.exists({ userID: message.author.id })) {
await this.client.db.Member.create({ userID: message.author.id }); await this.client.db.Member.create({ userID: message.author.id });
} }

View File

@ -15,16 +15,25 @@ export default class Profile_Bio extends Command {
if (!await this.client.db.Member.exists({ userID: message.author.id })) { if (!await this.client.db.Member.exists({ userID: message.author.id })) {
await this.client.db.Member.create({ 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(' '); 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.'); 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({ await member.updateOne({
additional: { additional: {
...member.additional, ...member.additional,
bio, bio,
}, },
}); });
return message.addReaction('modSuccess:578750988907970567');
} }
} }

View File

@ -15,7 +15,16 @@ export default class Profile_GitHub extends Command {
if (!await this.client.db.Member.exists({ userID: message.author.id })) { if (!await this.client.db.Member.exists({ userID: message.author.id })) {
await this.client.db.Member.create({ 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( const urlRegex = new RegExp(
'^(https?:\\/\\/)?' '^(https?:\\/\\/)?'
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + '((([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.'); 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({ await member.updateOne({
additional: { additional: {
...member.additional, ...member.additional,
github: args[0], github: args[0],
}, },
}); });
return message.addReaction('modSuccess:578750988907970567');
} }
} }

View File

@ -16,6 +16,16 @@ export default class Profile_GitLab extends Command {
await this.client.db.Member.create({ 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.'); 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( const urlRegex = new RegExp(
'^(https?:\\/\\/)?' '^(https?:\\/\\/)?'
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + '((([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_]*)?$', + '(\\#[-a-z\\d_]*)?$',
'i', '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({ await member.updateOne({
additional: { additional: {
...member.additional, ...member.additional,
gitlab: args[0], gitlab: args[0],
}, },
}); });
return message.addReaction('modSuccess:578750988907970567');
} }
} }

View File

@ -56,7 +56,7 @@ export default class Whois extends Command {
if (ackResolve?.extension) { if (ackResolve?.extension) {
description += `☎️ ${ackResolve.extension}\n`; 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) { if (memberProfile?.additional?.gitlab) {
description += `${emotes.gitlab} ${memberProfile?.additional.gitlab}\n`; description += `${emotes.gitlab} ${memberProfile?.additional.gitlab}\n`;
} }

View File

@ -9,7 +9,6 @@ export interface MemberInterface extends Document {
gitlab: string, gitlab: string,
bio: string, bio: string,
}, },
bio: string,
} }
const Member: Schema = new Schema({ const Member: Schema = new Schema({
@ -21,7 +20,6 @@ const Member: Schema = new Schema({
gitlab: String, gitlab: String,
bio: String, bio: String,
}, },
bio: String,
}); });
export default model<MemberInterface>('Member', Member); export default model<MemberInterface>('Member', Member);