/* * Vencord, a Discord client mod * Copyright (c) 2024 nin0dev * SPDX-License-Identifier: GPL-3.0-or-later */ import "./style.css"; import { ApplicationCommandInputType, ApplicationCommandOptionType, sendBotMessage } from "@api/Commands"; import { getUserSettingLazy } from "@api/UserSettings"; import { InfoIcon } from "@components/Icons"; import { Devs } from "@utils/constants"; import { getCurrentChannel, getCurrentGuild } from "@utils/discord"; import { classes } from "@utils/misc"; import definePlugin from "@utils/types"; import { Forms, GuildMemberStore, GuildStore, Menu, Parser } from "@webpack/common"; import { GuildMember } from "discord-types/general"; import { PropsWithChildren, SVGProps } from "react"; import { showInRoleModal } from "./RoleMembersModal"; const DeveloperMode = getUserSettingLazy("appearance", "developerMode")!; interface BaseIconProps extends IconProps { viewBox: string; } interface IconProps extends SVGProps { className?: string; height?: string | number; width?: string | number; } function Icon({ height = 24, width = 24, className, children, viewBox, ...svgProps }: PropsWithChildren) { return ( {children} ); } function EyeIcon(props: IconProps) { return ( ); } function getMembersInRole(roleId: string, guildId: string) { const members = GuildMemberStore.getMembers(guildId); const membersInRole: GuildMember[] = []; members.forEach(member => { if (member.roles.includes(roleId)) { membersInRole.push(member); } }); return membersInRole; } export default definePlugin({ name: "InRole", description: "Know who is in a role (read plugin info!)", authors: [Devs.nin0dev], dependencies: ["UserSettingsAPI"], start() { // DeveloperMode needs to be enabled for the context menu to be shown DeveloperMode.updateSetting(true); }, settingsAboutComponent: () => { return ( <> {Parser.parse(":warning:")} Limitations If you don't have mod permissions on the server, and that server is large (over 100 members), the plugin may be limited in the following ways: • Offline members won't be listed • Up to 100 members will be listed by default. To get more, scroll down in the member list to load more members. ); }, commands: [ { name: "inrole", description: "Block someone", inputType: ApplicationCommandInputType.BUILT_IN, options: [ { name: "role", description: "The role", type: ApplicationCommandOptionType.ROLE, required: true }, ], execute: (args, ctx) => { // Guild check if (!ctx.guild) { return sendBotMessage(ctx.channel.id, { content: "Make sure that you are in a server." }); } const role = args[0].value; showInRoleModal(getMembersInRole(role, ctx.guild.id), role, ctx.channel.id); } } ], contextMenus: { "dev-context"(children, { id }: { id: string; }) { const guild = getCurrentGuild(); if (!guild) return; const channel = getCurrentChannel(); if (!channel) return; const role = GuildStore.getRole(guild.id, id); if (!role) return; children.push( { showInRoleModal(getMembersInRole(role.id, guild.id), role.id, channel.id); }} icon={InfoIcon} /> ); } } });