diff options
author | Nico <nico@d3sox.me> | 2022-10-25 17:32:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-25 17:32:05 +0200 |
commit | 2f46b934c960f4289cd72db225a060d4c2093406 (patch) | |
tree | 0d56f8cde73df818b45919677f50efea7d1a4a60 | |
parent | 2af324c3020697d7be36048ede1252fa9d6c98fa (diff) | |
download | Vencord-2f46b934c960f4289cd72db225a060d4c2093406.tar.gz Vencord-2f46b934c960f4289cd72db225a060d4c2093406.tar.bz2 Vencord-2f46b934c960f4289cd72db225a060d4c2093406.zip |
feat: add new plugin ForceOwnerCrown (#157)
-rw-r--r-- | src/plugins/forceOwnerCrown.ts | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/plugins/forceOwnerCrown.ts b/src/plugins/forceOwnerCrown.ts new file mode 100644 index 0000000..b942d9a --- /dev/null +++ b/src/plugins/forceOwnerCrown.ts @@ -0,0 +1,56 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +import { Devs } from "../utils/constants"; +import definePlugin from "../utils/types"; +import { waitFor } from "../webpack"; + +let GuildStore; +waitFor(["getGuild"], m => GuildStore = m); + +export default definePlugin({ + name: "ForceOwnerCrown", + description: "Force the owner crown next to usernames even if the server is large.", + authors: [Devs.D3SOX], + patches: [ + { + // This is the logic where it decides whether to render the owner crown or not + find: ".renderOwner=", + replacement: { + match: /isOwner;return null!=(\w+)?&&/g, + replace: "isOwner;if(Vencord.Plugins.plugins.ForceOwnerCrown.isGuildOwner(this.props)){$1=true;}return null!=$1&&" + } + }, + ], + isGuildOwner(props) { + // guild id is in props twice, fallback if the first is undefined + const guildId = props?.guildId ?? props?.channel?.guild_id; + const userId = props?.user?.id; + + if (guildId && userId) { + const guild = GuildStore.getGuild(guildId); + if (guild) { + return guild.ownerId === userId; + } + console.error("[ForceOwnerCrown] failed to get guild", { guildId, guild, props }); + } else { + console.error("[ForceOwnerCrown] no guildId or userId", { guildId, userId, props }); + } + return false; + }, +}); |