diff --git a/modules/channel-stats/channels.json b/modules/channel-stats/channels.json index 9570f679..692dab81 100644 --- a/modules/channel-stats/channels.json +++ b/modules/channel-stats/channels.json @@ -83,6 +83,14 @@ { "name": "%currentTime%", "description": "Current time and date" + }, + { + "name": "%userWithRoleCount-%", + "description": "Count of members with a specific role (replace \"\" with an actual role-id)" + }, + { + "name": "%onlineUserWithRoleCount-%", + "description": "Count of members with a specific role who are online (replace \"\" with an actual role-id)" } ], "humanname-de": "Kanalname", @@ -98,10 +106,6 @@ }, { "name": "%onlineUserCount%", - "description": "Anzahl an Nutzern auf dem Server, welche Online sind (Bitte nicht stören oder Online Status)" - }, - { - "name": "%onlineMemberCount%", "description": "Anzahl an Mitgliedern (keine Bots) auf dem Server, welche Online sind (Bitte nicht stören oder Online Status)" }, { @@ -151,6 +155,14 @@ { "name": "%currentTime%", "description": "Aktuelles Datum und Uhrzeit" + }, + { + "name": "%userWithRoleCount-%", + "description": "Anzahl von Nutzern mit einer bestimmen Rolle (bitte \"\" mit einer echten Rollen-ID ersetzen)" + }, + { + "name": "%onlineUserWithRoleCount-%", + "description": "Anzahl von Nutzern mit einer bestimmen Rolle, die online sind (bitte \"\" mit einer echten Rollen-ID ersetzen)" } ], "default-de": "" diff --git a/modules/channel-stats/events/botReady.js b/modules/channel-stats/events/botReady.js index 3b0ea112..f14b84d1 100644 --- a/modules/channel-stats/events/botReady.js +++ b/modules/channel-stats/events/botReady.js @@ -2,12 +2,12 @@ const {formatDate} = require('../../../src/functions/helpers'); const {localize} = require('../../../src/functions/localize'); module.exports.run = async (client) => { - const channels = require(`${client.configDir}/channel-stats/channels.json`); + const channels = client.configurations['channel-stats']['channels']; for (const channel of channels) { const dcChannel = await client.channels.fetch(channel.channelID).catch(() => { }); if (!dcChannel) continue; - if (dcChannel.type !== 'GUILD_VOICE') client.logger.warn(`[channel-stats] ` + localize('channel-stats', 'not-voice-channel-info', { + if (dcChannel.type !== 'GUILD_VOICE' && dcChannel.type !== 'GUILD_CATEGORY') client.logger.warn(`[channel-stats] ` + localize('channel-stats', 'not-voice-channel-info', { c: dcChannel.name, id: dcChannel.id, t: dcChannel.type @@ -32,6 +32,29 @@ module.exports.run = async (client) => { async function channelNameReplacer(client, channel, input) { const users = await channel.guild.members.fetch(); const members = users.filter(u => !u.user.bot); + + /** + * Replaces the first member-with-role-count parameters of the input + * @private + */ + function replaceFirst() { + if (input.includes('%userWithRoleCount-')) { + const id = input.split('%userWithRoleCount-')[1].split('%')[0]; + if (input.includes(`%userWithRoleCount-${id}%`)) { + input = input.replaceAll(`%userWithRoleCount-${id}%`, users.filter(f => f.roles.cache.has(id)).size.toString()); + replaceFirst(); + } + } + if (input.includes('%onlineUserWithRoleCount-')) { + const id = input.split('%onlineUserWithRoleCount-')[1].split('%')[0]; + if (input.includes(`%onlineUserWithRoleCount-${id}%`)) { + input = input.replaceAll(`%onlineUserWithRoleCount-${id}%`, users.filter(f => f.roles.cache.has(id) && f.presence && (f.presence || {}).status !== 'offline').size.toString()); + replaceFirst(); + } + } + } + + replaceFirst(); return input.split('%userCount%').join(users.size) .split('%memberCount%').join(members.size) .split('%onlineUserCount%').join(users.filter(u => u.presence && (u.presence || {}).status !== 'offline').size)