This commit is contained in:
nin0dev 2024-09-01 08:52:25 -04:00
commit 562e8065c2
Signed by: nin0
GPG key ID: 3FA8F96ABAE04214
3 changed files with 177 additions and 0 deletions

59
Modals.tsx Normal file
View file

@ -0,0 +1,59 @@
import ErrorBoundary from "@components/ErrorBoundary";
import { openModal, ModalRoot, ModalSize, ModalHeader, ModalCloseButton, ModalContent, closeModal, closeAllModals } from "@utils/modal";
import { Button, Forms, Parser, TextInput } from "@webpack/common";
import { cl } from "plugins/memberCount";
import { SelectedChannelStore, useState } from "@webpack/common";
import "./style.css";
import { sendMessage } from "@utils/discord";
export function showPrefefinedDurationModal(duration: string, id: string) {
let reason = "";
openModal(props =>
<>
<ErrorBoundary>
<ModalRoot {...props} size={ModalSize.DYNAMIC} fullscreenOnMobile={true} >
<ModalHeader className={cl("header")}>
<Forms.FormText style={{ fontSize: "1.2rem", fontWeight: "bold", marginRight: "7px" }}>Mute user</Forms.FormText>
</ModalHeader>
<ModalContent>
<TextInput onChange={v => { reason = v; }} placeholder="Reason" className="vc-punishcommands-reason" />
<div className="vc-punishcommands-button-container">
<Button color={Button.Colors.RED} onClick={() => {
sendMessage(SelectedChannelStore.getChannelId(), { content: `+Cg ${id} ${duration} ${reason}` });
closeAllModals();
}}>Mute</Button>
</div>
</ModalContent>
</ModalRoot>
</ErrorBoundary>
</>
);
}
export function showCustomDurationModal(id: string) {
let duration = "";
let reason = "";
let pendingSend = false;
openModal(props =>
<>
<ErrorBoundary>
<ModalRoot {...props} size={ModalSize.DYNAMIC} fullscreenOnMobile={true} >
<ModalHeader className={cl("header")}>
<Forms.FormText style={{ fontSize: "1.2rem", fontWeight: "bold", marginRight: "7px" }}>Mute user</Forms.FormText>
</ModalHeader>
<ModalContent>
<TextInput onChange={v => { duration = v; }} placeholder="Duration (as written in the command)" className="vc-punishcommands-duration-c" />
<TextInput onChange={v => { reason = v; }} placeholder="Reason" className="vc-punishcommands-reason-c" />
<div className="vc-punishcommands-button-container">
<Button color={Button.Colors.RED} onClick={() => {
if (pendingSend) return;
pendingSend = true;
sendMessage(SelectedChannelStore.getChannelId(), { content: `+Cg ${id} ${duration} ${reason}` });
closeAllModals();
}}>Mute</Button>
</div>
</ModalContent>
</ModalRoot>
</ErrorBoundary>
</>
);
}

63
index.tsx Normal file
View file

@ -0,0 +1,63 @@
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { ImageIcon, SafetyIcon } from "@components/Icons";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { showCustomDurationModal, showPrefefinedDurationModal } from "./Modals";
import { GuildMemberStore, i18n, IconUtils, Menu, SelectedGuildStore } from "@webpack/common";
import { UserContextProps } from "plugins/biggerStreamPreview";
/**** BEGIN CONFIG ****/
const GUILD_ID = "1274790619146879108"; // SERVER ID
/**** END CONFIG ****/
const UserContext: NavContextMenuPatchCallback = (children, { user }: UserContextProps) => {
if (!user) return;
children.splice(-3, 0,
(
<>
{SelectedGuildStore.getGuildId() === GUILD_ID &&
<>
<Menu.MenuItem id="vc-staff" label="Staff">
<Menu.MenuItem
id="mute-1h"
color="#ff0000"
label="Mute for 1 hour"
action={() => {
showPrefefinedDurationModal("1h", user.id);
}}
icon={SafetyIcon}
/>
<Menu.MenuItem
id="mute-2h"
color="#ff0000"
label="Mute for 2 hours"
action={() => {
showPrefefinedDurationModal("2h", user.id);
}}
icon={SafetyIcon}
/>
<Menu.MenuItem
id="mute-custom"
color="#ff0000"
label="Mute (custom duration)"
action={() => {
showCustomDurationModal(user.id);
}}
icon={SafetyIcon}
/>
</Menu.MenuItem>
</>
}
</>
)
);
};
export default definePlugin({
name: "PunishmentCommands",
description: "Allows you to send a command in chat to punish someone, right from the context menu",
authors: [Devs.nin0dev],
contextMenus: {
"user-context": UserContext
}
});

55
style.css Normal file
View file

@ -0,0 +1,55 @@
/* stylelint-disable selector-id-pattern */
/* stylelint-disable declaration-block-no-redundant-longhand-properties */
#user-context-vc-staff--mute-1h {
color: var(--status-danger);
}
#user-context-vc-staff--mute-1h[class*="focused"] {
background-color: var(--menu-item-danger-hover-bg);
color: white;
}
#user-context-vc-staff--mute-2h {
color: var(--status-danger);
}
#user-context-vc-staff--mute-2h[class*="focused"] {
background-color: var(--menu-item-danger-hover-bg);
color: white;
}
#user-context-vc-staff--mute-custom {
color: var(--status-danger);
}
#user-context-vc-staff--mute-custom[class*="focused"] {
background-color: var(--menu-item-danger-hover-bg);
color: white;
}
.vc-punishcommands-reason {
margin: 20px;
min-width: 500px;
}
.vc-punishcommands-button-container * {
margin-left: auto;
margin-right: 20px;
margin-bottom: 20px;
}
.vc-punishcommands-duration-c {
margin-top: 20px;
margin-bottom: 10px;
min-width: 500px;
margin-left: 20px;
margin-right: 20px;
}
.vc-punishcommands-reason-c {
margin-bottom: 20px;
min-width: 500px;
margin-left: 20px;
margin-right: 20px;
}