Improvements
parent
e780777adb
commit
2c6cf8e552
|
@ -126,4 +126,9 @@ export default class Util {
|
||||||
const asHex = number.toString(16);
|
const asHex = number.toString(16);
|
||||||
return '#000000'.substring(0, 7 - asHex.length) + asHex;
|
return '#000000'.substring(0, 7 - asHex.length) + asHex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public guildFromMessage(message: Message): Guild | null {
|
||||||
|
if (message.channel instanceof PrivateChannel || message.channel instanceof GroupChannel) return null;
|
||||||
|
return message.channel.guild;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ export default class Ban extends Command {
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
const member = this.client.util.resolveMember(args[0], message.member.guild);
|
const guild = this.client.util.guildFromMessage(message);
|
||||||
|
const member = this.client.util.resolveMember(args[0], guild);
|
||||||
let user: User;
|
let user: User;
|
||||||
if (!member) {
|
if (!member) {
|
||||||
try {
|
try {
|
||||||
|
@ -25,7 +26,7 @@ export default class Ban extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await this.client.guilds.get(this.client.config.guildID).getBan(args[0]);
|
await guild.getBan(args[0]);
|
||||||
return this.error(message.channel, 'This user is already banned.');
|
return this.error(message.channel, 'This user is already banned.');
|
||||||
} catch {} // eslint-disable-line no-empty
|
} catch {} // eslint-disable-line no-empty
|
||||||
if (member && !this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.');
|
if (member && !this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.');
|
||||||
|
|
|
@ -24,10 +24,11 @@ export default class Game extends Command {
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
|
const guild = this.client.util.guildFromMessage(message);
|
||||||
let member: Member;
|
let member: Member;
|
||||||
if (!args[0]) member = message.member;
|
if (!args[0]) member = message.member;
|
||||||
else {
|
else {
|
||||||
member = this.client.util.resolveMember(args.join(' '), message.member.guild);
|
member = this.client.util.resolveMember(args.join(' '), guild);
|
||||||
if (!member) {
|
if (!member) {
|
||||||
return this.error(message.channel, 'Member not found.');
|
return this.error(message.channel, 'Member not found.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,12 @@ export default class Roleinfo extends Command {
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
|
const guild = this.client.util.guildFromMessage(message);
|
||||||
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 specifiy a role ID or a role name.');
|
||||||
|
|
||||||
let role: Role = message.member.guild.roles.find((r: Role) => r.id === args[0]);
|
let role: Role = guild.roles.find((r: Role) => r.id === args[0]);
|
||||||
if (!role) { // if it's a role name
|
if (!role) { // if it's a role name
|
||||||
role = message.member.guild.roles.find((r: Role) => r.name.toLowerCase().includes(args.join(' ').toLowerCase()));
|
role = guild.roles.find((r: Role) => r.name.toLowerCase().includes(args.join(' ').toLowerCase()));
|
||||||
}
|
}
|
||||||
if (!role) return this.error(message.channel, 'Could not find role.');
|
if (!role) return this.error(message.channel, 'Could not find role.');
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ export default class Unban extends Command {
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
|
const guild = this.client.util.guildFromMessage(message);
|
||||||
let user: User;
|
let user: User;
|
||||||
try {
|
try {
|
||||||
user = await this.client.getRESTUser(args[0]);
|
user = await this.client.getRESTUser(args[0]);
|
||||||
|
@ -21,7 +22,7 @@ export default class Unban extends Command {
|
||||||
return this.error(message.channel, 'Could find find user.');
|
return this.error(message.channel, 'Could find find user.');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await this.client.guilds.get(this.client.config.guildID).getBan(args[0]);
|
await guild.getBan(args[0]);
|
||||||
} catch {
|
} catch {
|
||||||
return this.error(message.channel, 'This user is not banned.');
|
return this.error(message.channel, 'This user is not banned.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,11 @@ export default class Whois extends Command {
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
|
const guild = this.client.util.guildFromMessage(message);
|
||||||
let member: Member;
|
let member: Member;
|
||||||
if (!args[0]) member = message.member;
|
if (!args[0]) member = message.member;
|
||||||
else {
|
else {
|
||||||
member = this.client.util.resolveMember(args.join(' '), message.member.guild);
|
member = this.client.util.resolveMember(args.join(' '), guild);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!member) {
|
if (!member) {
|
||||||
|
@ -61,7 +62,7 @@ export default class Whois extends Command {
|
||||||
description += `\n<@${member.id}>`;
|
description += `\n<@${member.id}>`;
|
||||||
embed.setDescription(description);
|
embed.setDescription(description);
|
||||||
|
|
||||||
const roles = member.roles.map((r) => message.member.guild.roles.get(r)).sort((a, b) => b.position - a.position);
|
const roles = member.roles.map((r) => guild.roles.get(r)).sort((a, b) => b.position - a.position);
|
||||||
|
|
||||||
const { color } = roles.find((r) => r.color);
|
const { color } = roles.find((r) => r.color);
|
||||||
embed.setColor(color);
|
embed.setColor(color);
|
||||||
|
@ -72,7 +73,7 @@ export default class Whois extends Command {
|
||||||
const permissions: string[] = [];
|
const permissions: string[] = [];
|
||||||
const serverAcknowledgements: string[] = [];
|
const serverAcknowledgements: string[] = [];
|
||||||
const bit = member.permission.allow;
|
const bit = member.permission.allow;
|
||||||
if (this.client.guilds.get(this.client.config.guildID).ownerID === member.id) serverAcknowledgements.push('Server Owner');
|
if (guild.ownerID === member.id) serverAcknowledgements.push('Server Owner');
|
||||||
if ((bit | 8) === bit) { permissions.push('Administrator'); serverAcknowledgements.push('Server Admin'); }
|
if ((bit | 8) === bit) { permissions.push('Administrator'); serverAcknowledgements.push('Server Admin'); }
|
||||||
if ((bit | 20) === bit) { permissions.push('Manage Server'); serverAcknowledgements.push('Server Manager'); }
|
if ((bit | 20) === bit) { permissions.push('Manage Server'); serverAcknowledgements.push('Server Manager'); }
|
||||||
if ((bit | 10) === bit) permissions.push('Manage Channels');
|
if ((bit | 10) === bit) permissions.push('Manage Channels');
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* eslint-disable no-useless-return */
|
/* eslint-disable no-useless-return */
|
||||||
import { Message, TextChannel } from 'eris';
|
import { Message, TextChannel, NewsChannel } from 'eris';
|
||||||
import { Client } from '../class';
|
import { Client } from '../class';
|
||||||
|
|
||||||
export default class {
|
export default class {
|
||||||
|
@ -16,7 +16,7 @@ export default class {
|
||||||
const noPrefix: string[] = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g);
|
const noPrefix: string[] = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g);
|
||||||
const resolved = await this.client.util.resolveCommand(noPrefix);
|
const resolved = await this.client.util.resolveCommand(noPrefix);
|
||||||
if (!resolved) return;
|
if (!resolved) return;
|
||||||
if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel)) return;
|
if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel || message.channel instanceof NewsChannel)) return;
|
||||||
if (!resolved.cmd.enabled) { message.channel.createMessage(`***${this.client.util.emojis.ERROR} This command has been disabled***`); return; }
|
if (!resolved.cmd.enabled) { message.channel.createMessage(`***${this.client.util.emojis.ERROR} This command has been disabled***`); return; }
|
||||||
if (!resolved.cmd.checkPermissions(message.member)) return;
|
if (!resolved.cmd.checkPermissions(message.member)) return;
|
||||||
this.client.util.signale.info(`User '${message.author.username}#${message.author.discriminator}' ran command '${resolved.cmd.name}' in '${message.channel.id}'.`);
|
this.client.util.signale.info(`User '${message.author.username}#${message.author.discriminator}' ran command '${resolved.cmd.name}' in '${message.channel.id}'.`);
|
||||||
|
|
Loading…
Reference in New Issue