aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/forceOwnerCrown.ts
blob: 0c1df4780a38d97f61c0a169187961cfcab8d83c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * 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 { GuildStore } from "@webpack/common";

export default definePlugin({
    name: "ForceOwnerCrown",
    description: "Force the owner crown next to usernames even if the server is large.",
    authors: [Devs.D3SOX, Devs.Nickyux],
    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) {
        // Check if channel is a Group DM, if so return false
        if (props?.channel?.type === 3) {
            return false;
        }

        // 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;
    },
});