From 721262f7d37989b26f1d4add27dcbb33fcd35149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Mon, 18 May 2020 23:38:53 -0400 Subject: [PATCH 01/11] fixing djs command --- src/commands/djs.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/commands/djs.ts b/src/commands/djs.ts index 224150a..44e6367 100644 --- a/src/commands/djs.ts +++ b/src/commands/djs.ts @@ -17,10 +17,20 @@ export default class DJS extends Command { try { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - const { data }: AxiosResponse = await axios.get(`https://djsdocs.sorta.moe/v2/embed?src=master&q=${args[0]}`); + let res: AxiosResponse; + try { + res = await axios.get(`https://djsdocs.sorta.moe/v2/embed?src=master&q=${args[0]}`); + } catch (err) { + this.error(message.channel, 'Please try again later, something unexpected happened.'); + return this.client.util.handleError(err, message, this); + } + + const { data }: AxiosResponse = res; if (!data) return this.error(message.channel, 'Could not find information. Try something else.'); const embed = new RichEmbed(data); + embed.setFooter(this.client.user.username, this.client.user.avatarURL); + embed.setTimestamp(); return message.channel.createMessage({ embed }); } catch (err) { return this.client.util.handleError(err, message, this); From 5225a2bda2df354cd991e0e9a34c729cbf757223 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 19 May 2020 17:48:40 -0400 Subject: [PATCH 02/11] Apply suggestion to src/commands/djs.ts --- src/commands/djs.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/commands/djs.ts b/src/commands/djs.ts index 44e6367..c94a0c1 100644 --- a/src/commands/djs.ts +++ b/src/commands/djs.ts @@ -25,10 +25,9 @@ export default class DJS extends Command { return this.client.util.handleError(err, message, this); } - const { data }: AxiosResponse = res; - if (!data) return this.error(message.channel, 'Could not find information. Try something else.'); + if (!res.data) return this.error(message.channel, 'Could not find information. Try something else.'); - const embed = new RichEmbed(data); + const embed = new RichEmbed(res.data); embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setTimestamp(); return message.channel.createMessage({ embed }); From ed9a93715577159cf908408db0ea2d57127e26d3 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 19 May 2020 17:49:10 -0400 Subject: [PATCH 03/11] Apply suggestion to src/commands/djs.ts --- src/commands/djs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/djs.ts b/src/commands/djs.ts index c94a0c1..250fa95 100644 --- a/src/commands/djs.ts +++ b/src/commands/djs.ts @@ -17,7 +17,7 @@ export default class DJS extends Command { try { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - let res: AxiosResponse; + let res: AxiosResponse; try { res = await axios.get(`https://djsdocs.sorta.moe/v2/embed?src=master&q=${args[0]}`); } catch (err) { From 46c99ef7bf14a1042501cb685c08bb3619b39744 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 19 May 2020 17:49:24 -0400 Subject: [PATCH 04/11] Apply suggestion to src/commands/djs.ts --- src/commands/djs.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commands/djs.ts b/src/commands/djs.ts index 250fa95..405e0ac 100644 --- a/src/commands/djs.ts +++ b/src/commands/djs.ts @@ -21,8 +21,7 @@ export default class DJS extends Command { try { res = await axios.get(`https://djsdocs.sorta.moe/v2/embed?src=master&q=${args[0]}`); } catch (err) { - this.error(message.channel, 'Please try again later, something unexpected happened.'); - return this.client.util.handleError(err, message, this); + return this.error(message.channel, 'Please try again later, something unexpected happened.'); } if (!res.data) return this.error(message.channel, 'Could not find information. Try something else.'); From 0aea3d1bd2af5b65d3a4f9874e0a64a84771fb68 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 30 May 2020 10:09:31 -0400 Subject: [PATCH 05/11] Fix ban message --- src/commands/ban.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/ban.ts b/src/commands/ban.ts index b18a0ea..8d6e375 100644 --- a/src/commands/ban.ts +++ b/src/commands/ban.ts @@ -45,7 +45,7 @@ export default class Ban extends Command { if (reason.length > 512) return this.error(message.channel, 'Ban reasons cannot be longer than 512 characters.'); } await this.client.util.moderation.ban(user, message.member, momentMilliseconds, reason); - return this.success(message.channel, `${user.username}#${user.id} has been banned.`); + return this.success(message.channel, `${user.username}#${user.discriminator} has been banned.`); } catch (err) { return this.client.util.handleError(err, message, this, false); } From f9753b25fb8b190677168cd1e6c0ee8e0afdb3bc Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 1 Jun 2020 19:15:40 +0000 Subject: [PATCH 06/11] remove unneeded comments --- src/class/RichEmbed.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/class/RichEmbed.ts b/src/class/RichEmbed.ts index 38cf297..b4c99a6 100644 --- a/src/class/RichEmbed.ts +++ b/src/class/RichEmbed.ts @@ -30,14 +30,6 @@ export default class RichEmbed implements EmbedOptions { fields?: {name: string, value: string, inline?: boolean}[] constructor(data: EmbedOptions = {}) { - /* - let types: { - title?: string, type?: string, description?: string, url?: string, timestamp?: Date, color?: number, fields?: {name: string, value: string, inline?: boolean}[] - footer?: { text: string, icon_url?: string, proxy_icon_url?: string}, image?: { url?: string, proxy_url?: string, height?: number, width?: number }, - thumbnail?: { url?: string, proxy_url?: string, height?: number, width?: number }, video?: { url?: string, height?: number, width?: number }, - provider?: { name?: string, url?: string}, author?: { name?: string, url?: string, proxy_icon_url?: string, icon_url?: string} - }; - */ this.title = data.title; this.description = data.description; this.url = data.url; From 7a3ccd7bd71c1f9a5ade3426425358ed6e0ffac1 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 9 Jun 2020 23:19:20 +0100 Subject: [PATCH 07/11] Simplication --- src/commands/ban.ts | 6 +++--- src/commands/game.ts | 2 +- src/commands/kick.ts | 2 +- src/commands/roleinfo.ts | 4 ++-- src/commands/unban.ts | 2 +- src/commands/whois.ts | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/commands/ban.ts b/src/commands/ban.ts index 8d6e375..87c93c3 100644 --- a/src/commands/ban.ts +++ b/src/commands/ban.ts @@ -1,5 +1,5 @@ import moment, { unitOfTime } from 'moment'; -import { Message, User } from 'eris'; +import { Message, User, GuildTextableChannel } from 'eris'; import { Client, Command } from '../class'; export default class Ban extends Command { @@ -16,7 +16,7 @@ export default class Ban extends Command { public async run(message: Message, args: string[]) { try { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - const member = this.client.util.resolveMember(args[0], this.client.guilds.get(this.client.config.guildID)); + const member = this.client.util.resolveMember(args[0], message.guild); let user: User; if (!member) { try { @@ -28,7 +28,7 @@ export default class Ban extends Command { user = member.user; } try { - await this.client.guilds.get(this.client.config.guildID).getBan(args[0]); + await message.guild.getBan(args[0]); return this.error(message.channel, 'This user is already banned.'); } catch {} // eslint-disable-line no-empty if (member && !this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.'); diff --git a/src/commands/game.ts b/src/commands/game.ts index 40ecb6f..382b640 100644 --- a/src/commands/game.ts +++ b/src/commands/game.ts @@ -27,7 +27,7 @@ export default class Game extends Command { let member: Member; if (!args[0]) member = message.member; else { - member = this.client.util.resolveMember(args.join(' '), this.client.guilds.get(this.client.config.guildID)); + member = this.client.util.resolveMember(args.join(' '), message.guild); if (!member) { return this.error(message.channel, 'Member not found.'); } diff --git a/src/commands/kick.ts b/src/commands/kick.ts index 2bf5c51..8ad74e3 100644 --- a/src/commands/kick.ts +++ b/src/commands/kick.ts @@ -15,7 +15,7 @@ export default class Kick extends Command { public async run(message: Message, args: string[]) { try { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - let user: Member = this.client.util.resolveMember(args[0], this.client.guilds.get(this.client.config.guildID)); + let user: Member = this.client.util.resolveMember(args[0], message.guild); if (!user) { try { user = await this.client.getRESTGuildMember(this.client.config.guildID, args[0]); diff --git a/src/commands/roleinfo.ts b/src/commands/roleinfo.ts index fb39158..59ed6b4 100644 --- a/src/commands/roleinfo.ts +++ b/src/commands/roleinfo.ts @@ -17,9 +17,9 @@ export default class Roleinfo extends Command { try { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - let role: Role = this.client.guilds.get(this.client.config.guildID).roles.find((r: Role) => r.id === args[0]); + let role: Role = message.guild.roles.find((r: Role) => r.id === args[0]); if (!role) { // if it's a role name - role = this.client.guilds.get(this.client.config.guildID).roles.find((r: Role) => r.name.toLowerCase().includes(args.join(' ').toLowerCase())); + role = message.guild.roles.find((r: Role) => r.name.toLowerCase().includes(args.join(' ').toLowerCase())); } if (!role) return this.error(message.channel, 'Could not find role.'); diff --git a/src/commands/unban.ts b/src/commands/unban.ts index 3eb0cae..1bcfc9d 100644 --- a/src/commands/unban.ts +++ b/src/commands/unban.ts @@ -22,7 +22,7 @@ export default class Unban extends Command { return this.error(message.channel, 'Could find find user.'); } try { - await this.client.guilds.get(this.client.config.guildID).getBan(args[0]); + await message.guild.getBan(args[0]); } catch { return this.error(message.channel, 'This user is not banned.'); } diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 6b52b8e..9f56a6a 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -21,7 +21,7 @@ export default class Whois extends Command { let member: Member; if (!args[0]) member = message.member; else { - member = this.client.util.resolveMember(args.join(' '), this.client.guilds.get(this.client.config.guildID)); + member = this.client.util.resolveMember(args.join(' '), message.guild); } if (!member) { @@ -59,7 +59,7 @@ export default class Whois extends Command { description += `\n<@${member.id}>`; embed.setDescription(description); - for (const role of member.roles.map((r) => this.client.guilds.get(this.client.config.guildID).roles.get(r)).sort((a, b) => b.position - a.position)) { + for (const role of member.roles.map((r) => message.guild.roles.get(r)).sort((a, b) => b.position - a.position)) { if (role?.color !== 0) { embed.setColor(role.color); break; @@ -80,12 +80,12 @@ export default class Whois extends Command { 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) { - embed.addField(`Roles [${member.roles.length}]`, member.roles.map((r) => this.client.guilds.get(this.client.config.guildID).roles.get(r)).sort((a, b) => b.position - a.position).map((r) => `<@&${r.id}>`).join(', ')); + embed.addField(`Roles [${member.roles.length}]`, member.roles.map((r) => message.guild.roles.get(r)).sort((a, b) => b.position - a.position).map((r) => `<@&${r.id}>`).join(', ')); } const permissions: string[] = []; const serverAcknowledgements: string[] = []; const bit = member.permission.allow; - if (this.client.guilds.get(this.client.config.guildID).ownerID === member.id) serverAcknowledgements.push('Server Owner'); + if (message.guild.ownerID === member.id) serverAcknowledgements.push('Server Owner'); if ((bit | 8) === bit) { permissions.push('Administrator'); serverAcknowledgements.push('Server Admin'); } if ((bit | 32) === bit) { permissions.push('Manage Server'); serverAcknowledgements.push('Server Manager'); } if ((bit | 16) === bit) permissions.push('Manage Channels'); From e387d20f441547fc37891776b061b95e94cb88e5 Mon Sep 17 00:00:00 2001 From: Bsian Date: Wed, 10 Jun 2020 14:05:07 +0100 Subject: [PATCH 08/11] Clean up bitfield calculations --- src/commands/whois.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 9f56a6a..77c5156 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -86,15 +86,15 @@ export default class Whois extends Command { const serverAcknowledgements: string[] = []; const bit = member.permission.allow; if (message.guild.ownerID === member.id) serverAcknowledgements.push('Server Owner'); - if ((bit | 8) === bit) { permissions.push('Administrator'); serverAcknowledgements.push('Server Admin'); } - if ((bit | 32) === bit) { permissions.push('Manage Server'); serverAcknowledgements.push('Server Manager'); } - if ((bit | 16) === bit) permissions.push('Manage Channels'); - if ((bit | 268435456) === bit) permissions.push('Manage Roles'); - if ((bit | 8192) === bit) { permissions.push('Manage Messages'); serverAcknowledgements.push('Server Moderator'); } - if ((bit | 134217728) === bit) permissions.push('Manage Nicknames'); - if ((bit | 1073741824) === bit) permissions.push('Manage Emojis'); - if ((bit | 4) === bit) permissions.push('Ban Members'); - if ((bit | 2) === bit) permissions.push('Kick Members'); + if (bit & 8) { permissions.push('Administrator'); serverAcknowledgements.push('Server Admin'); } + if (bit & 32) { permissions.push('Manage Server'); serverAcknowledgements.push('Server Manager'); } + if (bit & 16) permissions.push('Manage Channels'); + if (bit & 268435456) permissions.push('Manage Roles'); + if (bit & 8192) { permissions.push('Manage Messages'); serverAcknowledgements.push('Server Moderator'); } + if (bit & 134217728) permissions.push('Manage Nicknames'); + if (bit & 1073741824) permissions.push('Manage Emojis'); + if (bit & 4) permissions.push('Ban Members'); + if (bit & 2) permissions.push('Kick Members'); const account = await this.client.db.Member.findOne({ userID: member.id }); if (account?.additional?.langs.length > 0) { const langs: string[] = []; From 1786239f6ad1c0c46e395781d9d11506bf50e82f Mon Sep 17 00:00:00 2001 From: Bsian Date: Wed, 10 Jun 2020 14:13:38 +0100 Subject: [PATCH 09/11] Fix status checker --- src/commands/whois.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 77c5156..4e7c9b6 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -65,9 +65,7 @@ export default class Whois extends Command { break; } } - if (member.status) { - embed.addField('Status', `${member.status[0].toUpperCase()}${member.status.slice(1)}`, true); - } + embed.addField('Status', member.status === 'dnd' ? 'Do Not Disturb' : `${member.status?.substring(0, 1).toUpperCase()}${member.status?.substring(1)}` || 'Unknown', true); if (member.bot) { embed.addField('Platform', 'API/WebSocket', true); } else if (member.clientStatus?.web === 'online' || member.clientStatus?.web === 'idle' || member.clientStatus?.web === 'dnd') { From e55dcfc7dda8f7df6471939f3d7683c836540d8b Mon Sep 17 00:00:00 2001 From: Bsian Date: Wed, 10 Jun 2020 14:28:02 +0100 Subject: [PATCH 10/11] Clean up and improve platform calculation --- src/commands/whois.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 4e7c9b6..47ce288 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -65,16 +65,10 @@ export default class Whois extends Command { break; } } - embed.addField('Status', member.status === 'dnd' ? 'Do Not Disturb' : `${member.status?.substring(0, 1).toUpperCase()}${member.status?.substring(1)}` || 'Unknown', true); - if (member.bot) { - embed.addField('Platform', 'API/WebSocket', true); - } else if (member.clientStatus?.web === 'online' || member.clientStatus?.web === 'idle' || member.clientStatus?.web === 'dnd') { - embed.addField('Platform', 'Web', true); - } else if (member.clientStatus?.desktop === 'online' || member.clientStatus?.desktop === 'idle' || member.clientStatus?.desktop === 'dnd') { - embed.addField('Platform', 'Desktop', true); - } else if (member.clientStatus?.mobile === 'online' || member.clientStatus?.mobile === 'idle' || member.clientStatus?.mobile === 'dnd') { - embed.addField('Platform', 'Mobile', true); - } + embed.addField('Status', member.status === 'dnd' ? 'Do Not Disturb' : this.capsFirstLetter(member.status) || 'Unknown', true); + const platform = Object.entries(message.member.clientStatus).filter((a) => a[1] !== 'offline').map((a) => this.capsFirstLetter(a[0])); + if (member.bot) platform.push('API/WebSocket'); + if (platform.length) embed.addField('Platform', platform.join(', '), 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) { @@ -197,4 +191,9 @@ export default class Whois extends Command { public resolveStaffInformation(id: string) { return acknowledgements.find((m) => m.id === id); } + + public capsFirstLetter(string?: string): string | void { + if (typeof string !== 'string') return undefined; + return string.substring(0, 1).toUpperCase() + string.substring(1); + } } From fbf28dbdb2d3cd419dd4ef850502f453472eb9b3 Mon Sep 17 00:00:00 2001 From: Bsian Date: Wed, 10 Jun 2020 16:03:33 +0100 Subject: [PATCH 11/11] More plaform fix improvements Fixes #11 --- src/commands/whois.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 47ce288..4ca1969 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -66,9 +66,8 @@ export default class Whois extends Command { } } embed.addField('Status', member.status === 'dnd' ? 'Do Not Disturb' : this.capsFirstLetter(member.status) || 'Unknown', true); - const platform = Object.entries(message.member.clientStatus).filter((a) => a[1] !== 'offline').map((a) => this.capsFirstLetter(a[0])); - if (member.bot) platform.push('API/WebSocket'); - if (platform.length) embed.addField('Platform', platform.join(', '), true); + const platform = member.bot && member.status !== 'offline' ? 'API/WebSocket' : Object.entries(message.member.clientStatus).filter((a) => a[1] !== 'offline').map((a) => this.capsFirstLetter(a[0])).join(', '); + if (platform) embed.addField('Platform', platform, 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) {