diff --git a/structure/client/components/observers/UtilityHook.js b/structure/client/components/observers/UtilityHook.js new file mode 100644 index 0000000..ed47c46 --- /dev/null +++ b/structure/client/components/observers/UtilityHook.js @@ -0,0 +1,67 @@ +const { Observer } = require('../../../interfaces/'); + +const CONSTANTS = {}; + +class UtilityHook extends Observer { + + constructor(client) { + + super(client, { + name: 'utility', + priority: 3 + }); + + this.hooks = [ + ['guildMemberAdd', this.welcome.bind(this)], + ['guildMemberAdd', this.autorole.bind(this)] + ] + + } + + async stickyRole(member) { + + const { guild } = member; + const settings = await guild.settings(); + const setting = settings.stickyRole; + if(!setting.enabled) return; + + } + + async autorole(member) { + + const { guild } = member; + const settings = await guild.settings(); + const setting = settings.autorole; + if(!setting.enabled) return; + + } + + async welcome(member) { + + const { guild, user } = member; + const settings = await guild.settings(); + const setting = settings.welcomer; + if(!setting.enabled) return; + + const channel = await user.createDM(); + const message = this._replaceTags(setting.message, member); + await channel.send(message).catch(); + + } + + _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) + .trim(); + } + +} + +module.exports = UtilityHook; \ No newline at end of file