mirror of
https://github.com/Vendicated/Vencord.git
synced 2024-09-20 06:30:35 +00:00
Compare commits
20 commits
f53fb6946c
...
fe7402a082
Author | SHA1 | Date | |
---|---|---|---|
|
fe7402a082 | ||
|
6cce8a8bc4 | ||
|
1848b16536 | ||
|
c572116b97 | ||
|
e26986f66a | ||
|
cecba0029f | ||
|
2e0977dd2b | ||
|
1b9ea1f413 | ||
|
cfb4972394 | ||
|
d0f048f81d | ||
|
a6058f8285 | ||
|
d17c0ea387 | ||
|
7ceaa5a6f0 | ||
|
2099d6ec94 | ||
|
2c33b5ac4d | ||
|
c27e01591e | ||
|
e5f743c922 | ||
|
8c0d54f13a | ||
|
ad64da0621 | ||
|
49c48393e0 |
16 changed files with 551 additions and 125 deletions
|
@ -24,7 +24,7 @@ interface ActivityButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Activity {
|
interface Activity {
|
||||||
state: string;
|
state?: string;
|
||||||
details?: string;
|
details?: string;
|
||||||
timestamps?: {
|
timestamps?: {
|
||||||
start?: number;
|
start?: number;
|
||||||
|
@ -52,8 +52,8 @@ const enum ActivityFlag {
|
||||||
|
|
||||||
export interface TrackData {
|
export interface TrackData {
|
||||||
name: string;
|
name: string;
|
||||||
album: string;
|
album?: string;
|
||||||
artist: string;
|
artist?: string;
|
||||||
|
|
||||||
appleMusicLink?: string;
|
appleMusicLink?: string;
|
||||||
songLink?: string;
|
songLink?: string;
|
||||||
|
@ -61,8 +61,8 @@ export interface TrackData {
|
||||||
albumArtwork?: string;
|
albumArtwork?: string;
|
||||||
artistArtwork?: string;
|
artistArtwork?: string;
|
||||||
|
|
||||||
playerPosition: number;
|
playerPosition?: number;
|
||||||
duration: number;
|
duration?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const enum AssetImageType {
|
const enum AssetImageType {
|
||||||
|
@ -155,8 +155,8 @@ const settings = definePluginSettings({
|
||||||
function customFormat(formatStr: string, data: TrackData) {
|
function customFormat(formatStr: string, data: TrackData) {
|
||||||
return formatStr
|
return formatStr
|
||||||
.replaceAll("{name}", data.name)
|
.replaceAll("{name}", data.name)
|
||||||
.replaceAll("{album}", data.album)
|
.replaceAll("{album}", data.album ?? "")
|
||||||
.replaceAll("{artist}", data.artist);
|
.replaceAll("{artist}", data.artist ?? "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getImageAsset(type: AssetImageType, data: TrackData) {
|
function getImageAsset(type: AssetImageType, data: TrackData) {
|
||||||
|
@ -212,14 +212,16 @@ export default definePlugin({
|
||||||
|
|
||||||
const assets: ActivityAssets = {};
|
const assets: ActivityAssets = {};
|
||||||
|
|
||||||
|
const isRadio = Number.isNaN(trackData.duration) && (trackData.playerPosition === 0);
|
||||||
|
|
||||||
if (settings.store.largeImageType !== AssetImageType.Disabled) {
|
if (settings.store.largeImageType !== AssetImageType.Disabled) {
|
||||||
assets.large_image = largeImageAsset;
|
assets.large_image = largeImageAsset;
|
||||||
assets.large_text = customFormat(settings.store.largeTextString, trackData);
|
if (!isRadio) assets.large_text = customFormat(settings.store.largeTextString, trackData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.store.smallImageType !== AssetImageType.Disabled) {
|
if (settings.store.smallImageType !== AssetImageType.Disabled) {
|
||||||
assets.small_image = smallImageAsset;
|
assets.small_image = smallImageAsset;
|
||||||
assets.small_text = customFormat(settings.store.smallTextString, trackData);
|
if (!isRadio) assets.small_text = customFormat(settings.store.smallTextString, trackData);
|
||||||
}
|
}
|
||||||
|
|
||||||
const buttons: ActivityButton[] = [];
|
const buttons: ActivityButton[] = [];
|
||||||
|
@ -243,17 +245,17 @@ export default definePlugin({
|
||||||
|
|
||||||
name: customFormat(settings.store.nameString, trackData),
|
name: customFormat(settings.store.nameString, trackData),
|
||||||
details: customFormat(settings.store.detailsString, trackData),
|
details: customFormat(settings.store.detailsString, trackData),
|
||||||
state: customFormat(settings.store.stateString, trackData),
|
state: isRadio ? undefined : customFormat(settings.store.stateString, trackData),
|
||||||
|
|
||||||
timestamps: (settings.store.enableTimestamps ? {
|
timestamps: (trackData.playerPosition && trackData.duration && settings.store.enableTimestamps) ? {
|
||||||
start: Date.now() - (trackData.playerPosition * 1000),
|
start: Date.now() - (trackData.playerPosition * 1000),
|
||||||
end: Date.now() - (trackData.playerPosition * 1000) + (trackData.duration * 1000),
|
end: Date.now() - (trackData.playerPosition * 1000) + (trackData.duration * 1000),
|
||||||
} : undefined),
|
} : undefined,
|
||||||
|
|
||||||
assets,
|
assets,
|
||||||
|
|
||||||
buttons: buttons.length ? buttons.map(v => v.label) : undefined,
|
buttons: !isRadio && buttons.length ? buttons.map(v => v.label) : undefined,
|
||||||
metadata: { button_urls: buttons.map(v => v.url) || undefined, },
|
metadata: !isRadio && buttons.length ? { button_urls: buttons.map(v => v.url) } : undefined,
|
||||||
|
|
||||||
type: settings.store.activityType,
|
type: settings.store.activityType,
|
||||||
flags: ActivityFlag.INSTANCE,
|
flags: ActivityFlag.INSTANCE,
|
||||||
|
|
68
src/plugins/betterSettings/PluginsSubmenu.tsx
Normal file
68
src/plugins/betterSettings/PluginsSubmenu.tsx
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2024 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { openPluginModal } from "@components/PluginSettings/PluginModal";
|
||||||
|
import { isObjectEmpty } from "@utils/misc";
|
||||||
|
import { Alerts, i18n, Menu, useMemo, useState } from "@webpack/common";
|
||||||
|
|
||||||
|
import Plugins from "~plugins";
|
||||||
|
|
||||||
|
function onRestartNeeded() {
|
||||||
|
Alerts.show({
|
||||||
|
title: "Restart required",
|
||||||
|
body: <p>You have changed settings that require a restart.</p>,
|
||||||
|
confirmText: "Restart now",
|
||||||
|
cancelText: "Later!",
|
||||||
|
onConfirm: () => location.reload()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function PluginsSubmenu() {
|
||||||
|
const sortedPlugins = useMemo(() => Object.values(Plugins)
|
||||||
|
.sort((a, b) => a.name.localeCompare(b.name)), []);
|
||||||
|
const [query, setQuery] = useState("");
|
||||||
|
|
||||||
|
const search = query.toLowerCase();
|
||||||
|
const include = (p: typeof Plugins[keyof typeof Plugins]) => (
|
||||||
|
Vencord.Plugins.isPluginEnabled(p.name)
|
||||||
|
&& p.options && !isObjectEmpty(p.options)
|
||||||
|
&& (
|
||||||
|
p.name.toLowerCase().includes(search)
|
||||||
|
|| p.description.toLowerCase().includes(search)
|
||||||
|
|| p.tags?.some(t => t.toLowerCase().includes(search))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const plugins = sortedPlugins.filter(include);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Menu.MenuControlItem
|
||||||
|
id="vc-plugins-search"
|
||||||
|
control={(props, ref) => (
|
||||||
|
<Menu.MenuSearchControl
|
||||||
|
{...props}
|
||||||
|
query={query}
|
||||||
|
onChange={setQuery}
|
||||||
|
ref={ref}
|
||||||
|
placeholder={i18n.Messages.SEARCH}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!!plugins.length && <Menu.MenuSeparator />}
|
||||||
|
|
||||||
|
{plugins.map(p => (
|
||||||
|
<Menu.MenuItem
|
||||||
|
key={p.name}
|
||||||
|
id={p.name}
|
||||||
|
label={p.name}
|
||||||
|
action={() => openPluginModal(p, onRestartNeeded)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
|
@ -13,6 +13,8 @@ import { waitFor } from "@webpack";
|
||||||
import { ComponentDispatch, FocusLock, i18n, Menu, useEffect, useRef } from "@webpack/common";
|
import { ComponentDispatch, FocusLock, i18n, Menu, useEffect, useRef } from "@webpack/common";
|
||||||
import type { HTMLAttributes, ReactElement } from "react";
|
import type { HTMLAttributes, ReactElement } from "react";
|
||||||
|
|
||||||
|
import PluginsSubmenu from "./PluginsSubmenu";
|
||||||
|
|
||||||
type SettingsEntry = { section: string, label: string; };
|
type SettingsEntry = { section: string, label: string; };
|
||||||
|
|
||||||
const cl = classNameFactory("");
|
const cl = classNameFactory("");
|
||||||
|
@ -118,13 +120,21 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
{ // Settings cog context menu
|
{ // Settings cog context menu
|
||||||
find: "Messages.USER_SETTINGS_ACTIONS_MENU_LABEL",
|
find: "Messages.USER_SETTINGS_ACTIONS_MENU_LABEL",
|
||||||
replacement: {
|
replacement: [
|
||||||
match: /(EXPERIMENTS:.+?)(\(0,\i.\i\)\(\))(?=\.filter\(\i=>\{let\{section:\i\}=)/,
|
{
|
||||||
replace: "$1$self.wrapMenu($2)"
|
match: /(EXPERIMENTS:.+?)(\(0,\i.\i\)\(\))(?=\.filter\(\i=>\{let\{section:\i\}=)/,
|
||||||
}
|
replace: "$1$self.wrapMenu($2)"
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
match: /case \i\.\i\.DEVELOPER_OPTIONS:return \i;/,
|
||||||
|
replace: "$&case 'VencordPlugins':return $self.PluginsSubmenu();"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
|
PluginsSubmenu,
|
||||||
|
|
||||||
// This is the very outer layer of the entire ui, so we can't wrap this in an ErrorBoundary
|
// This is the very outer layer of the entire ui, so we can't wrap this in an ErrorBoundary
|
||||||
// without possibly also catching unrelated errors of children.
|
// without possibly also catching unrelated errors of children.
|
||||||
//
|
//
|
||||||
|
|
|
@ -126,7 +126,7 @@ export default definePlugin({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
find: '"Handling ping: "',
|
find: '"_handleLocalVideoDisabled: ',
|
||||||
predicate: () => settings.store.disableNoisyLoggers,
|
predicate: () => settings.store.disableNoisyLoggers,
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /new \i\.\i\("RTCConnection\("\.concat.+?\)\)(?=,)/,
|
match: /new \i\.\i\("RTCConnection\("\.concat.+?\)\)(?=,)/,
|
||||||
|
|
|
@ -23,12 +23,13 @@ import { ErrorCard } from "@components/ErrorCard";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { findByPropsLazy } from "@webpack";
|
import { findByPropsLazy, findLazy } from "@webpack";
|
||||||
import { Forms, React } from "@webpack/common";
|
import { Forms, React } from "@webpack/common";
|
||||||
|
|
||||||
import hideBugReport from "./hideBugReport.css?managed";
|
import hideBugReport from "./hideBugReport.css?managed";
|
||||||
|
|
||||||
const KbdStyles = findByPropsLazy("key", "combo");
|
const KbdStyles = findByPropsLazy("key", "combo");
|
||||||
|
const BugReporterExperiment = findLazy(m => m?.definition?.id === "2024-09_bug_reporter");
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
toolbarDevMenu: {
|
toolbarDevMenu: {
|
||||||
|
@ -78,8 +79,8 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: "toolbar:function",
|
find: "toolbar:function",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /\i\.isStaff\(\)/,
|
match: /hasBugReporterAccess:(\i)/,
|
||||||
replace: "true"
|
replace: "_hasBugReporterAccess:$1=true"
|
||||||
},
|
},
|
||||||
predicate: () => settings.store.toolbarDevMenu
|
predicate: () => settings.store.toolbarDevMenu
|
||||||
},
|
},
|
||||||
|
@ -91,10 +92,18 @@ export default definePlugin({
|
||||||
match: /\i\.isDM\(\)\|\|\i\.isThread\(\)/,
|
match: /\i\.isDM\(\)\|\|\i\.isThread\(\)/,
|
||||||
replace: "false",
|
replace: "false",
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// enable option to always record clips even if you are not streaming
|
||||||
|
{
|
||||||
|
find: "isDecoupledGameClippingEnabled(){",
|
||||||
|
replacement: {
|
||||||
|
match: /\i\.isStaff\(\)/,
|
||||||
|
replace: "true"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
start: () => enableStyle(hideBugReport),
|
start: () => !BugReporterExperiment.getCurrentConfig().hasBugReporterAccess && enableStyle(hideBugReport),
|
||||||
stop: () => disableStyle(hideBugReport),
|
stop: () => disableStyle(hideBugReport),
|
||||||
|
|
||||||
settingsAboutComponent: () => {
|
settingsAboutComponent: () => {
|
||||||
|
|
|
@ -91,7 +91,7 @@ export default definePlugin({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
find: ".PANEL,isInteractionSource:",
|
find: ".PANEL,interactionType:",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /{profileType:\i\.\i\.PANEL,children:\[/,
|
match: /{profileType:\i\.\i\.PANEL,children:\[/,
|
||||||
replace: "$&$self.BiteSizeReviewsButton({user:arguments[0].user}),"
|
replace: "$&$self.BiteSizeReviewsButton({user:arguments[0].user}),"
|
||||||
|
|
110
src/plugins/showTimeoutDetails/TimeoutReasonStore.ts
Normal file
110
src/plugins/showTimeoutDetails/TimeoutReasonStore.ts
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2024 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { proxyLazy } from "@utils/lazy";
|
||||||
|
import { findByPropsLazy } from "@webpack";
|
||||||
|
import { Constants, Flux, FluxDispatcher, GuildMemberStore, PermissionsBits, PermissionStore, RestAPI, useStateFromStores } from "@webpack/common";
|
||||||
|
|
||||||
|
|
||||||
|
const AuditLogReasons: {
|
||||||
|
MEMBER_UPDATE: number;
|
||||||
|
AUTO_MODERATION_USER_COMMUNICATION_DISABLED: number;
|
||||||
|
[reason: string]: number;
|
||||||
|
} = findByPropsLazy("ALL", "AUTO_MODERATION_USER_COMMUNICATION_DISABLED", "MEMBER_UPDATE");
|
||||||
|
|
||||||
|
export type TimeoutEntry = {
|
||||||
|
reason: string | undefined;
|
||||||
|
moderator: string | undefined; // User ID of moderator, undefined if automod did the timeout
|
||||||
|
automod: boolean | undefined;
|
||||||
|
automodRuleName: string | undefined;
|
||||||
|
automodChannelId: string | undefined;
|
||||||
|
expires: string | undefined; // used to compare if timeout reason is different
|
||||||
|
loading: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const NoTimeout: TimeoutEntry = {
|
||||||
|
reason: undefined,
|
||||||
|
moderator: undefined,
|
||||||
|
automod: undefined,
|
||||||
|
automodRuleName: undefined,
|
||||||
|
automodChannelId: undefined,
|
||||||
|
expires: undefined,
|
||||||
|
loading: false
|
||||||
|
};
|
||||||
|
|
||||||
|
export const TimeoutLoading: TimeoutEntry = {
|
||||||
|
reason: undefined,
|
||||||
|
moderator: undefined,
|
||||||
|
automod: undefined,
|
||||||
|
automodRuleName: undefined,
|
||||||
|
automodChannelId: undefined,
|
||||||
|
expires: undefined,
|
||||||
|
loading: true
|
||||||
|
};
|
||||||
|
|
||||||
|
export const TimeoutReasonStore = proxyLazy(() => {
|
||||||
|
class TimeoutReasonStore extends Flux.Store {
|
||||||
|
public reasonMap = new Map<string, TimeoutEntry>();
|
||||||
|
|
||||||
|
getReason(guildId: string, userId: string) {
|
||||||
|
const member = GuildMemberStore.getMember(guildId, userId);
|
||||||
|
|
||||||
|
if (!member?.communicationDisabledUntil) return NoTimeout;
|
||||||
|
if (new Date(member?.communicationDisabledUntil!) <= new Date()) return NoTimeout;
|
||||||
|
|
||||||
|
const reason = this.reasonMap.get(`${guildId}-${userId}`);
|
||||||
|
// Return if timeout reason entry is found and is up to date, or if it's still loading
|
||||||
|
if (reason && (reason.loading ? true : reason.expires === member?.communicationDisabledUntil)) return reason;
|
||||||
|
|
||||||
|
// The indicator being visible does not depend on any data here. This just returns that there's no extra information about the timeout.
|
||||||
|
if (!PermissionStore.canWithPartialContext(PermissionsBits.VIEW_AUDIT_LOG, { guildId })) return NoTimeout;
|
||||||
|
|
||||||
|
// Stop requesting data multiple times
|
||||||
|
this.reasonMap.set(`${guildId}-${userId}`, TimeoutLoading);
|
||||||
|
|
||||||
|
RestAPI.get({
|
||||||
|
url: Constants.Endpoints.GUILD_AUDIT_LOG(guildId),
|
||||||
|
query: {
|
||||||
|
// action_type is intentionally not specified here as we need multiple types of audit log actions.
|
||||||
|
target_id: userId,
|
||||||
|
limit: 100
|
||||||
|
}
|
||||||
|
}).then(logs => {
|
||||||
|
const entry = logs.body.audit_log_entries.find((entry: { action_type: number; changes: any[]; }) => {
|
||||||
|
if (entry.action_type === AuditLogReasons.AUTO_MODERATION_USER_COMMUNICATION_DISABLED) return true;
|
||||||
|
if (entry.action_type === AuditLogReasons.MEMBER_UPDATE && entry?.changes.some((change: { key: string; }) => change.key === "communication_disabled_until")) return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!entry) return this.reasonMap.set(`${guildId}-${userId}`, NoTimeout);
|
||||||
|
|
||||||
|
const isAutomod = entry.action_type === AuditLogReasons.AUTO_MODERATION_USER_COMMUNICATION_DISABLED;
|
||||||
|
|
||||||
|
this.reasonMap.set(`${guildId}-${userId}`, {
|
||||||
|
reason: entry.reason,
|
||||||
|
moderator: isAutomod ? undefined : entry.user_id,
|
||||||
|
automod: isAutomod,
|
||||||
|
automodRuleName: isAutomod ? entry?.options?.auto_moderation_rule_name : undefined,
|
||||||
|
automodChannelId: isAutomod ? entry?.options?.channel_id : undefined,
|
||||||
|
expires: member?.communicationDisabledUntil,
|
||||||
|
loading: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// Re-render the timeout indicator components
|
||||||
|
this.emitChange();
|
||||||
|
});
|
||||||
|
|
||||||
|
return TimeoutLoading;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = new TimeoutReasonStore(FluxDispatcher, {});
|
||||||
|
|
||||||
|
return store;
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useTimeoutReason = (guildId: string, userId: string) => useStateFromStores([TimeoutReasonStore], () => {
|
||||||
|
return TimeoutReasonStore.getReason(guildId, userId);
|
||||||
|
});
|
|
@ -0,0 +1,108 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2024 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { SafetyIcon } from "@components/Icons";
|
||||||
|
import { classes, Margins } from "@utils/index";
|
||||||
|
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
|
||||||
|
import { Button, Dialog, GuildMemberStore, GuildStore, i18n, Parser, PermissionsBits, PermissionStore, Text, UserStore, useState, useStateFromStores } from "@webpack/common";
|
||||||
|
import { Message } from "discord-types/general";
|
||||||
|
|
||||||
|
import { CountDown } from "..";
|
||||||
|
import { useTimeoutReason } from "../TimeoutReasonStore";
|
||||||
|
import TimeoutDetailsRow from "./TimeoutDetailsRow";
|
||||||
|
|
||||||
|
const PopoutClasses = findByPropsLazy("container", "scroller", "list");
|
||||||
|
|
||||||
|
const TimeoutIcon = findComponentByCodeLazy("M12 23c.08 0 .14-.08.11-.16a2.88 2.88 0 0 1 .29-2.31l2.2-3.85");
|
||||||
|
const ChannelIcon = findComponentByCodeLazy("h4.97l-.8 4.84a1 1 0 0 0 1.97.32l.86-5.16H20a1");
|
||||||
|
const CustomAutoModRuleIcon = findComponentByCodeLazy("a1 1 0 0 1 1-1h8a1 1 0 0 1 0 2H3a1 1 0 0 1-1-1ZM3 19a1 1 0 1 0 0 2h8a1 1 0 0 0 0-2H3Z");
|
||||||
|
const MessageIcon = findComponentByCodeLazy('"M12 22a10 10 0 1 0-8.45-4.64c.13.19.11.44-.04.61l-2.06 2.37A1 1 0 0 0 2.2 22H12Z"');
|
||||||
|
|
||||||
|
const { setCommunicationDisabledUntil } = findByPropsLazy("setCommunicationDisabledUntil");
|
||||||
|
|
||||||
|
export default function TimeoutDetailsPopout({ closePopout, guildId, userId, message }: { closePopout(): void; guildId: string; userId: string; message: Message; }) {
|
||||||
|
const user = UserStore.getUser(userId);
|
||||||
|
const member = GuildMemberStore.getMember(guildId, userId);
|
||||||
|
const reason = useTimeoutReason(guildId, userId);
|
||||||
|
const hasModerationPermission = useStateFromStores([PermissionStore], () => PermissionStore.canManageUser(PermissionsBits.MODERATE_MEMBERS, userId, GuildStore.getGuild(guildId)));
|
||||||
|
const parse = (text: string) => Parser.parse(text, true, {
|
||||||
|
channelId: message.channel_id,
|
||||||
|
messageId: message.id
|
||||||
|
});
|
||||||
|
|
||||||
|
const [cancelling, setCancelling] = useState(false);
|
||||||
|
|
||||||
|
return <Dialog
|
||||||
|
className={classes("vc-std-popout", PopoutClasses.container)}
|
||||||
|
>
|
||||||
|
<Text tag="h2" variant="eyebrow" style={{ color: "var(--header-primary)", display: "inline" }}>
|
||||||
|
Timeout details for {user.username}
|
||||||
|
</Text>
|
||||||
|
<div className={Margins.bottom8} />
|
||||||
|
|
||||||
|
<TimeoutDetailsRow
|
||||||
|
description="Remaining time in timeout"
|
||||||
|
icon={TimeoutIcon}
|
||||||
|
>
|
||||||
|
<CountDown
|
||||||
|
deadline={new Date(member.communicationDisabledUntil!)}
|
||||||
|
showUnits
|
||||||
|
stopAtOneSec
|
||||||
|
/>
|
||||||
|
</TimeoutDetailsRow>
|
||||||
|
|
||||||
|
<TimeoutDetailsRow
|
||||||
|
description="Moderator"
|
||||||
|
icon={SafetyIcon}
|
||||||
|
condition={!!(reason.moderator || reason.automod)}
|
||||||
|
>
|
||||||
|
{reason.automod ? i18n.Messages.GUILD_SETTINGS_AUTOMOD_TITLE : parse(`<@${reason.moderator}>`)}
|
||||||
|
</TimeoutDetailsRow>
|
||||||
|
|
||||||
|
<TimeoutDetailsRow
|
||||||
|
description="Channel where offending message was sent"
|
||||||
|
icon={ChannelIcon}
|
||||||
|
condition={!!reason.automodChannelId}
|
||||||
|
>
|
||||||
|
{parse(`<#${reason.automodChannelId}>`)}
|
||||||
|
</TimeoutDetailsRow>
|
||||||
|
|
||||||
|
<TimeoutDetailsRow
|
||||||
|
description="AutoMod Rule"
|
||||||
|
icon={CustomAutoModRuleIcon}
|
||||||
|
>
|
||||||
|
{reason.automodRuleName}
|
||||||
|
</TimeoutDetailsRow>
|
||||||
|
|
||||||
|
<TimeoutDetailsRow
|
||||||
|
description="Reason"
|
||||||
|
icon={MessageIcon}
|
||||||
|
>
|
||||||
|
{reason.reason}
|
||||||
|
</TimeoutDetailsRow>
|
||||||
|
|
||||||
|
{hasModerationPermission && <div className="vc-std-popout-button-wrapper"><Button
|
||||||
|
className="vc-std-popout-button"
|
||||||
|
size={Button.Sizes.SMALL}
|
||||||
|
color={Button.Colors.RED}
|
||||||
|
onClick={async () => {
|
||||||
|
setCancelling(true);
|
||||||
|
await setCommunicationDisabledUntil({
|
||||||
|
guildId,
|
||||||
|
userId,
|
||||||
|
communicationDisabledUntilTimestamp: null,
|
||||||
|
duratiion: null,
|
||||||
|
reason: null,
|
||||||
|
location: null
|
||||||
|
});
|
||||||
|
closePopout();
|
||||||
|
}}
|
||||||
|
submitting={cancelling}
|
||||||
|
>
|
||||||
|
{i18n.Messages.REMOVE_TIME_OUT}
|
||||||
|
</Button></div>}
|
||||||
|
</Dialog>;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2024 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { findByPropsLazy } from "@webpack";
|
||||||
|
import { Tooltip } from "@webpack/common";
|
||||||
|
import { JSXElementConstructor, ReactNode } from "react";
|
||||||
|
|
||||||
|
const rowClasses = findByPropsLazy("row", "rowIcon", "rowGuildName");
|
||||||
|
|
||||||
|
export default function TimeoutDetailsRow(props: {
|
||||||
|
description: ReactNode;
|
||||||
|
icon: JSXElementConstructor<any>;
|
||||||
|
children: ReactNode;
|
||||||
|
condition?: boolean | string;
|
||||||
|
}) {
|
||||||
|
if (props.condition === undefined ? !props.children : !props.condition) return null;
|
||||||
|
return <div className={rowClasses.row}>
|
||||||
|
<Tooltip text={props.description}>
|
||||||
|
{p => <props.icon {...p} className={rowClasses.rowIcon} height="24" width="24" />}
|
||||||
|
</Tooltip>
|
||||||
|
{props.children}
|
||||||
|
</div>;
|
||||||
|
}
|
92
src/plugins/showTimeoutDetails/components/TooltipWrapper.tsx
Normal file
92
src/plugins/showTimeoutDetails/components/TooltipWrapper.tsx
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2024 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { classes, Margins } from "@utils/index";
|
||||||
|
import { findByPropsLazy } from "@webpack";
|
||||||
|
import { ChannelStore, GuildMemberStore, i18n, Popout, Text, Tooltip } from "@webpack/common";
|
||||||
|
import { Message } from "discord-types/general";
|
||||||
|
import { FunctionComponent, ReactNode } from "react";
|
||||||
|
|
||||||
|
import { CountDown, DisplayStyle, settings } from "..";
|
||||||
|
import { useTimeoutReason } from "../TimeoutReasonStore";
|
||||||
|
import TimeoutDetailsPopout from "./TimeoutDetailsPopout";
|
||||||
|
|
||||||
|
const clickableClasses = findByPropsLazy("clickable", "avatar", "username");
|
||||||
|
|
||||||
|
export default function TooltipWrapper({ message, children, text }: { message: Message; children: FunctionComponent<any>; text: ReactNode; }) {
|
||||||
|
const guildId = ChannelStore.getChannel(message.channel_id)?.guild_id;
|
||||||
|
const timeoutReason = useTimeoutReason(guildId, message.author.id);
|
||||||
|
|
||||||
|
if (settings.store.displayStyle === DisplayStyle.Tooltip) return <Tooltip
|
||||||
|
tooltipClassName="vc-std-tooltip"
|
||||||
|
text={renderTimeout(message, false)}
|
||||||
|
children={(props: any) => (
|
||||||
|
<Popout
|
||||||
|
position="top"
|
||||||
|
align="left"
|
||||||
|
renderPopout={p => <TimeoutDetailsPopout {...p} guildId={guildId} userId={message.author.id} message={message} />}
|
||||||
|
>
|
||||||
|
{popoutProps => <span
|
||||||
|
{...popoutProps}
|
||||||
|
className={classes("vc-std-icon", clickableClasses.clickable, timeoutReason.automod && "vc-std-automod")}
|
||||||
|
onClick={e => { e.stopPropagation(); popoutProps.onClick(e); }} // stop double click to reply/edit
|
||||||
|
>
|
||||||
|
{children(props)}
|
||||||
|
</span>}
|
||||||
|
</Popout>
|
||||||
|
)}
|
||||||
|
/>;
|
||||||
|
return (
|
||||||
|
<Popout
|
||||||
|
position="top"
|
||||||
|
align="left"
|
||||||
|
renderPopout={p => <TimeoutDetailsPopout {...p} guildId={guildId} userId={message.author.id} message={message} />}
|
||||||
|
>
|
||||||
|
{popoutProps => <div
|
||||||
|
{...popoutProps}
|
||||||
|
className={classes("vc-std-wrapper", clickableClasses.clickable, timeoutReason.automod && "vc-std-automod")}
|
||||||
|
onClick={e => { e.stopPropagation(); popoutProps.onClick(e); }} // stop double click to reply/edit
|
||||||
|
>
|
||||||
|
<Tooltip text={text} children={children} />
|
||||||
|
<span className={Margins.right8} />
|
||||||
|
<Text variant="text-md/normal" className="vc-std-wrapper-text">
|
||||||
|
{renderTimeout(message, true)} timeout remaining
|
||||||
|
</Text>
|
||||||
|
</div>}
|
||||||
|
</Popout>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTimeout(message: Message, inline: boolean) {
|
||||||
|
const guildId = ChannelStore.getChannel(message.channel_id)?.guild_id;
|
||||||
|
if (!guildId) return null;
|
||||||
|
|
||||||
|
const member = GuildMemberStore.getMember(guildId, message.author.id);
|
||||||
|
if (!member?.communicationDisabledUntil) return null;
|
||||||
|
|
||||||
|
const countdown = () => <>
|
||||||
|
<wbr />
|
||||||
|
<span style={{ whiteSpace: "nowrap" }}>
|
||||||
|
<CountDown
|
||||||
|
deadline={new Date(member.communicationDisabledUntil!)}
|
||||||
|
showUnits
|
||||||
|
stopAtOneSec
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
<wbr />
|
||||||
|
</>;
|
||||||
|
|
||||||
|
return inline
|
||||||
|
? countdown()
|
||||||
|
: <>
|
||||||
|
{i18n.Messages.GUILD_ENABLE_COMMUNICATION_TIME_REMAINING.format({
|
||||||
|
username: message.author.username,
|
||||||
|
countdown
|
||||||
|
})}
|
||||||
|
<br />
|
||||||
|
Click for more details.
|
||||||
|
</>;
|
||||||
|
}
|
61
src/plugins/showTimeoutDetails/index.tsx
Normal file
61
src/plugins/showTimeoutDetails/index.tsx
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2024 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import "./styles.css";
|
||||||
|
|
||||||
|
import { definePluginSettings, migratePluginSettings } from "@api/Settings";
|
||||||
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
|
import { Devs } from "@utils/constants";
|
||||||
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
|
import { findComponentLazy } from "@webpack";
|
||||||
|
|
||||||
|
import TooltipWrapper from "./components/TooltipWrapper";
|
||||||
|
import { TimeoutReasonStore } from "./TimeoutReasonStore";
|
||||||
|
|
||||||
|
export const CountDown = findComponentLazy(m => m.prototype?.render?.toString().includes(".MAX_AGE_NEVER"));
|
||||||
|
|
||||||
|
export const enum DisplayStyle {
|
||||||
|
Tooltip = "tooltip",
|
||||||
|
Inline = "ssalggnikool"
|
||||||
|
}
|
||||||
|
|
||||||
|
export const settings = definePluginSettings({
|
||||||
|
displayStyle: {
|
||||||
|
description: "How to display the timeout duration and reason",
|
||||||
|
type: OptionType.SELECT,
|
||||||
|
options: [
|
||||||
|
{ label: "In the Tooltip", value: DisplayStyle.Tooltip },
|
||||||
|
{ label: "Next to the timeout icon", value: DisplayStyle.Inline, default: true },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
migratePluginSettings("ShowTimeoutDetails", "ShowTimeoutDuration");
|
||||||
|
|
||||||
|
export default definePlugin({
|
||||||
|
name: "ShowTimeoutDetails",
|
||||||
|
description: "Shows how much longer a user's timeout will last and why they are timed out, either in the timeout icon tooltip or next to it",
|
||||||
|
authors: [Devs.Ven, Devs.Sqaaakoi],
|
||||||
|
tags: ["ShowTimeoutDuration", "ShowTimeoutReason"],
|
||||||
|
|
||||||
|
settings,
|
||||||
|
|
||||||
|
patches: [
|
||||||
|
{
|
||||||
|
find: ".GUILD_COMMUNICATION_DISABLED_ICON_TOOLTIP_BODY",
|
||||||
|
replacement: [
|
||||||
|
{
|
||||||
|
match: /(\i)\.Tooltip,{(text:.{0,30}\.Messages\.GUILD_COMMUNICATION_DISABLED_ICON_TOOLTIP_BODY)/,
|
||||||
|
replace: "$self.TooltipWrapper,{message:arguments[0].message,$2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
TimeoutReasonStore,
|
||||||
|
|
||||||
|
TooltipWrapper: ErrorBoundary.wrap(TooltipWrapper, { noop: true })
|
||||||
|
});
|
35
src/plugins/showTimeoutDetails/styles.css
Normal file
35
src/plugins/showTimeoutDetails/styles.css
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
.vc-std-wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vc-std-wrapper [class*="communicationDisabled"] {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vc-std-wrapper-text {
|
||||||
|
color: var(--status-danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.vc-std-automod :is(svg, .vc-std-wrapper-text) {
|
||||||
|
color: var(--status-warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
.vc-std-tooltip {
|
||||||
|
max-width: 220px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vc-std-popout {
|
||||||
|
width: unset;
|
||||||
|
min-width: 180px;
|
||||||
|
max-width: 360px;
|
||||||
|
color: var(--text-normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
.vc-std-popout-button-wrapper {
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vc-std-popout-button {
|
||||||
|
padding: 2px 10px;
|
||||||
|
}
|
|
@ -1,92 +0,0 @@
|
||||||
/*
|
|
||||||
* Vencord, a Discord client mod
|
|
||||||
* Copyright (c) 2024 Vendicated and contributors
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
import "./styles.css";
|
|
||||||
|
|
||||||
import { definePluginSettings } from "@api/Settings";
|
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
|
||||||
import { Devs } from "@utils/constants";
|
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
|
||||||
import { findComponentLazy } from "@webpack";
|
|
||||||
import { ChannelStore, GuildMemberStore, i18n, Text, Tooltip } from "@webpack/common";
|
|
||||||
import { Message } from "discord-types/general";
|
|
||||||
import { FunctionComponent, ReactNode } from "react";
|
|
||||||
|
|
||||||
const CountDown = findComponentLazy(m => m.prototype?.render?.toString().includes(".MAX_AGE_NEVER"));
|
|
||||||
|
|
||||||
const enum DisplayStyle {
|
|
||||||
Tooltip = "tooltip",
|
|
||||||
Inline = "ssalggnikool"
|
|
||||||
}
|
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
|
||||||
displayStyle: {
|
|
||||||
description: "How to display the timeout duration",
|
|
||||||
type: OptionType.SELECT,
|
|
||||||
options: [
|
|
||||||
{ label: "In the Tooltip", value: DisplayStyle.Tooltip },
|
|
||||||
{ label: "Next to the timeout icon", value: DisplayStyle.Inline, default: true },
|
|
||||||
],
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function renderTimeout(message: Message, inline: boolean) {
|
|
||||||
const guildId = ChannelStore.getChannel(message.channel_id)?.guild_id;
|
|
||||||
if (!guildId) return null;
|
|
||||||
|
|
||||||
const member = GuildMemberStore.getMember(guildId, message.author.id);
|
|
||||||
if (!member?.communicationDisabledUntil) return null;
|
|
||||||
|
|
||||||
const countdown = () => (
|
|
||||||
<CountDown
|
|
||||||
deadline={new Date(member.communicationDisabledUntil!)}
|
|
||||||
showUnits
|
|
||||||
stopAtOneSec
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
return inline
|
|
||||||
? countdown()
|
|
||||||
: i18n.Messages.GUILD_ENABLE_COMMUNICATION_TIME_REMAINING.format({
|
|
||||||
username: message.author.username,
|
|
||||||
countdown
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default definePlugin({
|
|
||||||
name: "ShowTimeoutDuration",
|
|
||||||
description: "Shows how much longer a user's timeout will last, either in the timeout icon tooltip or next to it",
|
|
||||||
authors: [Devs.Ven, Devs.Sqaaakoi],
|
|
||||||
|
|
||||||
settings,
|
|
||||||
|
|
||||||
patches: [
|
|
||||||
{
|
|
||||||
find: ".GUILD_COMMUNICATION_DISABLED_ICON_TOOLTIP_BODY",
|
|
||||||
replacement: [
|
|
||||||
{
|
|
||||||
match: /(\i)\.Tooltip,{(text:.{0,30}\.Messages\.GUILD_COMMUNICATION_DISABLED_ICON_TOOLTIP_BODY)/,
|
|
||||||
replace: "$self.TooltipWrapper,{message:arguments[0].message,$2"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
TooltipWrapper: ErrorBoundary.wrap(({ message, children, text }: { message: Message; children: FunctionComponent<any>; text: ReactNode; }) => {
|
|
||||||
if (settings.store.displayStyle === DisplayStyle.Tooltip) return <Tooltip
|
|
||||||
children={children}
|
|
||||||
text={renderTimeout(message, false)}
|
|
||||||
/>;
|
|
||||||
return (
|
|
||||||
<div className="vc-std-wrapper">
|
|
||||||
<Tooltip text={text} children={children} />
|
|
||||||
<Text variant="text-md/normal" color="status-danger">
|
|
||||||
{renderTimeout(message, true)} timeout remaining
|
|
||||||
</Text>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}, { noop: true })
|
|
||||||
});
|
|
|
@ -1,8 +0,0 @@
|
||||||
.vc-std-wrapper {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.vc-std-wrapper [class*="communicationDisabled"] {
|
|
||||||
margin-right: 0;
|
|
||||||
}
|
|
5
src/webpack/common/types/menu.d.ts
vendored
5
src/webpack/common/types/menu.d.ts
vendored
|
@ -72,6 +72,11 @@ export interface Menu {
|
||||||
onChange(value: number): void,
|
onChange(value: number): void,
|
||||||
renderValue?(value: number): string,
|
renderValue?(value: number): string,
|
||||||
}>;
|
}>;
|
||||||
|
MenuSearchControl: RC<{
|
||||||
|
query: string
|
||||||
|
onChange(query: string): void;
|
||||||
|
placeholder?: string;
|
||||||
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ContextMenuApi {
|
export interface ContextMenuApi {
|
||||||
|
|
Loading…
Reference in a new issue