39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
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 <GitHub profile URL>`;
|
|
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],
|
|
},
|
|
});
|
|
}
|
|
}
|