This commit is contained in:
Erik 2020-07-26 23:11:12 +03:00
parent bbd8a390c4
commit 79e0bce3b5
2 changed files with 18 additions and 12 deletions

View File

@ -1,4 +1,5 @@
const { Observer } = require('../../../interfaces/');
const { Util } = require('../../../../util');
const CONSTANTS = {};
@ -14,7 +15,7 @@ class UtilityHook extends Observer {
this.hooks = [
['guildMemberAdd', this.welcome.bind(this)],
['guildMemberAdd', this.autorole.bind(this)]
]
];
}
@ -32,7 +33,12 @@ class UtilityHook extends Observer {
const { guild } = member;
const settings = await guild.settings();
const setting = settings.autorole;
if(!setting.enabled) return;
if (!setting.enabled) return;
if (!guild.me.hasPermission('MANAGE_ROLES')) return;
const _roles = await guild.resolveRoles(setting.roles);
const roles = _roles.map((r) => r.id);
await member.roles.add(roles, 'Adding autoroles').catch(this.client.logger.error);
}
@ -41,7 +47,7 @@ class UtilityHook extends Observer {
const { guild, user } = member;
const settings = await guild.settings();
const setting = settings.welcomer;
if(!setting.enabled) return;
if (!setting.enabled) return;
const channel = await user.createDM();
const message = this._replaceTags(setting.message, member);
@ -52,13 +58,13 @@ class UtilityHook extends Observer {
_replaceTags(text, member) {
const { user, guild } = member;
return text
.replace(/\{mention\}/g, `<@${member.id}>`)
.replace(/\{tag\}/g, Util.escapeMarkdown(user.tag))
.replace(/\{user\}/g, Util.escapeMarkdown(user.username))
.replace(/\{guildsize\}/g, guild.memberCount)
.replace(/\{guildname\}/g, guild.name)
.replace(/\{accage\}/g, this.client.resolver.timeAgo(Date.now()/1000 - user.createdTimestamp/1000)) //.replace(/a/, '1')
.replace(/\{id\}/g, user.id)
.replace(/\{mention\}/gu, `<@${member.id}>`)
.replace(/\{tag\}/gu, Util.escapeMarkdown(user.tag))
.replace(/\{user\}/gu, Util.escapeMarkdown(user.username))
.replace(/\{guildsize\}/gu, guild.memberCount)
.replace(/\{guildname\}/gu, guild.name)
.replace(/\{accage\}/gu, this.client.resolver.timeAgo(Date.now()/1000 - user.createdTimestamp/1000)) //.replace(/a/, '1')
.replace(/\{id\}/gu, user.id)
.trim();
}

View File

@ -60,7 +60,7 @@ const Message = Structures.extend('Message', (Message) => {
}
if (this.command.showUsage && !this.parameters.length && !Object.values(this.arguments).length) {
return this._showUsage();
return this.embed(this.command.usageEmbed(this));
}
this.client.emit('commandExecute', this);