From cfe5e65ed892cea71f19d219d5dfb2518ec65137 Mon Sep 17 00:00:00 2001 From: Bsian Date: Fri, 17 Apr 2020 03:56:52 +0100 Subject: [PATCH 01/20] Fix everything Matt please don't change the ECMA target --- package.json | 2 +- src/class/Collection.ts | 12 ++++++------ src/class/Command.ts | 14 +++++++++++++- src/class/Moderation.ts | 5 +++-- src/class/RichEmbed.ts | 27 ++++++++++++++++++--------- src/class/Util.ts | 32 +++++++++++++++++++++++--------- src/commands/ban.ts | 19 ++++++++----------- src/commands/eval.ts | 4 ++-- src/commands/game.ts | 11 +++++------ src/commands/roleinfo.ts | 24 +++++++++--------------- src/commands/unban.ts | 14 +++----------- src/commands/whois.ts | 30 +++++++++++++----------------- src/events/ready.ts | 4 ++-- tsconfig.json | 2 +- 14 files changed, 107 insertions(+), 93 deletions(-) diff --git a/package.json b/package.json index 81eb46a..0fbd1f2 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "axios": "^0.19.2", - "eris": "^0.11.2", + "eris": "abalabahaha/eris#dev", "moment": "^2.24.0", "mongoose": "^5.9.9", "signale": "^1.4.0", diff --git a/src/class/Collection.ts b/src/class/Collection.ts index 80120b4..044e12c 100644 --- a/src/class/Collection.ts +++ b/src/class/Collection.ts @@ -2,12 +2,12 @@ * Hold a bunch of something */ export default class Collection extends Map { - baseObject: any + baseObject: new (...args: any[]) => V; /** * Creates an instance of Collection */ - constructor(iterable: any[]|object = null) { + constructor(iterable: Iterable<[string, V]>|object = null) { if (iterable && iterable instanceof Array) { super(iterable); } else if (iterable && iterable instanceof Object) { @@ -33,8 +33,8 @@ export default class Collection extends Map { * { key: value, key: value, key: value } * ``` */ - toObject(): object { - const obj: object = {}; + toObject(): { [key: string]: V } { + const obj: { [key: string]: V } = {}; for (const [key, value] of this.entries()) { obj[key] = value; } @@ -90,7 +90,7 @@ export default class Collection extends Map { * Return all the objects that make the function evaluate true * @param func A function that takes an object and returns true if it matches */ - filter(func: Function): V[] { + filter(func: (value: V) => boolean): V[] { const arr = []; for (const item of this.values()) { if (func(item)) { @@ -104,7 +104,7 @@ export default class Collection extends Map { * Test if at least one element passes the test implemented by the provided function. Returns true if yes, or false if not. * @param func A function that takes an object and returns true if it matches */ - some(func: Function) { + some(func: (value: V) => boolean) { for (const item of this.values()) { if (func(item)) { return true; diff --git a/src/class/Command.ts b/src/class/Command.ts index 9a8fc92..2fa7faa 100644 --- a/src/class/Command.ts +++ b/src/class/Command.ts @@ -1,4 +1,4 @@ -import { Member, Message } from 'eris'; +import { Member, Message, TextableChannel } from 'eris'; import { Client } from '.'; export default class Command { @@ -68,4 +68,16 @@ export default class Command { return false; } } + + public error(channel: TextableChannel, text: string): Promise { + return channel.createMessage(`***${this.client.util.emojis.ERROR} ${text}***`); + } + + public success(channel: TextableChannel, text: string): Promise { + return channel.createMessage(`***${this.client.util.emojis.SUCCESS} ${text}***`); + } + + public loading(channel: TextableChannel, text: string): Promise { + return channel.createMessage(`***${this.client.util.emojis.LOADING} ${text}***`); + } } diff --git a/src/class/Moderation.ts b/src/class/Moderation.ts index 13ba195..71fcb22 100644 --- a/src/class/Moderation.ts +++ b/src/class/Moderation.ts @@ -41,13 +41,14 @@ export default class Moderation { } public async ban(user: User, moderator: Member, duration: number, reason?: string): Promise { + if (reason && reason.length > 512) throw new Error('Ban reason cannot be longer than 512 characters'); await this.client.guilds.get(this.client.config.guildID).banMember(user.id, 7, reason); const logID = uuid(); const mod = new ModerationModel({ userID: user.id, logID, moderatorID: moderator.id, - reason: reason ?? null, + reason: reason || null, type: 5, date: new Date(), }); @@ -89,7 +90,7 @@ export default class Moderation { userID, logID, moderatorID: moderator.id, - reason: reason ?? null, + reason: reason || null, type: 4, date: new Date(), }); diff --git a/src/class/RichEmbed.ts b/src/class/RichEmbed.ts index 4f95f3b..307f9c5 100644 --- a/src/class/RichEmbed.ts +++ b/src/class/RichEmbed.ts @@ -1,6 +1,20 @@ /* eslint-disable no-param-reassign */ -export default class RichEmbed { +export interface EmbedData { + title?: string + description?: string + url?: string + timestamp?: Date + color?: number + 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 } + author?: { name: string, url?: string, proxy_icon_url?: string, icon_url?: string} + fields?: {name: string, value: string, inline?: boolean}[] +} + +export default class RichEmbed implements EmbedData { title?: string type?: string @@ -17,7 +31,7 @@ export default class RichEmbed { image?: { url: string, proxy_url?: string, height?: number, width?: number } - thumbnail?: { 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 } @@ -27,12 +41,7 @@ export default class RichEmbed { fields?: {name: string, value: string, inline?: boolean}[] - constructor(data: { - 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}, - } = {}) { + constructor(data: EmbedData = {}) { /* let types: { title?: string, type?: string, description?: string, url?: string, timestamp?: Date, color?: number, fields?: {name: string, value: string, inline?: boolean}[] @@ -79,7 +88,7 @@ export default class RichEmbed { setURL(url: string) { if (typeof url !== 'string') throw new TypeError('RichEmbed URLs must be a string.'); if (!url.startsWith('http://') || !url.startsWith('https://')) url = `https://${url}`; - this.url = url; + this.url = encodeURI(url); return this; } diff --git a/src/class/Util.ts b/src/class/Util.ts index 1c6d3e9..f31a4ca 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-bitwise */ import signale from 'signale'; import { Member, Message, Guild, PrivateChannel, GroupChannel, Role, AnyGuildChannel } from 'eris'; import { Client, Command, Moderation, RichEmbed } from '.'; @@ -50,19 +51,23 @@ export default class Util { } } - public resolveGuildChannel(query: string, { channels }: Guild): AnyGuildChannel | undefined { - const nchannels = channels.map((c) => c).sort((a: AnyGuildChannel, b: AnyGuildChannel) => a.type - b.type); - return nchannels.find((c) => (c.id === query || c.name === query || c.name.toLowerCase() === query.toLowerCase() || c.name.toLowerCase().startsWith(query.toLowerCase()))); + public resolveGuildChannel(query: string, { channels }: Guild, categories = false): AnyGuildChannel | undefined { + const ch: AnyGuildChannel[] = channels.filter((c) => (!categories ? c.type !== 4 : true)); + return ch.find((c) => c.id === query.replace(/[<#>]/g, '') || c.name === query) + || ch.find((c) => c.name.toLowerCase() === query.toLowerCase()) + || ch.find((c) => c.name.toLowerCase().startsWith(query.toLowerCase())); } public resolveRole(query: string, { roles }: Guild): Role | undefined { - return roles.find((r) => r.id === query || r.name === query || r.name.toLowerCase() === query.toLowerCase() || r.name.toLowerCase().startsWith(query.toLowerCase())); + return roles.find((r) => r.id === query.replace(/[<@&>]/g, '') || r.name === query) + || roles.find((r) => r.name.toLowerCase() === query.toLowerCase()) + || roles.find((r) => r.name.toLowerCase().startsWith(query.toLowerCase())); } public resolveMember(query: string, { members }: Guild): Member | undefined { - return members.find((m) => m.mention.replace('!', '') === query.replace('!', '') || `${m.username}#${m.discriminator}` === query || m.username === query || m.id === query || m.nick === query) // Exact match for mention, username+discrim, username and user ID - || members.find((m) => `${m.username.toLowerCase()}#${m.discriminator}` === query.toLowerCase() || m.username.toLowerCase() === query.toLowerCase() || (m.nick && m.nick.toLowerCase() === query.toLowerCase())) // Case insensitive match for username+discrim, username - || members.find((m) => m.username.toLowerCase().startsWith(query.toLowerCase()) || (m.nick && m.nick.toLowerCase().startsWith(query.toLowerCase()))); + return members.find((m) => `${m.username}#${m.discriminator}` === query || m.username === query || m.id === query.replace(/[<@!>]/g, '') || m.nick === query) // Exact match for mention, username+discrim, username and user ID + || members.find((m) => `${m.username.toLowerCase()}#${m.discriminator}` === query.toLowerCase() || m.username.toLowerCase() === query.toLowerCase() || (m.nick && m.nick.toLowerCase() === query.toLowerCase())) // Case insensitive match for username+discrim, username + || members.find((m) => m.username.toLowerCase().startsWith(query.toLowerCase()) || (m.nick && m.nick.toLowerCase().startsWith(query.toLowerCase()))); } public async handleError(error: Error, message?: Message, command?: Command, disable?: boolean): Promise { @@ -85,10 +90,10 @@ export default class Util { info.embed = embed; } await this.client.createMessage('595788220764127272', info); - const msg = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g); + const msg = message ? message.content.slice(this.client.config.prefix.length).trim().split(/ +/g) : []; // eslint-disable-next-line no-param-reassign if (command && disable) this.resolveCommand(msg).then((c) => { c.cmd.enabled = false; }); - if (message) message.channel.createMessage(`***${this.emojis.ERROR} An unexpected error has occured - please contact a Faculty Marshal.${command ? ' This command has been disabled.' : ''}***`); + if (message) message.channel.createMessage(`***${this.emojis.ERROR} An unexpected error has occured - please contact a Faculty Marshal.${command && disable ? ' This command has been disabled.' : ''}***`); } catch (err) { this.signale.error(err); } @@ -112,4 +117,13 @@ export default class Util { } return arrayString; } + + 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; + } } diff --git a/src/commands/ban.ts b/src/commands/ban.ts index 4562e1d..d6977f7 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, PrivateChannel, GroupChannel } from 'eris'; import { Client, Command } from '../class'; export default class Ban extends Command { @@ -15,24 +15,20 @@ export default class Ban extends Command { public async run(message: Message, args: string[]) { try { - // @ts-ignore - const member = this.client.util.resolveMember(args[0], message.channel.guild); + const member = this.client.util.resolveMember(args[0], message.member.guild); let user: User; if (!member) { try { user = await this.client.getRESTUser(args[0]); } catch { - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Cannot find user.***`); + return this.error(message.channel, 'Cannot find user.'); } } try { await this.client.guilds.get(this.client.config.guildID).getBan(args[0]); - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} This user is already banned.***`); - } catch { - // eslint-disable-next-line no-unused-expressions - undefined; - } - if (member && !this.client.util.moderation.checkPermissions(member, message.member)) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Permission denied.***`); + 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.'); message.delete(); let momentMilliseconds: number; @@ -43,9 +39,10 @@ export default class Ban extends Command { const unit = lockLength[1] as unitOfTime.Base; momentMilliseconds = moment.duration(length, unit).asMilliseconds(); reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' '); + 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 message.channel.createMessage(`***${this.client.util.emojis.SUCCESS} ${user.username}#${user.id} has been banned.***`); + return this.success(message.channel, `${user.username}#${user.id} has been banned.`); } catch (err) { return this.client.util.handleError(err, message, this, false); } diff --git a/src/commands/eval.ts b/src/commands/eval.ts index 6e78ba1..f62fc7a 100644 --- a/src/commands/eval.ts +++ b/src/commands/eval.ts @@ -54,9 +54,9 @@ export default class Eval extends Command { if (display[5]) { try { const { data } = await axios.post('https://snippets.cloud.libraryofcode.org/documents', display.join('')); - return message.channel.createMessage(`${this.client.util.emojis.SUCCESS} Your evaluation evaled can be found on https://snippets.cloud.libraryofcode.org/${data.key}`); + return this.success(message.channel, `Your evaluation evaled can be found on https://snippets.cloud.libraryofcode.org/${data.key}`); } catch (error) { - return message.channel.createMessage(`${this.client.util.emojis.ERROR} ${error}`); + return this.error(message.channel, `${error}`); } } diff --git a/src/commands/game.ts b/src/commands/game.ts index a8f82a3..f1d18d2 100644 --- a/src/commands/game.ts +++ b/src/commands/game.ts @@ -1,5 +1,5 @@ /* eslint-disable prefer-destructuring */ -import { Activity, Member, Message } from 'eris'; +import { Activity, Member, Message, PrivateChannel, GroupChannel } from 'eris'; import { Client, Command, RichEmbed } from '../class'; export default class Game extends Command { @@ -19,10 +19,9 @@ export default class Game extends Command { let member: Member; if (!args[0]) member = message.member; else { - // @ts-ignore - member = this.client.util.resolveMember(message, args[0], message.channel.guild); + member = this.client.util.resolveMember(args.join(' '), message.member.guild); if (!member) { - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Member not found.***`); + return this.error(message.channel, 'Member not found.'); } } if (member.activities.length <= 0) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Cannot find a game for this member.***`); @@ -35,7 +34,7 @@ export default class Game extends Command { mainStatus = member.activities[0]; } embed.setAuthor(member.user.username, member.user.avatarURL); - if (mainStatus?.name === 'Spotify') { + if (mainStatus.type === 4) { embed.setTitle('Spotify'); embed.setColor('#1ed760'); embed.addField('Song', mainStatus.details, true); @@ -51,7 +50,7 @@ export default class Game extends Command { embed.setFooter(`Listening to Spotify | ${this.client.user.username}`, 'https://media.discordapp.net/attachments/358674161566220288/496894273304920064/2000px-Spotify_logo_without_text.png'); embed.setTimestamp(); } else { - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Only Spotify games are supported at this time.***`); + return this.error(message.channel, 'Only Spotify games are supported at this time.'); } return message.channel.createMessage({ embed }); } catch (err) { diff --git a/src/commands/roleinfo.ts b/src/commands/roleinfo.ts index 673c705..574a7d0 100644 --- a/src/commands/roleinfo.ts +++ b/src/commands/roleinfo.ts @@ -14,19 +14,13 @@ export default class Roleinfo extends Command { public async run(message: Message, args: string[]) { try { - if (!args[0]) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You need to specifiy a role ID or a role name.***`); + if (!args[0]) return this.error(message.channel, 'You need to specifiy a role ID or a role name.'); - // @ts-ignore - let role: Role = message.channel.guild.roles.find((r: Role) => r.id === args[0]); + let role: Role = message.member.guild.roles.find((r: Role) => r.id === args[0]); if (!role) { // if it's a role name - // @ts-ignore - role = message.channel.guild.roles.find((r: Role) => r.name.toLowerCase().includes(args.join(' ').toLowerCase())); + role = message.member.guild.roles.find((r: Role) => r.name.toLowerCase().includes(args.join(' ').toLowerCase())); } - if (!role) return this.client.createMessage(message.channel.id, `***${this.client.util.emojis.ERROR} Could not find role.***`); - - const ms = role.createdAt; - const date = new Date(ms).toLocaleDateString('en-us'); - const time = new Date(ms).toLocaleTimeString('en-us'); + if (!role) return this.error(message.channel, 'Could not find role.'); const perms = role.permissions; const permsArray: string[] = []; @@ -45,11 +39,11 @@ export default class Roleinfo extends Command { embed.setDescription(`<@&${role.id}> ID: \`${role.id}\``); embed.setColor(role.color); embed.addField('Name', role.name, true); - embed.addField('Color', `#${role.color.toString(16)}`, true); - embed.addField('Hoisted', role.hoist.toString(), true); - embed.addField('Position', role.position.toString(), true); - embed.addField('Creation Date', `${date} ${time}`, true); - embed.addField('Mentionnable', role.mentionable.toString(), true); + embed.addField('Color', role.color ? this.client.util.decimalToHex(role.color) : 'None', true); + embed.addField('Hoisted', role.hoist ? 'Yes' : 'No', true); + embed.addField('Position', role.position ? 'Yes' : 'No', true); + embed.addField('Creation Date', new Date(role.createdAt).toLocaleString(), true); + embed.addField('Mentionable', role.mentionable ? 'Yes' : 'No', true); embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setTimestamp(); diff --git a/src/commands/unban.ts b/src/commands/unban.ts index 34efd89..025758c 100644 --- a/src/commands/unban.ts +++ b/src/commands/unban.ts @@ -14,29 +14,21 @@ export default class Unban extends Command { public async run(message: Message, args: string[]) { try { - // @ts-ignore let user: User; try { user = await this.client.getRESTUser(args[0]); } catch { - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Could find find user.***`); - } - try { - if (await this.client.getRESTGuildMember(this.client.config.guildID, args[0])) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} This member exists in the server.***`); - } catch { - // eslint-disable-next-line no-unused-expressions - undefined; + return this.error(message.channel, 'Could find find user.'); } try { await this.client.guilds.get(this.client.config.guildID).getBan(args[0]); } catch { - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} This user is not banned.***`); + return this.error(message.channel, 'This user is not banned.'); } - if (!user) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Unable to locate user.***`); message.delete(); await this.client.util.moderation.unban(user.id, message.member, args.slice(1).join(' ')); - return message.channel.createMessage(`***${this.client.util.emojis.SUCCESS} ${user.username}#${user.discriminator} has been unbanned.***`); + return this.success(message.channel, `${user.username}#${user.discriminator} has been unbanned.`); } catch (err) { return this.client.util.handleError(err, message, this, false); } diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 4c65a3e..e5be07b 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -1,6 +1,6 @@ /* eslint-disable no-bitwise */ import moment from 'moment'; -import { Message, Member } from 'eris'; +import { Message, Member, PrivateChannel, GroupChannel } from 'eris'; import { Client, Command, RichEmbed } from '../class'; import acknowledgements from '../configs/acknowledgements.json'; import { whois as emotes } from '../configs/emotes.json'; @@ -21,11 +21,11 @@ export default class Whois extends Command { let member: Member; if (!args[0]) member = message.member; else { - // @ts-ignore - member = this.client.util.resolveMember(args.join(' '), message.channel.guild); - if (!member) { - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Member not found.***`); - } + member = this.client.util.resolveMember(args.join(' '), message.member.guild); + } + + if (!member) { + return this.error(message.channel, 'Member not found.'); } const embed = new RichEmbed(); embed.setAuthor(`${member.user.username}#${member.user.discriminator}`, member.user.avatarURL); @@ -58,18 +58,15 @@ export default class Whois extends Command { } description += `\n<@${member.id}>`; embed.setDescription(description); - // @ts-ignore - for (const role of member.roles.map((r) => message.channel.guild.roles.get(r)).sort((a, b) => b.position - a.position)) { - if (role.color !== 0) { - embed.setColor(role.color); - break; - } - } + + const roles = member.roles.map((r) => message.member.guild.roles.get(r)).sort((a, b) => b.position - a.position); + + const { color } = roles.find((r) => r.color); + embed.setColor(color); embed.addField('Status', `${member.status[0].toUpperCase()}${member.status.slice(1)}`, true); embed.addField('Joined At', `${moment(new Date(message.member.joinedAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true); embed.addField('Created At', `${moment(new Date(message.author.createdAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true); - // @ts-ignore - embed.addField(`Roles [${member.roles.length}]`, member.roles.map((r) => message.channel.guild.roles.get(r)).sort((a, b) => b.position - a.position).map((r) => `<@&${r.id}>`).join(', ')); + embed.addField(`Roles [${roles.length}]`, roles.map((r) => `<@&${r.id}>`).join(', ')); const permissions: string[] = []; const serverAcknowledgements: string[] = []; const bit = member.permission.allow; @@ -101,7 +98,6 @@ export default class Whois extends Command { } public resolveStaffInformation(id: string) { - const ack = acknowledgements.find((m) => m.id === id); - return ack; + return acknowledgements.find((m) => m.id === id); } } diff --git a/src/events/ready.ts b/src/events/ready.ts index 142f42b..908e189 100644 --- a/src/events/ready.ts +++ b/src/events/ready.ts @@ -16,8 +16,8 @@ export default class { this.client.util.handleError(err); process.exit(1); }); - process.on('unhandledRejection', (err) => { - this.client.util.handleError(new Error(err.toString())); + process.on('unhandledRejection', (err: Error) => { + this.client.util.handleError(err); }); } } diff --git a/tsconfig.json b/tsconfig.json index 251319b..fc5e133 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ - "target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ + "target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ -- 2.20.1 From 99ef533121903cd3281535c2bb9457bba2cf3b63 Mon Sep 17 00:00:00 2001 From: Bsian Date: Fri, 17 Apr 2020 04:07:33 +0100 Subject: [PATCH 02/20] Remove optional chaining --- src/commands/whois.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index e5be07b..495e64a 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -41,20 +41,22 @@ export default class Whois extends Command { embed.setThumbnail(member.avatarURL); const ackResolve = this.resolveStaffInformation(member.id); let description = ''; - if (ackResolve?.title && ackResolve?.dept) { - description += `${emotes.titleAndDepartment} __**${ackResolve.title}**__, ${ackResolve.dept}\n\n`; - } - if (ackResolve?.emailAddress) { - description += `${emotes.email} ${ackResolve.emailAddress}\n`; - } - if (ackResolve?.gitlab) { - description += `${emotes.gitlab} ${ackResolve.gitlab}\n`; - } - if (ackResolve?.github) { - description += `${emotes.github} ${ackResolve.github}\n`; - } - if (ackResolve?.bio) { - description += `${emotes.bio} *${ackResolve.bio}*\n`; + if (ackResolve) { + if (ackResolve.title && ackResolve.dept) { + description += `${emotes.titleAndDepartment} __**${ackResolve.title}**__, ${ackResolve.dept}\n\n`; + } + if (ackResolve.emailAddress) { + description += `${emotes.email} ${ackResolve.emailAddress}\n`; + } + if (ackResolve.gitlab) { + description += `${emotes.gitlab} ${ackResolve.gitlab}\n`; + } + if (ackResolve.github) { + description += `${emotes.github} ${ackResolve.github}\n`; + } + if (ackResolve.bio) { + description += `${emotes.bio} *${ackResolve.bio}*\n`; + } } description += `\n<@${member.id}>`; embed.setDescription(description); @@ -86,7 +88,7 @@ export default class Whois extends Command { if (serverAcknowledgements.length > 0) { embed.addField('Acknowledgements', serverAcknowledgements[0]); } - if (ackResolve?.acknowledgements) { + if (ackResolve && ackResolve.acknowledgements) { embed.addField('Bot Acknowledgements', ackResolve.acknowledgements.join(', ')); } embed.setFooter(this.client.user.username, this.client.user.avatarURL); -- 2.20.1 From c72d5c1f1b1ed66fde8233b445957d4b3ac22909 Mon Sep 17 00:00:00 2001 From: Bsian Date: Fri, 17 Apr 2020 04:27:46 +0100 Subject: [PATCH 03/20] Add activity type enum --- src/commands/game.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/commands/game.ts b/src/commands/game.ts index f1d18d2..f7bd914 100644 --- a/src/commands/game.ts +++ b/src/commands/game.ts @@ -1,7 +1,15 @@ /* eslint-disable prefer-destructuring */ -import { Activity, Member, Message, PrivateChannel, GroupChannel } from 'eris'; +import { Activity, Member, Message } from 'eris'; import { Client, Command, RichEmbed } from '../class'; +enum ActivityType { + PLAYING = 0, + STREAMING = 1, + LISTENING = 2, + WATCHING = 3, + CUSTOM_STATUS = 4 +} + export default class Game extends Command { constructor(client: Client) { super(client); @@ -27,14 +35,14 @@ export default class Game extends Command { if (member.activities.length <= 0) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Cannot find a game for this member.***`); const embed = new RichEmbed(); let mainStatus: Activity; - if (member.activities[0].type === 4) { + if (member.activities[0].type === ActivityType.CUSTOM_STATUS) { mainStatus = member.activities[1]; embed.setDescription(`*${member.activities[0].state}*`); } else { mainStatus = member.activities[0]; } embed.setAuthor(member.user.username, member.user.avatarURL); - if (mainStatus.type === 4) { + if (mainStatus.type === ActivityType.LISTENING) { embed.setTitle('Spotify'); embed.setColor('#1ed760'); embed.addField('Song', mainStatus.details, true); -- 2.20.1 From f35317c43cce65f4a1ff0b57f91c072f418234fe Mon Sep 17 00:00:00 2001 From: Bsian Date: Fri, 17 Apr 2020 04:29:17 +0100 Subject: [PATCH 04/20] Remove imports --- src/commands/ban.ts | 2 +- src/commands/whois.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/ban.ts b/src/commands/ban.ts index d6977f7..a5afa43 100644 --- a/src/commands/ban.ts +++ b/src/commands/ban.ts @@ -1,5 +1,5 @@ import moment, { unitOfTime } from 'moment'; -import { Message, User, PrivateChannel, GroupChannel } from 'eris'; +import { Message, User } from 'eris'; import { Client, Command } from '../class'; export default class Ban extends Command { diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 495e64a..e6bdad9 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -1,6 +1,6 @@ /* eslint-disable no-bitwise */ import moment from 'moment'; -import { Message, Member, PrivateChannel, GroupChannel } from 'eris'; +import { Message, Member } from 'eris'; import { Client, Command, RichEmbed } from '../class'; import acknowledgements from '../configs/acknowledgements.json'; import { whois as emotes } from '../configs/emotes.json'; -- 2.20.1 From 41cd6869f52cab70cdc7777395310b0387f2cdad Mon Sep 17 00:00:00 2001 From: Bsian Date: Fri, 17 Apr 2020 04:35:56 +0100 Subject: [PATCH 05/20] Use error function --- src/commands/game.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/game.ts b/src/commands/game.ts index f7bd914..6d1aa68 100644 --- a/src/commands/game.ts +++ b/src/commands/game.ts @@ -32,7 +32,7 @@ export default class Game extends Command { return this.error(message.channel, 'Member not found.'); } } - if (member.activities.length <= 0) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Cannot find a game for this member.***`); + if (member.activities.length <= 0) return this.error(message.channel, 'Cannot find a game for this member.'); const embed = new RichEmbed(); let mainStatus: Activity; if (member.activities[0].type === ActivityType.CUSTOM_STATUS) { -- 2.20.1 From 178aa9f37b3c9d99a21aa4d06020f7f7a5843bff Mon Sep 17 00:00:00 2001 From: Bsian Date: Fri, 17 Apr 2020 15:17:04 +0100 Subject: [PATCH 06/20] Conflict --- package.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/package.json b/package.json index 322f8ad..bf1c286 100644 --- a/package.json +++ b/package.json @@ -22,11 +22,7 @@ }, "dependencies": { "axios": "^0.19.2", -<<<<<<< HEAD - "eris": "abalabahaha/eris#dev", -======= "eris": "bsian03/eris#bsian", ->>>>>>> dev "moment": "^2.24.0", "mongoose": "^5.9.9", "signale": "^1.4.0", -- 2.20.1 From 36d02a8f122a009dec092dcd0a894c9746022a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Fri, 17 Apr 2020 21:10:18 -0400 Subject: [PATCH 07/20] Added slow mode command --- slowmode.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 slowmode.ts diff --git a/slowmode.ts b/slowmode.ts new file mode 100644 index 0000000..76575a3 --- /dev/null +++ b/slowmode.ts @@ -0,0 +1,37 @@ +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class Slowmode extends Command { + constructor(client: Client) { + super(client); + this.name = 'slowmode'; + this.description = 'Set slowmode to a channel.'; + this.usage = 'slowmode [time] [seconds | minutes | hours]'; + this.permissions = 1; + this.guildOnly = true; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You need to specifiy the slowmode time.***`); + + // @ts-ignore + let time: number = args[0]; + if (isNaN(time)) { + return message.channel.createMessage(`***${this.client.util.emojis.ERROR} The first argument must be a number.***`); + } + + if (args[1]) { + if (args[1] === 'm' || args[1] === 'min'|| args[1] === 'mins' || args[1] === 'minute' || args[1] === 'minutes') time *= 60; + else if (args[1] === 'h' || args[1] === 'hour' || args[1] === 'hours') time = time * 60 * 60; + else time = time; + } + if (time > 21600) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Maximum slow mode is 6 hours.***`); + // @ts-ignore + return message.channel.edit({ rateLimitPerUser: time }); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} -- 2.20.1 From e360798cc60a851c665d17cb0de59bbda819afce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Fri, 24 Apr 2020 03:55:31 -0400 Subject: [PATCH 08/20] Deleted slowmode.ts because it's in wrong location --- slowmode.ts | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 slowmode.ts diff --git a/slowmode.ts b/slowmode.ts deleted file mode 100644 index 76575a3..0000000 --- a/slowmode.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Message } from 'eris'; -import { Client, Command } from '../class'; - -export default class Slowmode extends Command { - constructor(client: Client) { - super(client); - this.name = 'slowmode'; - this.description = 'Set slowmode to a channel.'; - this.usage = 'slowmode [time] [seconds | minutes | hours]'; - this.permissions = 1; - this.guildOnly = true; - this.enabled = true; - } - - public async run(message: Message, args: string[]) { - try { - if (!args[0]) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You need to specifiy the slowmode time.***`); - - // @ts-ignore - let time: number = args[0]; - if (isNaN(time)) { - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} The first argument must be a number.***`); - } - - if (args[1]) { - if (args[1] === 'm' || args[1] === 'min'|| args[1] === 'mins' || args[1] === 'minute' || args[1] === 'minutes') time *= 60; - else if (args[1] === 'h' || args[1] === 'hour' || args[1] === 'hours') time = time * 60 * 60; - else time = time; - } - if (time > 21600) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Maximum slow mode is 6 hours.***`); - // @ts-ignore - return message.channel.edit({ rateLimitPerUser: time }); - } catch (err) { - return this.client.util.handleError(err, message, this); - } - } -} -- 2.20.1 From 76d00baeb8da67a32d52ed81c4ff37385541a924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Fri, 24 Apr 2020 03:57:17 -0400 Subject: [PATCH 09/20] using the correct location --- slowmode.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 slowmode.ts diff --git a/slowmode.ts b/slowmode.ts new file mode 100644 index 0000000..8713f3c --- /dev/null +++ b/slowmode.ts @@ -0,0 +1,37 @@ +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class Slowmode extends Command { + constructor(client: Client) { + super(client); + this.name = 'slowmode'; + this.description = 'Set slowmode to a channel.'; + this.usage = 'slowmode [time] [seconds | minutes | hours]'; + this.permissions = 1; + this.guildOnly = true; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You need to specifiy the slowmode time.***`); + + // @ts-ignore + let time: number = args[0]; + if (isNaN(time)) { + return message.channel.createMessage(`***${this.client.util.emojis.ERROR} The first argument must be a number.***`); + } + + if (args[1]) { + if (args[1] === 'm' || args[1] === 'min'|| args[1] === 'mins' || args[1] === 'minute' || args[1] === 'minutes') time *= 60; + else if (args[1] === 'h' || args[1] === 'hour' || args[1] === 'hours') time = time * 60 * 60; + else time = time; + } + if (time > 21600) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Maximum slow mode is 6 hours.***`); + // @ts-ignore + return message.channel.edit({ rateLimitPerUser: time }); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} \ No newline at end of file -- 2.20.1 From 7225368b4fd7d6b3505aba75695c3e39a4e48808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Fri, 24 Apr 2020 03:57:41 -0400 Subject: [PATCH 10/20] wrong location 2 --- slowmode.ts | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 slowmode.ts diff --git a/slowmode.ts b/slowmode.ts deleted file mode 100644 index 8713f3c..0000000 --- a/slowmode.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Message } from 'eris'; -import { Client, Command } from '../class'; - -export default class Slowmode extends Command { - constructor(client: Client) { - super(client); - this.name = 'slowmode'; - this.description = 'Set slowmode to a channel.'; - this.usage = 'slowmode [time] [seconds | minutes | hours]'; - this.permissions = 1; - this.guildOnly = true; - this.enabled = true; - } - - public async run(message: Message, args: string[]) { - try { - if (!args[0]) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You need to specifiy the slowmode time.***`); - - // @ts-ignore - let time: number = args[0]; - if (isNaN(time)) { - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} The first argument must be a number.***`); - } - - if (args[1]) { - if (args[1] === 'm' || args[1] === 'min'|| args[1] === 'mins' || args[1] === 'minute' || args[1] === 'minutes') time *= 60; - else if (args[1] === 'h' || args[1] === 'hour' || args[1] === 'hours') time = time * 60 * 60; - else time = time; - } - if (time > 21600) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Maximum slow mode is 6 hours.***`); - // @ts-ignore - return message.channel.edit({ rateLimitPerUser: time }); - } catch (err) { - return this.client.util.handleError(err, message, this); - } - } -} \ No newline at end of file -- 2.20.1 From e892d7a6d6f42959d2bbcac19899494b05b7783f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Fri, 24 Apr 2020 03:58:30 -0400 Subject: [PATCH 11/20] correct location 2 --- src/commands/slowmode.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/commands/slowmode.ts diff --git a/src/commands/slowmode.ts b/src/commands/slowmode.ts new file mode 100644 index 0000000..8713f3c --- /dev/null +++ b/src/commands/slowmode.ts @@ -0,0 +1,37 @@ +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class Slowmode extends Command { + constructor(client: Client) { + super(client); + this.name = 'slowmode'; + this.description = 'Set slowmode to a channel.'; + this.usage = 'slowmode [time] [seconds | minutes | hours]'; + this.permissions = 1; + this.guildOnly = true; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You need to specifiy the slowmode time.***`); + + // @ts-ignore + let time: number = args[0]; + if (isNaN(time)) { + return message.channel.createMessage(`***${this.client.util.emojis.ERROR} The first argument must be a number.***`); + } + + if (args[1]) { + if (args[1] === 'm' || args[1] === 'min'|| args[1] === 'mins' || args[1] === 'minute' || args[1] === 'minutes') time *= 60; + else if (args[1] === 'h' || args[1] === 'hour' || args[1] === 'hours') time = time * 60 * 60; + else time = time; + } + if (time > 21600) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Maximum slow mode is 6 hours.***`); + // @ts-ignore + return message.channel.edit({ rateLimitPerUser: time }); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} \ No newline at end of file -- 2.20.1 From 4529867037d929cbed385d64a1f9d4c38d091a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Fri, 15 May 2020 21:35:48 -0400 Subject: [PATCH 12/20] Used moment instead of a custom time parser --- src/commands/slowmode.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/commands/slowmode.ts b/src/commands/slowmode.ts index 8713f3c..b842182 100644 --- a/src/commands/slowmode.ts +++ b/src/commands/slowmode.ts @@ -1,4 +1,5 @@ import { Message } from 'eris'; +import moment, { unitOfTime } from 'moment'; import { Client, Command } from '../class'; export default class Slowmode extends Command { @@ -6,7 +7,7 @@ export default class Slowmode extends Command { super(client); this.name = 'slowmode'; this.description = 'Set slowmode to a channel.'; - this.usage = 'slowmode [time] [seconds | minutes | hours]'; + this.usage = 'slowmode '; this.permissions = 1; this.guildOnly = true; this.enabled = true; @@ -14,24 +15,22 @@ export default class Slowmode extends Command { public async run(message: Message, args: string[]) { try { - if (!args[0]) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You need to specifiy the slowmode time.***`); + if (!args[0]) return this.error(message.channel, 'This command requires an argument.'); - // @ts-ignore - let time: number = args[0]; - if (isNaN(time)) { - return message.channel.createMessage(`***${this.client.util.emojis.ERROR} The first argument must be a number.***`); + let momentSeconds: number; + if (args[0]) { + const Length = args[0].match(/[a-z]+|[^a-z]+/gi); + const length = Number(Length[0]); + if (isNaN(length)) return this.error(message.channel, 'Could not determine the slowmode time.'); + const unit = Length[1] as unitOfTime.Base; + momentSeconds = moment.duration(length, unit || 's').asSeconds(); } - if (args[1]) { - if (args[1] === 'm' || args[1] === 'min'|| args[1] === 'mins' || args[1] === 'minute' || args[1] === 'minutes') time *= 60; - else if (args[1] === 'h' || args[1] === 'hour' || args[1] === 'hours') time = time * 60 * 60; - else time = time; - } - if (time > 21600) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Maximum slow mode is 6 hours.***`); + if (momentSeconds > 21600) return this.error(message.channel, 'Slowmode cannot be longer than 6 hours.'); // @ts-ignore - return message.channel.edit({ rateLimitPerUser: time }); + return message.channel.edit({ rateLimitPerUser: momentSeconds }); } catch (err) { return this.client.util.handleError(err, message, this); } } -} \ No newline at end of file +} -- 2.20.1 From f92d51323b00043789ad79dc4d31a0485008ffa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Sun, 17 May 2020 17:46:44 -0400 Subject: [PATCH 13/20] few changes in the slowmode command (Bsian) --- src/commands/slowmode.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/commands/slowmode.ts b/src/commands/slowmode.ts index b842182..8d6f55a 100644 --- a/src/commands/slowmode.ts +++ b/src/commands/slowmode.ts @@ -1,4 +1,4 @@ -import { Message } from 'eris'; +import { Message, GuildTextableChannel } from 'eris'; import moment, { unitOfTime } from 'moment'; import { Client, Command } from '../class'; @@ -13,22 +13,19 @@ export default class Slowmode extends Command { this.enabled = true; } - public async run(message: Message, args: string[]) { + public async run(message: Message, args: string[]) { try { if (!args[0]) return this.error(message.channel, 'This command requires an argument.'); - let momentSeconds: number; - if (args[0]) { - const Length = args[0].match(/[a-z]+|[^a-z]+/gi); - const length = Number(Length[0]); - if (isNaN(length)) return this.error(message.channel, 'Could not determine the slowmode time.'); - const unit = Length[1] as unitOfTime.Base; - momentSeconds = moment.duration(length, unit || 's').asSeconds(); - } + const Length = args[0].match(/[a-z]+|[^a-z]+/gi); + const length = Number(Length[0]); + if (Number.isNaN(length)) return this.error(message.channel, 'Could not determine the slowmode time.'); + const unit = Length[1] as unitOfTime.Base; + const momentSeconds: number = moment.duration(length, unit || 's').asSeconds(); - if (momentSeconds > 21600) return this.error(message.channel, 'Slowmode cannot be longer than 6 hours.'); - // @ts-ignore - return message.channel.edit({ rateLimitPerUser: momentSeconds }); + if (momentSeconds > 21600 || momentSeconds < 0) return this.error(message.channel, 'Slowmode must be between 0 seconds and 6 hours.'); + + return message.channel.edit({ rateLimitPerUser: momentSeconds }).then((c) => message.addReaction(':success:477618704155410452')); } catch (err) { return this.client.util.handleError(err, message, this); } -- 2.20.1 From 9b2cebde85a82b1ab905c9dbf5d738dea3ef3377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Mon, 18 May 2020 22:20:05 -0400 Subject: [PATCH 14/20] handle decimal numbers in slowmode command (Bsian) --- src/commands/slowmode.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/commands/slowmode.ts b/src/commands/slowmode.ts index 8d6f55a..33807c5 100644 --- a/src/commands/slowmode.ts +++ b/src/commands/slowmode.ts @@ -17,13 +17,12 @@ export default class Slowmode extends Command { try { if (!args[0]) return this.error(message.channel, 'This command requires an argument.'); - const Length = args[0].match(/[a-z]+|[^a-z]+/gi); - const length = Number(Length[0]); - if (Number.isNaN(length)) return this.error(message.channel, 'Could not determine the slowmode time.'); - const unit = Length[1] as unitOfTime.Base; - const momentSeconds: number = moment.duration(length, unit || 's').asSeconds(); + const [length, unit]: Array = args[0].match(/[a-z]+|[^a-z]+/gi); + if (Number.isNaN(Number(length))) return this.error(message.channel, 'Could not determine the slowmode time.'); + const momentSeconds: number = moment.duration(length, unit as unitOfTime.Base || 's').asSeconds(); if (momentSeconds > 21600 || momentSeconds < 0) return this.error(message.channel, 'Slowmode must be between 0 seconds and 6 hours.'); + if (momentSeconds % 1) return this.error(message.channel, 'Slowmode cannot have decimals'); return message.channel.edit({ rateLimitPerUser: momentSeconds }).then((c) => message.addReaction(':success:477618704155410452')); } catch (err) { -- 2.20.1 From 34239aa8fafd054af09d9af3492b5783982aaaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Mon, 18 May 2020 22:25:59 -0400 Subject: [PATCH 15/20] added slowmode in src/commands/index.ts --- src/commands/index.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/commands/index.ts diff --git a/src/commands/index.ts b/src/commands/index.ts new file mode 100644 index 0000000..b6bb4fc --- /dev/null +++ b/src/commands/index.ts @@ -0,0 +1,18 @@ +export { default as additem } from './additem'; +export { default as addredirect } from './addredirect'; +export { default as ban } from './ban'; +export { default as delitem } from './delitem'; +export { default as delredirect } from './delredirect'; +export { default as djs } from './djs'; +export { default as eval } from './eval'; +export { default as game } from './game'; +export { default as help } from './help'; +export { default as info } from './info'; +export { default as kick } from './kick'; +export { default as listredirects } from './listredirects'; +export { default as npm } from './npm'; +export { default as ping } from './ping'; +export { default as roleinfo } from './roleinfo'; +export { default as unban } from './unban'; +export { default as whois } from './whois'; +export { default as slowmode } from './slowmode'; \ No newline at end of file -- 2.20.1 From 8316ff53cdee895a512a1b4ed171e1ac8af81762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Tue, 19 May 2020 23:01:05 -0400 Subject: [PATCH 16/20] added new line --- src/commands/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/index.ts b/src/commands/index.ts index b6bb4fc..a9dde61 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -15,4 +15,4 @@ export { default as ping } from './ping'; export { default as roleinfo } from './roleinfo'; export { default as unban } from './unban'; export { default as whois } from './whois'; -export { default as slowmode } from './slowmode'; \ No newline at end of file +export { default as slowmode } from './slowmode'; -- 2.20.1 From 5cd7cb7bf2410d2a7187aa8aaebcfc2e9ae28761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Wed, 20 May 2020 22:24:44 -0400 Subject: [PATCH 17/20] isNaN() instead of Number.isNaN() --- src/commands/slowmode.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/slowmode.ts b/src/commands/slowmode.ts index 33807c5..b85bbad 100644 --- a/src/commands/slowmode.ts +++ b/src/commands/slowmode.ts @@ -17,8 +17,9 @@ export default class Slowmode extends Command { try { if (!args[0]) return this.error(message.channel, 'This command requires an argument.'); - const [length, unit]: Array = args[0].match(/[a-z]+|[^a-z]+/gi); - if (Number.isNaN(Number(length))) return this.error(message.channel, 'Could not determine the slowmode time.'); + const [length, unit] = args[0].match(/[a-z]+|[^a-z]+/gi); + // eslint-disable-next-line no-restricted-globals + if (isNaN(length as unknown as number)) return this.error(message.channel, 'Could not determine the slowmode time.'); const momentSeconds: number = moment.duration(length, unit as unitOfTime.Base || 's').asSeconds(); if (momentSeconds > 21600 || momentSeconds < 0) return this.error(message.channel, 'Slowmode must be between 0 seconds and 6 hours.'); -- 2.20.1 From 34d363b07113c728ed28fcaba85018cdbacbeb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Fri, 22 May 2020 22:51:30 -0400 Subject: [PATCH 18/20] round decimal instead of cancelling the command (Khaaz) --- src/commands/slowmode.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commands/slowmode.ts b/src/commands/slowmode.ts index b85bbad..72b302b 100644 --- a/src/commands/slowmode.ts +++ b/src/commands/slowmode.ts @@ -20,10 +20,9 @@ export default class Slowmode extends Command { const [length, unit] = args[0].match(/[a-z]+|[^a-z]+/gi); // eslint-disable-next-line no-restricted-globals if (isNaN(length as unknown as number)) return this.error(message.channel, 'Could not determine the slowmode time.'); - const momentSeconds: number = moment.duration(length, unit as unitOfTime.Base || 's').asSeconds(); + const momentSeconds: number = Number(moment.duration(length, unit as unitOfTime.Base || 's').asSeconds().toFixed()); if (momentSeconds > 21600 || momentSeconds < 0) return this.error(message.channel, 'Slowmode must be between 0 seconds and 6 hours.'); - if (momentSeconds % 1) return this.error(message.channel, 'Slowmode cannot have decimals'); return message.channel.edit({ rateLimitPerUser: momentSeconds }).then((c) => message.addReaction(':success:477618704155410452')); } catch (err) { -- 2.20.1 From cba3456e37364c4a54bb75e852a4fe2fc323fb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Tue, 26 May 2020 19:41:00 -0400 Subject: [PATCH 19/20] regex in constructor --- src/commands/slowmode.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/commands/slowmode.ts b/src/commands/slowmode.ts index 72b302b..00e2490 100644 --- a/src/commands/slowmode.ts +++ b/src/commands/slowmode.ts @@ -3,6 +3,8 @@ import moment, { unitOfTime } from 'moment'; import { Client, Command } from '../class'; export default class Slowmode extends Command { + regex: RegExp; + constructor(client: Client) { super(client); this.name = 'slowmode'; @@ -11,16 +13,16 @@ export default class Slowmode extends Command { this.permissions = 1; this.guildOnly = true; this.enabled = true; + this.regex = /[a-z]+|[^a-z]+/gi; } public async run(message: Message, args: string[]) { try { if (!args[0]) return this.error(message.channel, 'This command requires an argument.'); - const [length, unit] = args[0].match(/[a-z]+|[^a-z]+/gi); - // eslint-disable-next-line no-restricted-globals - if (isNaN(length as unknown as number)) return this.error(message.channel, 'Could not determine the slowmode time.'); - const momentSeconds: number = Number(moment.duration(length, unit as unitOfTime.Base || 's').asSeconds().toFixed()); + const [length, unit] = args[0].match(this.regex); + if (Number.isNaN(Number(length))) return this.error(message.channel, 'Could not determine the slowmode time.'); + const momentSeconds: number = Math.round(moment.duration(length, unit as unitOfTime.Base || 's').asSeconds()); if (momentSeconds > 21600 || momentSeconds < 0) return this.error(message.channel, 'Slowmode must be between 0 seconds and 6 hours.'); -- 2.20.1 From d9420239730971f33ddd045ac0d22e974d298892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Thu, 20 Aug 2020 12:46:09 -0400 Subject: [PATCH 20/20] alphabetical order (Bsian) --- src/commands/index.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/commands/index.ts b/src/commands/index.ts index a9dde61..a4d0f26 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,18 +1,31 @@ export { default as additem } from './additem'; +export { default as addnote } from './addnote'; +export { default as addrank } from './addrank'; export { default as addredirect } from './addredirect'; export { default as ban } from './ban'; export { default as delitem } from './delitem'; +export { default as delnote } from './delnote'; +export { default as delrank } from './delrank'; export { default as delredirect } from './delredirect'; export { default as djs } from './djs'; +export { default as eris } from './eris'; export { default as eval } from './eval'; export { default as game } from './game'; export { default as help } from './help'; export { default as info } from './info'; export { default as kick } from './kick'; export { default as listredirects } from './listredirects'; +export { default as members } from './members'; +export { default as mute } from './mute'; +export { default as notes } from './notes'; export { default as npm } from './npm'; +export { default as page } from './page'; export { default as ping } from './ping'; +export { default as rank } from './rank'; export { default as roleinfo } from './roleinfo'; -export { default as unban } from './unban'; -export { default as whois } from './whois'; export { default as slowmode } from './slowmode'; +export { default as stats } from './stats'; +export { default as storemessages } from './storemessages'; +export { default as unban } from './unban'; +export { default as unmute } from './unmute'; +export { default as whois } from './whois'; -- 2.20.1