add command to add known langs

merge-requests/12/head
Matthew 2020-04-24 23:46:54 -04:00 committed by Bsian
parent 15eee459d1
commit 2a87dd253c
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 45 additions and 0 deletions

45
src/commands/additem.ts Normal file
View File

@ -0,0 +1,45 @@
import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class';
export default class AddItem extends Command {
constructor(client: Client) {
super(client);
this.name = 'additem';
this.description = 'Adds information to your whois embed.';
this.usage = 'additem [code]';
this.permissions = 0;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (args.length < 1) {
const embed = new RichEmbed();
embed.setTitle('Whois Data Codes');
embed.addField('Languages', '**Assembly Language:** lang-asm\n**C/C++:** lang-cfam\n**C#:** lang-csharp\n**Go:** lang-go\n**Java:** lang-java\n**JavaScript:** lang-js\n**Kotlin:** lang-kt\n**Python:** lang-py\n**Ruby:** lang-rb\n**Rust:** lang-rs\n**Swift:** lang-swift\n**TypeScript:** lang-ts');
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
return message.channel.createMessage({ embed });
}
if (['js', 'py', 'rb', 'ts', 'rs', 'go', 'cfam', 'csharp', 'swift', 'java', 'kt', 'asm'].includes(args[0].split('-')[1])) {
const account = await this.client.db.member.findOne({ userID: message.member.id });
if (!account) {
// eslint-disable-next-line new-cap
const newAccount = new this.client.db.member({
userID: message.member.id,
additional: {
langs: [args[0].split('-')[1]],
},
});
await newAccount.save();
return message.channel.createMessage(`***${this.client.util.emojis.SUCCESS} Added langauge code ${args[0]} to profile.***`);
}
await account.updateOne({ $addToSet: { 'additional.langs': args[0].split('-')[1] } });
return message.channel.createMessage(`***${this.client.util.emojis.SUCCESS} Added langauge code ${args[0]} to profile.***`);
}
return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Invalid language code.***`);
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}