Make Activities and Leave Messages part of client

This commit is contained in:
Dragon Fire
2020-05-05 21:11:12 -04:00
parent 6afcce1f12
commit c76c05aa3b
3 changed files with 10 additions and 8 deletions
+4 -6
View File
@@ -10,8 +10,6 @@ const client = new Client({
disabledEvents: ['TYPING_START']
});
const { formatNumber } = require('./util/Util');
const activities = require('./assets/json/activity');
const leaveMsgs = require('./assets/json/leave-messages');
client.registry
.registerDefaultTypes()
@@ -50,14 +48,14 @@ client.registry
client.on('ready', () => {
client.logger.info(`[READY] Logged in as ${client.user.tag}! ID: ${client.user.id}`);
activities.push(
client.activities.push(
{ text: () => `${formatNumber(client.guilds.cache.size)} servers`, type: 'WATCHING' },
{ text: () => `with ${formatNumber(client.registry.commands.size)} commands`, type: 'PLAYING' },
{ text: () => `${formatNumber(client.users.cache.size)} users`, type: 'WATCHING' },
{ text: () => `${formatNumber(client.channels.cache.size)} channels`, type: 'WATCHING' }
);
client.setInterval(() => {
const activity = activities[Math.floor(Math.random() * activities.length)];
const activity = client.activities[Math.floor(Math.random() * client.activities.length)];
const text = typeof activity.text === 'function' ? activity.text() : activity.text;
client.user.setActivity(text, { type: activity.type });
}, 60000);
@@ -87,8 +85,8 @@ client.on('guildMemberRemove', async member => {
if (!channel || !channel.permissionsFor(client.user).has('SEND_MESSAGES')) return null;
if (channel.topic && channel.topic.includes('<xiao:disable-leave>')) return null;
try {
const leaveMsg = leaveMsgs[Math.floor(Math.random() * leaveMsgs.length)];
await channel.send(leaveMsg.replace(/{{user}}/gi, `**${member.user.tag}**`));
const leaveMessage = client.leaveMessages[Math.floor(Math.random() * client.leaveMessages.length)];
await channel.send(leaveMessage.replace(/{{user}}/gi, `**${member.user.tag}**`));
return null;
} catch {
return null;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "114.5.7",
"version": "114.5.8",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+5 -1
View File
@@ -4,6 +4,8 @@ const Collection = require('@discordjs/collection');
const winston = require('winston');
const PokemonStore = require('./pokemon/PokemonStore');
const MemePoster = require('./MemePoster');
const activities = require('../assets/json/activity');
const leaveMsgs = require('../assets/json/leave-messages');
const { XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN } = process.env;
module.exports = class XiaoClient extends CommandoClient {
@@ -17,10 +19,12 @@ module.exports = class XiaoClient extends CommandoClient {
winston.format.printf(log => `[${log.timestamp}] [${log.level.toUpperCase()}]: ${log.message}`)
)
});
this.webhook = new WebhookClient(XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN, { disableEveryone: true });
this.webhook = new WebhookClient(XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN, { disableMentions: 'everyone' });
this.pokemon = new PokemonStore();
this.memePoster = new MemePoster(this);
this.games = new Collection();
this.phone = new Collection();
this.activities = activities;
this.leaveMessages = leaveMsgs;
}
};