galactic-bot/structure/client/components/observers/UtilityHook.js

67 lines
1.7 KiB
JavaScript

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;