From c31c99f54e470a8306179c138addb47ad3c33896 Mon Sep 17 00:00:00 2001 From: hector6704 Date: Mon, 6 Jul 2020 12:21:36 +0200 Subject: [PATCH 1/5] role command --- src/commands/role.ts | 69 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/commands/role.ts diff --git a/src/commands/role.ts b/src/commands/role.ts new file mode 100644 index 0000000..cfb6519 --- /dev/null +++ b/src/commands/role.ts @@ -0,0 +1,69 @@ +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class Role extends Command { + constructor(client: Client) { + super(client); + this.name = 'role'; + this.description = 'Manage the roles of a member'; + this.usage = 'role '; + this.permissions = 6; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (args.length < 2) return this.client.commands.get('help').run(message, [this.name]); + const member = this.client.util.resolveMember(args[0], message.guild); + if (!member) return this.error(message.channel, 'Member not found'); + if (!this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.'); + const rolesList = args.slice(1).join(' ').split(', '); + const rolesToAdd = []; + const rolesToRemove = []; + let stop = false; + await rolesList.forEach((arg) => { + const action = arg[0]; + let role; + if (action !== '+' && action !== '-') { + role = this.client.util.resolveRole(arg, message.guild); + if (!role) { + stop = true; + return this.error(message.channel, `Role \`${arg}\` not found.`); + } + if (member.roles.includes(role.id)) return rolesToRemove.push(role); + return rolesToAdd.push(role); + } + if (action === '+') { + role = this.client.util.resolveRole(arg.slice(1), message.guild); + if (!role) { + stop = true; + return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`); + } + if (member.roles.includes(role.id)) { + stop = true; + return this.error(message.channel, `You already have the role \`${role.name}\`.`); + } + return rolesToAdd.push(role); + } + if (action === '-') { + role = this.client.util.resolveRole(arg.slice(1), message.guild); + if (!role) { + stop = true; + return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`); + } + if (!member.roles.includes(role.id)) { + stop = true; + return this.error(message.channel, `You don't have the role \`${role.name}\``); + } + return rolesToRemove.push(role); + } + }); + if (stop) return; + await rolesToAdd.forEach((role) => member.addRole(role.id)); + await rolesToRemove.forEach((role) => member.removeRole(role.id)); + return this.success(message.channel, `Changed the roles for ${member.username}#${member.discriminator}${rolesToAdd.length > 0 ? `, added \`${rolesToAdd.map((r) => r.name).join('`, `')}\`` : ''}${rolesToRemove.length > 0 ? `, removed \`${rolesToRemove.map((r) => r.name).join('`, `')}\`` : ''}`); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} From a475df226fd676592e763b9e6e59aeb10e49aac5 Mon Sep 17 00:00:00 2001 From: hector6704 Date: Tue, 7 Jul 2020 13:39:05 +0200 Subject: [PATCH 2/5] fix --- src/commands/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/index.ts b/src/commands/index.ts index 7e21286..8e2cc95 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -16,6 +16,7 @@ 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 role } from './role'; export { default as roleinfo } from './roleinfo'; export { default as unban } from './unban'; export { default as whois } from './whois'; From dee8243ad1b0cce48ea50a0b49ec79da0dfbf6dd Mon Sep 17 00:00:00 2001 From: hector6704 Date: Tue, 25 Aug 2020 15:28:53 +0200 Subject: [PATCH 3/5] use for of and remove awaits --- src/commands/role.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/role.ts b/src/commands/role.ts index cfb6519..46d2dfb 100644 --- a/src/commands/role.ts +++ b/src/commands/role.ts @@ -21,7 +21,7 @@ export default class Role extends Command { const rolesToAdd = []; const rolesToRemove = []; let stop = false; - await rolesList.forEach((arg) => { + for (const arg of rolesList) { const action = arg[0]; let role; if (action !== '+' && action !== '-') { @@ -57,10 +57,10 @@ export default class Role extends Command { } return rolesToRemove.push(role); } - }); + } if (stop) return; - await rolesToAdd.forEach((role) => member.addRole(role.id)); - await rolesToRemove.forEach((role) => member.removeRole(role.id)); + rolesToAdd.forEach((role) => member.addRole(role.id)); + rolesToRemove.forEach((role) => member.removeRole(role.id)); return this.success(message.channel, `Changed the roles for ${member.username}#${member.discriminator}${rolesToAdd.length > 0 ? `, added \`${rolesToAdd.map((r) => r.name).join('`, `')}\`` : ''}${rolesToRemove.length > 0 ? `, removed \`${rolesToRemove.map((r) => r.name).join('`, `')}\`` : ''}`); } catch (err) { return this.client.util.handleError(err, message, this); From 028094aa876eff737526c01dbc2e8bd60161b48a Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 6 Mar 2021 18:32:42 -0500 Subject: [PATCH 4/5] fix and add role cmd --- src/commands/role.ts | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/commands/role.ts b/src/commands/role.ts index 46d2dfb..f8031b6 100644 --- a/src/commands/role.ts +++ b/src/commands/role.ts @@ -1,12 +1,12 @@ -import { Message } from 'eris'; +import { Message, Role as DRole } from 'eris'; import { Client, Command } from '../class'; export default class Role extends Command { constructor(client: Client) { super(client); this.name = 'role'; - this.description = 'Manage the roles of a member'; - this.usage = 'role '; + this.description = 'Manage the roles of a member.'; + this.usage = `${this.client.config.prefix}role `; this.permissions = 6; this.enabled = true; } @@ -14,27 +14,28 @@ export default class Role extends Command { public async run(message: Message, args: string[]) { try { if (args.length < 2) return this.client.commands.get('help').run(message, [this.name]); - const member = this.client.util.resolveMember(args[0], message.guild); + const member = this.client.util.resolveMember(args[0], this.mainGuild); if (!member) return this.error(message.channel, 'Member not found'); - if (!this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.'); + // if (!this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission denied.'); const rolesList = args.slice(1).join(' ').split(', '); const rolesToAdd = []; const rolesToRemove = []; let stop = false; for (const arg of rolesList) { const action = arg[0]; - let role; + let role: DRole; if (action !== '+' && action !== '-') { - role = this.client.util.resolveRole(arg, message.guild); + role = this.client.util.resolveRole(arg, this.mainGuild); if (!role) { stop = true; return this.error(message.channel, `Role \`${arg}\` not found.`); } if (member.roles.includes(role.id)) return rolesToRemove.push(role); - return rolesToAdd.push(role); + rolesToAdd.push(role); + continue; } if (action === '+') { - role = this.client.util.resolveRole(arg.slice(1), message.guild); + role = this.client.util.resolveRole(arg.slice(1), this.mainGuild); if (!role) { stop = true; return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`); @@ -43,10 +44,11 @@ export default class Role extends Command { stop = true; return this.error(message.channel, `You already have the role \`${role.name}\`.`); } - return rolesToAdd.push(role); + rolesToAdd.push(role); + continue; } if (action === '-') { - role = this.client.util.resolveRole(arg.slice(1), message.guild); + role = this.client.util.resolveRole(arg.slice(1), this.mainGuild); if (!role) { stop = true; return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`); @@ -55,10 +57,12 @@ export default class Role extends Command { stop = true; return this.error(message.channel, `You don't have the role \`${role.name}\``); } - return rolesToRemove.push(role); + rolesToRemove.push(role); + continue; } } - if (stop) return; + // eslint-disable-next-line + // if (stop) return; rolesToAdd.forEach((role) => member.addRole(role.id)); rolesToRemove.forEach((role) => member.removeRole(role.id)); return this.success(message.channel, `Changed the roles for ${member.username}#${member.discriminator}${rolesToAdd.length > 0 ? `, added \`${rolesToAdd.map((r) => r.name).join('`, `')}\`` : ''}${rolesToRemove.length > 0 ? `, removed \`${rolesToRemove.map((r) => r.name).join('`, `')}\`` : ''}`); From ccece92a0184d9c008eab59cd69bc6c61713e361 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 6 Mar 2021 18:32:54 -0500 Subject: [PATCH 5/5] changes to eslint config --- .eslintrc.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 7cfeb4b..70d1a95 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -40,7 +40,8 @@ "no-underscore-dangle": "off", "keyword-spacing": "off", "no-multiple-empty-lines": "off", - "consistent-return": "off" + "consistent-return": "off", + "no-continue": "off" }, "ignorePatterns": "**/*.js" }