From b0aadbc73e42b3865b1cefdeec98e2c6c12b321f Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 20 Apr 2020 14:30:28 -0400 Subject: [PATCH 01/10] ack updates --- src/configs/acknowledgements.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/configs/acknowledgements.json b/src/configs/acknowledgements.json index 463ecda..c7e92d3 100644 --- a/src/configs/acknowledgements.json +++ b/src/configs/acknowledgements.json @@ -97,12 +97,19 @@ { "name": "Hector", "id": "377781496292835339", - "title": "Core Team", + "title": "Associate", "emailAddress": "hector@staff.libraryofcode.org", "gitlab": "https://gitlab.libraryofcode.org/Hector", "github": "https://github.com/Hector6704", "bio": "Hi there, I'm the developer of Delta, the Discord bot. I'm a free-time French JavaScript developer. I hope you'll enjoy LOC!" }, + { + "name": "Realitus", + "id": "156450671338586112", + "title": "Associate", + "github": "https://github.com/Realitus", + "bio": "A hobbyist software developer with some rather strange ideas, and even stranger implementations." + }, { "name": "KhaaZ", "id": "179908288337412096", From 4f55e2909405b9608eedd1d445cf95d580ba8fdb Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 21 Apr 2020 18:53:12 +0100 Subject: [PATCH 02/10] Fix hex parsing --- src/class/Util.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index f31a4ca..10a0702 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -119,11 +119,7 @@ export default class Util { } public decimalToHex(int: number): string { - const red = (int && 0x0000ff) << 16; - const green = int && 0x00ff00; - const blue = (int && 0xff0000) >>> 16; - const number = red | green | blue; - const asHex = number.toString(16); - return '#000000'.substring(0, 7 - asHex.length) + asHex; + const hex = int.toString(16); + return '#000000'.substring(0, 7 - hex.length) + hex; } } From 6cf4f9c8e3f91a90c76a1a5601e121f97247b091 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Wed, 22 Apr 2020 14:45:49 -0400 Subject: [PATCH 03/10] perms fix (@dedshot) --- src/class/Command.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/class/Command.ts b/src/class/Command.ts index 7fc00f5..7a2e5c5 100644 --- a/src/class/Command.ts +++ b/src/class/Command.ts @@ -68,8 +68,10 @@ export default class Command { case 4: return member.roles.some((r) => ['701454780828221450', '701454855952138300', '662163685439045632'].includes(r)); case 5: - return member.roles.some((r) => ['701454855952138300', '662163685439045632'].includes(r)); + return member.roles.some((r) => ['455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r)); case 6: + return member.roles.some((r) => ['701454855952138300', '662163685439045632'].includes(r)); + case 7: return member.roles.includes('662163685439045632'); default: return false; From cd6a10480b3a4542c9627df7d6fdb92187570c5e Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 24 Apr 2020 18:57:56 -0400 Subject: [PATCH 04/10] platform information in whois cmd --- src/commands/whois.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index ece051c..8ca5ff0 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -68,6 +68,15 @@ export default class Whois extends Command { } } embed.addField('Status', `${member.status[0].toUpperCase()}${member.status.slice(1)}`, true); + if (member.bot) { + embed.addField('Platform', 'API/WebSocket', true); + } else if (member.clientStatus.web) { + embed.addField('Platform', 'Web', true); + } else if (member.clientStatus.desktop) { + embed.addField('Platform', 'Desktop', true); + } else if (member.clientStatus.mobile) { + embed.addField('Platform', 'Mobile', true); + } embed.addField('Joined At', `${moment(new Date(member.joinedAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true); embed.addField('Created At', `${moment(new Date(member.user.createdAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true); if (member.roles.length > 0) { From 9ddc800e2a30f60600fa700e01eb460deb084ef1 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 24 Apr 2020 23:46:29 -0400 Subject: [PATCH 05/10] add new Member model --- src/class/Client.ts | 6 +++--- src/models/Member.ts | 17 +++++++++++++++++ src/models/index.ts | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/models/Member.ts diff --git a/src/class/Client.ts b/src/class/Client.ts index 589ff0f..29212bb 100644 --- a/src/class/Client.ts +++ b/src/class/Client.ts @@ -2,7 +2,7 @@ import eris from 'eris'; import mongoose from 'mongoose'; import { promises as fs } from 'fs'; import { Collection, Command, Util } from '.'; -import { Moderation, ModerationInterface } from '../models'; +import { Member, MemberInterface, Moderation, ModerationInterface } from '../models'; export default class Client extends eris.Client { public config: { token: string, prefix: string, guildID: string, mongoDB: string }; @@ -13,14 +13,14 @@ export default class Client extends eris.Client { public util: Util; - public db: { moderation: mongoose.Model }; + public db: { member: mongoose.Model, moderation: mongoose.Model }; // eslint-disable-next-line @typescript-eslint/no-useless-constructor constructor(token: string, options?: eris.ClientOptions) { super(token, options); this.commands = new Collection(); this.intervals = new Collection(); - this.db = { moderation: Moderation }; + this.db = { member: Member, moderation: Moderation }; } public async loadDatabase() { diff --git a/src/models/Member.ts b/src/models/Member.ts new file mode 100644 index 0000000..f8c496b --- /dev/null +++ b/src/models/Member.ts @@ -0,0 +1,17 @@ +import { Document, Schema, model } from 'mongoose'; + +export interface MemberInterface extends Document { + userID: string + additional: { + langs: ['js', 'py', 'rb', 'ts', 'rs', 'go', 'cfam', 'csharp', 'swift', 'java', 'kt', 'asm'], + }, +} + +const Member: Schema = new Schema({ + userID: String, + additional: { + langs: Array, + }, +}); + +export default model('Member', Member); diff --git a/src/models/index.ts b/src/models/index.ts index a149275..81202ce 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1 +1,2 @@ +export { default as Member, MemberInterface } from './Member'; export { default as Moderation, ModerationInterface } from './Moderation'; From 07951e289f705aa5c45cb0906d6d1cebaae17067 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 24 Apr 2020 23:46:43 -0400 Subject: [PATCH 06/10] fix typo in roleinfo (@dedshot) --- src/commands/roleinfo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/roleinfo.ts b/src/commands/roleinfo.ts index 9fc6052..a617ec3 100644 --- a/src/commands/roleinfo.ts +++ b/src/commands/roleinfo.ts @@ -15,7 +15,7 @@ export default class Roleinfo extends Command { public async run(message: Message, args: string[]) { try { - if (!args[0]) return this.error(message.channel, 'You need to specifiy a role ID or a role name.'); + if (!args[0]) return this.error(message.channel, 'You need to specify a role ID or a role name.'); let role: Role = this.client.guilds.get(this.client.config.guildID).roles.find((r: Role) => r.id === args[0]); if (!role) { // if it's a role name From ebdb1671e22f7e3b02ca4bf6fb36e5e36326b735 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 24 Apr 2020 23:46:54 -0400 Subject: [PATCH 07/10] add command to add known langs --- src/commands/additem.ts | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/commands/additem.ts diff --git a/src/commands/additem.ts b/src/commands/additem.ts new file mode 100644 index 0000000..f99d524 --- /dev/null +++ b/src/commands/additem.ts @@ -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); + } + } +} From f052fa76058f2753bf9c069101b3f3e2bdf9ba00 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 24 Apr 2020 23:47:07 -0400 Subject: [PATCH 08/10] add known languages list to whois --- src/commands/whois.ts | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 8ca5ff0..172afaf 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -95,6 +95,50 @@ export default class Whois extends Command { if ((bit | 1073741824) === bit) permissions.push('Manage Emojis'); if ((bit | 4) === bit) permissions.push('Ban Members'); if ((bit | 2) === bit) permissions.push('Kick Members'); + const account = await this.client.db.member.findOne({ userID: member.id }); + if (account?.additional?.langs.length > 0) { + const langs: string[] = []; + for (const lang of account.additional.langs) { + switch (lang) { + case 'asm': + langs.push('<:AssemblyLanguage:703448714248716442> Assembly Language'); + break; + case 'cfam': + langs.push('<:clang:553684262193332278> C/C++'); + break; + case 'go': + langs.push('<:Go:703449475405971466> Go'); + break; + case 'java': + langs.push('<:Java:703449725181100135> Java'); + break; + case 'js': + langs.push('<:JavaScriptECMA:703449987916496946> JavaScript'); + break; + case 'kt': + langs.push('<:Kotlin:703450201838321684> Kotlin'); + break; + case 'py': + langs.push('<:python:553682965482176513> Python'); + break; + case 'rb': + langs.push('<:ruby:604812470451699712> Ruby'); + break; + case 'rs': + langs.push('<:Rust:703450901960196206> Rust'); + break; + case 'swift': + langs.push('<:Swift:703451096093294672> Swift'); + break; + case 'ts': + langs.push('<:TypeScript:703451285789343774> TypeScript'); + break; + default: + break; + } + } + embed.addField('Known Languages', langs.join(', ')); + } if (permissions.length > 0) { embed.addField('Permissions', permissions.join(', ')); } From 3edcebae4362a183195f2677ad066cace5250b02 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 25 Apr 2020 00:01:40 -0400 Subject: [PATCH 09/10] fix issue with whois platform --- src/commands/whois.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 172afaf..96b9de5 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -70,11 +70,11 @@ export default class Whois extends Command { embed.addField('Status', `${member.status[0].toUpperCase()}${member.status.slice(1)}`, true); if (member.bot) { embed.addField('Platform', 'API/WebSocket', true); - } else if (member.clientStatus.web) { + } else if (member.clientStatus.web === 'online' || member.clientStatus.web === 'idle' || member.clientStatus.web === 'dnd') { embed.addField('Platform', 'Web', true); - } else if (member.clientStatus.desktop) { + } else if (member.clientStatus.desktop === 'online' || member.clientStatus.desktop === 'idle' || member.clientStatus.desktop === 'dnd') { embed.addField('Platform', 'Desktop', true); - } else if (member.clientStatus.mobile) { + } else if (member.clientStatus.mobile === 'online' || member.clientStatus.mobile === 'idle' || member.clientStatus.mobile === 'dnd') { embed.addField('Platform', 'Mobile', true); } embed.addField('Joined At', `${moment(new Date(member.joinedAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true); From b44289f51e76e3caf269cfb565e4e26ade6778ae Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 25 Apr 2020 00:09:40 -0400 Subject: [PATCH 10/10] delitem cmd --- src/commands/delitem.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/commands/delitem.ts diff --git a/src/commands/delitem.ts b/src/commands/delitem.ts new file mode 100644 index 0000000..d62bff1 --- /dev/null +++ b/src/commands/delitem.ts @@ -0,0 +1,37 @@ +import { Message } from 'eris'; +import { Client, Command, RichEmbed } from '../class'; + +export default class DelItem extends Command { + constructor(client: Client) { + super(client); + this.name = 'delitem'; + this.description = 'Removes information to your whois embed.'; + this.usage = 'delitem [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 || !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 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); + } + } +}