mirror of
https://github.com/PretendoNetwork/Yamamura.git
synced 2024-05-31 19:17:50 -04:00
Added member stats channels
This commit is contained in:
parent
66d6c4b1f6
commit
d209e29e88
|
@ -2,6 +2,7 @@ const Discord = require('discord.js');
|
|||
const discordModals = require('discord-modals');
|
||||
const setupGuild = require('./setup-guild');
|
||||
const guildMemberAddHandler = require('./events/guildMemberAdd');
|
||||
const guildMemberRemoveHandler = require('./events/guildMemberRemove');
|
||||
const interactionCreateHandler = require('./events/interactionCreate');
|
||||
const messageCreateHandler = require('./events/messageCreate');
|
||||
const modalSubmitHandler = require('./events/modalSubmit');
|
||||
|
@ -29,9 +30,9 @@ client.on('ready', async () => {
|
|||
});
|
||||
|
||||
client.on('guildMemberAdd', guildMemberAddHandler);
|
||||
client.on('guildMemberRemove', guildMemberRemoveHandler);
|
||||
client.on('interactionCreate', interactionCreateHandler);
|
||||
client.on('messageCreate', messageCreateHandler);
|
||||
client.on('modalSubmit', modalSubmitHandler);
|
||||
|
||||
|
||||
client.login(config.bot_token);
|
|
@ -1,10 +1,11 @@
|
|||
const Discord = require('discord.js');
|
||||
const util = require('../util');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.GuildMember} member
|
||||
*/
|
||||
function guildMemberAddHandler(member) {
|
||||
async function guildMemberAddHandler(member) {
|
||||
const welcomeEmbed = new Discord.MessageEmbed();
|
||||
|
||||
welcomeEmbed.setColor(0x1B1F3B);
|
||||
|
@ -60,10 +61,12 @@ function guildMemberAddHandler(member) {
|
|||
}
|
||||
]);
|
||||
|
||||
member.send({
|
||||
await member.send({
|
||||
content: 'Thank you for joining the Pretendo Network Discord server! Check below for some server information and links',
|
||||
embeds: [welcomeEmbed]
|
||||
});
|
||||
|
||||
await util.updateMemberCountChannels(member.guild);
|
||||
}
|
||||
|
||||
module.exports = guildMemberAddHandler;
|
12
src/events/guildMemberRemove.js
Normal file
12
src/events/guildMemberRemove.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
const Discord = require('discord.js');
|
||||
const util = require('../util');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.GuildMember} member
|
||||
*/
|
||||
async function guildMemberRemoveHandler(member) {
|
||||
await util.updateMemberCountChannels(member.guild);
|
||||
}
|
||||
|
||||
module.exports = guildMemberRemoveHandler;
|
|
@ -3,6 +3,7 @@ const { REST } = require('@discordjs/rest');
|
|||
const { Routes } = require('discord-api-types/v10');
|
||||
const { bot_token: botToken } = require('../config.json');
|
||||
const commands = require('./commands-manager');
|
||||
const util = require('./util');
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(botToken);
|
||||
|
||||
|
@ -26,6 +27,9 @@ async function setupGuild(guild) {
|
|||
// names should explain what they do
|
||||
await setupCategories(guild);
|
||||
await setupTextChannels(guild);
|
||||
await setupVoiceChannels(guild);
|
||||
|
||||
await util.updateMemberCountChannels(guild);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,6 +45,7 @@ async function deployCommands(guild) {
|
|||
* @param {Discord.Guild} guild
|
||||
*/
|
||||
async function setupCategories(guild) {
|
||||
await setupStatsCategory(guild);
|
||||
await setupPretendoCategory(guild);
|
||||
await setupModeratorCategory(guild);
|
||||
}
|
||||
|
@ -55,10 +60,45 @@ async function setupTextChannels(guild) {
|
|||
await setupModApplicationsChannel(guild);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.Guild} guild
|
||||
*/
|
||||
async function setupVoiceChannels(guild) {
|
||||
await setupMembersCountChannel(guild);
|
||||
await setupPeopleCountChannel(guild);
|
||||
await setupBotsCountChannel(guild);
|
||||
}
|
||||
|
||||
|
||||
/***************************
|
||||
* *
|
||||
* CATEGORY CHANNELS *
|
||||
* *
|
||||
***************************/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.Guild} guild
|
||||
*/
|
||||
async function setupStatsCategory(guild) {
|
||||
const channels = await guild.channels.fetch();
|
||||
let category = channels.find(channel => channel.type === 'GUILD_CATEGORY' && channel.name === 'stats');
|
||||
|
||||
if (!category) {
|
||||
category = await guild.channels.create('stats', {
|
||||
type: 'GUILD_CATEGORY'
|
||||
});
|
||||
}
|
||||
|
||||
if (category.position !== 0) {
|
||||
await category.setPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.Guild} guild
|
||||
* @returns {Discord.CategoryChannel} category
|
||||
*/
|
||||
async function setupPretendoCategory(guild) {
|
||||
const channels = await guild.channels.fetch();
|
||||
|
@ -253,6 +293,12 @@ async function setupReadmeChannel(guild) {
|
|||
}
|
||||
}
|
||||
|
||||
/***********************
|
||||
* *
|
||||
* TEXT CHANNELS *
|
||||
* *
|
||||
***********************/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.Guild} guild
|
||||
|
@ -337,7 +383,6 @@ async function setupRulesChannel(guild) {
|
|||
/**
|
||||
*
|
||||
* @param {Discord.Guild} guild
|
||||
* @returns {Discord.CategoryChannel} category
|
||||
*/
|
||||
async function setupModeratorCategory(guild) {
|
||||
const channels = await guild.channels.fetch();
|
||||
|
@ -406,4 +451,109 @@ async function setupModApplicationsChannel(guild) {
|
|||
await channel.permissionOverwrites.set(permissionOverwrites);
|
||||
}
|
||||
|
||||
/************************
|
||||
* *
|
||||
* VOICE CHANNELS *
|
||||
* *
|
||||
************************/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.Guild} guild
|
||||
*/
|
||||
async function setupMembersCountChannel(guild) {
|
||||
const channels = await guild.channels.fetch();
|
||||
const category = channels.find(channel => channel.type === 'GUILD_CATEGORY' && channel.name === 'stats');
|
||||
let channel = channels.find(channel => channel.type === 'GUILD_VOICE' && channel.name.startsWith('Members'));
|
||||
|
||||
if (!channel) {
|
||||
channel = await guild.channels.create('Members - 0', {
|
||||
type: 'GUILD_VOICE',
|
||||
});
|
||||
}
|
||||
|
||||
if (channel.parentId !== category.id) {
|
||||
await channel.setParent(category);
|
||||
}
|
||||
|
||||
if (channel.position !== 0) {
|
||||
await channel.setPosition(0);
|
||||
}
|
||||
|
||||
const permissionOverwrites = [{
|
||||
id: guild.roles.everyone,
|
||||
deny: [
|
||||
Discord.Permissions.FLAGS.CONNECT
|
||||
]
|
||||
}];
|
||||
|
||||
await channel.permissionOverwrites.set(permissionOverwrites);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.Guild} guild
|
||||
*/
|
||||
async function setupPeopleCountChannel(guild) {
|
||||
const channels = await guild.channels.fetch();
|
||||
const category = channels.find(channel => channel.type === 'GUILD_CATEGORY' && channel.name === 'stats');
|
||||
let channel = channels.find(channel => channel.type === 'GUILD_VOICE' && channel.name.startsWith('People'));
|
||||
|
||||
if (!channel) {
|
||||
channel = await guild.channels.create('People - 0', {
|
||||
type: 'GUILD_VOICE',
|
||||
});
|
||||
}
|
||||
|
||||
if (channel.parentId !== category.id) {
|
||||
await channel.setParent(category);
|
||||
}
|
||||
|
||||
if (channel.position !== 1) {
|
||||
await channel.setPosition(1);
|
||||
}
|
||||
|
||||
const permissionOverwrites = [{
|
||||
id: guild.roles.everyone,
|
||||
deny: [
|
||||
Discord.Permissions.FLAGS.CONNECT
|
||||
]
|
||||
}];
|
||||
|
||||
await channel.permissionOverwrites.set(permissionOverwrites);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.Guild} guild
|
||||
*/
|
||||
async function setupBotsCountChannel(guild) {
|
||||
const channels = await guild.channels.fetch();
|
||||
const category = channels.find(channel => channel.type === 'GUILD_CATEGORY' && channel.name === 'stats');
|
||||
let channel = channels.find(channel => channel.type === 'GUILD_VOICE' && channel.name.startsWith('Bots'));
|
||||
|
||||
if (!channel) {
|
||||
channel = await guild.channels.create('Bots - 0', {
|
||||
type: 'GUILD_VOICE',
|
||||
});
|
||||
}
|
||||
|
||||
if (channel.parentId !== category.id) {
|
||||
await channel.setParent(category);
|
||||
}
|
||||
|
||||
if (channel.position !== 2) {
|
||||
await channel.setPosition(2);
|
||||
}
|
||||
|
||||
const permissionOverwrites = [{
|
||||
id: guild.roles.everyone,
|
||||
deny: [
|
||||
Discord.Permissions.FLAGS.CONNECT
|
||||
]
|
||||
}];
|
||||
|
||||
await channel.permissionOverwrites.set(permissionOverwrites);
|
||||
}
|
||||
|
||||
module.exports = setupGuild;
|
36
src/util.js
Normal file
36
src/util.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
const Discord = require('discord.js');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Discord.Guild} guild
|
||||
*/
|
||||
|
||||
async function updateMemberCountChannels(guild) {
|
||||
const channels = await guild.channels.fetch();
|
||||
|
||||
const membersChannel = channels.find(channel => channel.type === 'GUILD_VOICE' && channel.name.startsWith('Members'));
|
||||
const peopleChannel = channels.find(channel => channel.type === 'GUILD_VOICE' && channel.name.startsWith('People'));
|
||||
const botsChannel = channels.find(channel => channel.type === 'GUILD_VOICE' && channel.name.startsWith('Bots'));
|
||||
|
||||
const members = await guild.members.fetch();
|
||||
const membersCount = guild.memberCount;
|
||||
let peopleCount = 0;
|
||||
let botsCount = 0;
|
||||
|
||||
// Only loop once
|
||||
members.forEach(member => {
|
||||
if (member.user.bot) {
|
||||
botsCount += 1;
|
||||
} else {
|
||||
peopleCount += 1;
|
||||
}
|
||||
});
|
||||
|
||||
await membersChannel.setName(`Members - ${membersCount}`);
|
||||
await peopleChannel.setName(`People - ${peopleCount}`);
|
||||
await botsChannel.setName(`Bots - ${botsCount}`);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
updateMemberCountChannels
|
||||
};
|
Loading…
Reference in a new issue