From fd70db8b73d6e903792e7989a651ffb8668137c0 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Wed, 6 May 2020 17:05:50 -0400 Subject: [PATCH] add operating systems to whois --- src/commands/additem.ts | 21 ++++++++++++++++++--- src/commands/delitem.ts | 15 ++++++++++++--- src/commands/whois.ts | 31 +++++++++++++++++++++++++++++++ src/models/Member.ts | 2 ++ 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/commands/additem.ts b/src/commands/additem.ts index 666489d..a23f12f 100644 --- a/src/commands/additem.ts +++ b/src/commands/additem.ts @@ -17,11 +17,27 @@ export default class AddItem extends Command { 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.addField('Operating Systems', '**Arch:** os-arch\n**Debian:** os-deb\n**Fedora:** os-fedora\n**macOS:** os-mdarwin\n**RedHat:** os-redhat\n**Ubuntu:** os-ubuntu\n**Windows:** os-win'); 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])) { + if (args[0].split('-')[0] === 'os' && ['arch', 'deb', 'fedora', 'mdarwin', 'redhat', 'ubuntu', 'win'].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: { + operatingSystems: [args[0].split('-')[1]], + }, + }); + await newAccount.save(); + } + await account.updateOne({ $addToSet: { 'additional.operatingSystems': args[0].split('-')[1] } }); + return message.channel.createMessage(`***${this.client.util.emojis.SUCCESS} Added OS code ${args[0]} to profile.***`); + } + if (args[0].split('-')[0] === 'lang' && ['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 @@ -32,12 +48,11 @@ export default class AddItem extends Command { }, }); await newAccount.save(); - return message.channel.createMessage(`***${this.client.util.emojis.SUCCESS} Added language 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 language code ${args[0]} to profile.***`); } - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Invalid language code.***`); + return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Invalid data code.***`); } catch (err) { return this.client.util.handleError(err, message, this); } diff --git a/src/commands/delitem.ts b/src/commands/delitem.ts index cf802d2..920922c 100644 --- a/src/commands/delitem.ts +++ b/src/commands/delitem.ts @@ -17,19 +17,28 @@ export default class DelItem extends Command { 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.addField('Operating Systems', '**Arch:** os-arch\n**Debian:** os-deb\n**Fedora:** os-fedora\n**macOS:** os-mdarwin\n**RedHat:** os-redhat\n**Ubuntu:** os-ubuntu\n**Windows:** os-win'); 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])) { + if (args[0].split('-')[0] === 'os' && ['arch', 'deb', 'fedora', 'mdarwin', 'redhat', 'ubuntu', 'win'].includes(args[0].split('-')[1])) { + const account = await this.client.db.member.findOne({ userID: message.member.id }); + if (!account || !account?.additional.operatingSystems || account?.additional.operatingSystems.length < 1) { + return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You don't have any operating systems to remove.***`); + } + await account.updateOne({ $pull: { 'additional.operatingSystems': args[0].split('-')[1] } }); + return message.channel.createMessage(`***${this.client.util.emojis.SUCCESS} Removed OS code ${args[0]} from profile.***`); + } + if (args[0].split('-')[0] === 'lang' && ['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 || !account?.additional.langs || account?.additional.langs.length < 1) { return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You don't have any languages to remove.***`); } await account.updateOne({ $pull: { 'additional.langs': args[0].split('-')[1] } }); - return message.channel.createMessage(`***${this.client.util.emojis.SUCCESS} Removed language code ${args[0]} to profile.***`); + return message.channel.createMessage(`***${this.client.util.emojis.SUCCESS} Removed language code ${args[0]} from profile.***`); } - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Invalid language code.***`); + return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Invalid data code.***`); } catch (err) { return this.client.util.handleError(err, message, this); } diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 80fde1a..96420e0 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -142,6 +142,37 @@ export default class Whois extends Command { } embed.addField('Known Languages', langs.join(', ')); } + if (account?.additional?.operatingSystems.length > 0) { + const operatingSystems: string[] = []; + for (const os of account.additional.operatingSystems.sort((a, b) => a.localeCompare(b))) { + switch (os) { + case 'arch': + operatingSystems.push('<:arch:707694976523304960> Arch'); + break; + case 'deb': + operatingSystems.push('<:debian:707695042617147589> Debian'); + break; + case 'fedora': + operatingSystems.push('<:fedora:707695073151680543> Fedora'); + break; + case 'mdarwin': + operatingSystems.push('<:mac:707695427754917919> macOS'); + break; + case 'redhat': + operatingSystems.push('<:redhat:707695102159749271> RedHat Enterprise Linux'); + break; + case 'ubuntu': + operatingSystems.push('<:ubuntu:707695136888586300> Ubuntu'); + break; + case 'win': + operatingSystems.push('<:windows10:707695160259248208> Windows'); + break; + default: + break; + } + } + embed.addField('Used Operating Systems', operatingSystems.join(', ')); + } if (permissions.length > 0) { embed.addField('Permissions', permissions.join(', ')); } diff --git a/src/models/Member.ts b/src/models/Member.ts index f8c496b..63a0a62 100644 --- a/src/models/Member.ts +++ b/src/models/Member.ts @@ -4,6 +4,7 @@ export interface MemberInterface extends Document { userID: string additional: { langs: ['js', 'py', 'rb', 'ts', 'rs', 'go', 'cfam', 'csharp', 'swift', 'java', 'kt', 'asm'], + operatingSystems: ['arch', 'deb', 'fedora', 'mdarwin', 'redhat', 'ubuntu', 'win'], }, } @@ -11,6 +12,7 @@ const Member: Schema = new Schema({ userID: String, additional: { langs: Array, + operatingSystems: Array, }, });