From 51f78e5caf9308e01acb744bfca4a370d64e8b54 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Sat, 8 Feb 2025 15:21:43 -0500 Subject: [PATCH] Add RoleMembersViewer to InRole --- README.md | 3 +- src/equicordplugins/inRole/index.tsx | 26 +++ .../roleMembersViewer/index.tsx | 151 ------------------ 3 files changed, 28 insertions(+), 152 deletions(-) delete mode 100644 src/equicordplugins/roleMembersViewer/index.tsx diff --git a/README.md b/README.md index da3cefc9..e0c1d63e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch ### Extra included plugins
-151 additional plugins +152 additional plugins ### All Platforms - AllCallTimers by MaxHerbold & D3SOX @@ -109,6 +109,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch - PinIcon by iamme - PolishWording (Grammar) by Samwich - PlatformSpoofer by Drag +- PreMiD by Nyako - PurgeMessages by bhop & nyx - QuestCompleter by HappyEnderman, SerStars, maintained by thororen - QuestionMarkReplacement by nyx diff --git a/src/equicordplugins/inRole/index.tsx b/src/equicordplugins/inRole/index.tsx index 37c0b379..d203c49a 100644 --- a/src/equicordplugins/inRole/index.tsx +++ b/src/equicordplugins/inRole/index.tsx @@ -85,6 +85,32 @@ export default definePlugin({ const role = GuildStore.getRole(guild.id, id); if (!role) return; + children.push( + { + showInRoleModal(getMembersInRole(role.id, guild.id), role.id, channel.id); + }} + icon={InfoIcon} + /> + ); + }, + "message"(children, { message }: { message: any; }) { + const guild = getCurrentGuild(); + if (!guild) return; + + const roleMentions = message.content.match(/<@&(\d+)>/g); + if (!roleMentions?.length) return; + + const channel = getCurrentChannel(); + if (!channel) return; + + const roleIds = roleMentions.map(mention => mention.match(/<@&(\d+)>/)![1]); + + const role = GuildStore.getRole(guild.id, roleIds); + if (!role) return; + children.push( { - if (member.roles.includes(roleId)) { - membersInRole++; - } - }); - if (Object.keys(guildMembers).length < membersInRole) { - const chunk = 100; - const requestCount = Math.ceil(membersInRole / chunk); - for (let i = 0; i < requestCount; i++) { - FluxDispatcher.dispatch({ - type: "GUILD_MEMBERS_REQUEST", - guildId, - userIds: [], - query: "", - limit: chunk, - withPresences: true, - notifyOnLimit: true - }); - } - } - const updatedGuildMembers = GuildMemberStore.getMembers(guildId); - return Object.values(updatedGuildMembers) - .filter(m => m.roles.includes(roleId)) - .map(m => ({ - ...m, - user: UserStore.getUser(m.userId) - })) - .sort((a, b) => a.user.username.localeCompare(b.user.username)); -} - -export default definePlugin({ - name: "RoleMembersViewer", - description: "Shows members with a role when right clicking roles in user profiles or role mentions in messages", - authors: [EquicordDevs.okiso], - - contextMenus: { - "dev-context"(children, { id }: { id: string; }) { - const guild = GuildStore.getGuild(SelectedGuildStore.getGuildId()); - if (!guild) return; - - const role = GuildStore.getRole(guild.id, id); - if (!role) return; - - const guildId = guild.id; - const membersWithRole = fetchMembersWithRole(guildId, id); - - const memberItems = membersWithRole.map(member => ( - { - UserProfileActions.openUserProfileModal({ - userId: member.userId, - guildId, - channelId: SelectedChannelStore.getChannelId() - }); - }} - /> - )); - - children.push( - - {memberItems} - - ); - }, - - "message"(children, { message }: { message: any; }) { - const guild = GuildStore.getGuild(SelectedGuildStore.getGuildId()); - if (!guild) return; - - const roleMentions = message.content.match(/<@&(\d+)>/g); - if (!roleMentions?.length) return; - - // Extract unique role IDs from the mentions. - const roleIds = roleMentions.map(mention => mention.match(/<@&(\d+)>/)![1]); - const uniqueRoleIds = [...new Set(roleIds)]; - - const guildId = guild.id; - const roleMenuItems: JSX.Element[] = []; - - for (const roleId of uniqueRoleIds as string[]) { - const role = GuildStore.getRole(guildId, roleId); - if (!role) continue; - - const membersWithRole = fetchMembersWithRole(guildId, roleId); - const memberItems = membersWithRole.map(member => ( - { - UserProfileActions.openUserProfileModal({ - userId: member.userId, - guildId, - channelId: SelectedChannelStore.getChannelId() - }); - }} - /> - )); - - roleMenuItems.push( - - {memberItems} - - ); - } - - if (roleMenuItems.length > 0) { - children.push( - - {roleMenuItems} - - ); - } - } - } -});