mirror of
https://github.com/Vendicated/Vencord.git
synced 2024-09-20 06:30:35 +00:00
Compare commits
58 commits
80e2b536ed
...
ca7c2ee802
Author | SHA1 | Date | |
---|---|---|---|
|
ca7c2ee802 | ||
|
f12335a371 | ||
|
640d99dcda | ||
|
618e1db41d | ||
|
86b920af45 | ||
|
1c0a4aa2a8 | ||
|
807231d138 | ||
|
f5d329bd84 | ||
|
aa0a18ff7d | ||
|
077e668234 | ||
|
09c42e3c51 | ||
|
435d273da0 | ||
|
74d63a2261 | ||
|
cd917a4ba2 | ||
|
13f909bc9a | ||
|
446fdc1009 | ||
|
c94af9033d | ||
|
1b3321088e | ||
|
a9a71d1323 | ||
|
9dc8cab27a | ||
|
d26a900581 | ||
|
89bc55114c | ||
|
f72d0babf4 | ||
|
e36c160ce2 | ||
|
52f3ab0e9d | ||
|
f0f6cf9ac7 | ||
|
73fcf02862 | ||
|
c5c83c234d | ||
|
ab65b263a0 | ||
|
7ded1985d2 | ||
|
4236cd9171 | ||
|
583409c448 | ||
|
928ff576cc | ||
|
dbcc2ea5d2 | ||
|
bb5e692439 | ||
|
a298057a84 | ||
|
c9ebab41ba | ||
|
616b66a62b | ||
|
c29dd6d57f | ||
|
e1cd58efc1 | ||
|
5e0a89b066 | ||
|
e175dbfa2c | ||
|
c8ed4b5a8e | ||
|
c1b67959b4 | ||
|
ba68c6b0e7 | ||
|
6e6ee4db68 | ||
|
d8524b087c | ||
|
78fd37a4c6 | ||
|
2a1f7b7dec | ||
|
265b580f95 | ||
|
c849657ff0 | ||
|
7b1a776f21 | ||
|
5ff2865969 | ||
|
909b997e3e | ||
|
90a0ed7249 | ||
|
3f3f9677ca | ||
|
9a634ab999 | ||
|
0514afe236 |
11 changed files with 666 additions and 177 deletions
|
@ -1,5 +0,0 @@
|
|||
# NoDefaultHangStatus
|
||||
|
||||
Disable the default hang status when joining voice channels
|
||||
|
||||
![Visualization](https://github.com/Vendicated/Vencord/assets/24937357/329a9742-236f-48f7-94ff-c3510eca505a)
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin from "@utils/types";
|
||||
|
||||
export default definePlugin({
|
||||
name: "NoDefaultHangStatus",
|
||||
description: "Disable the default hang status when joining voice channels",
|
||||
authors: [Devs.D3SOX],
|
||||
|
||||
patches: [
|
||||
{
|
||||
find: ".CHILLING)",
|
||||
replacement: {
|
||||
match: /{enableHangStatus:(\i),/,
|
||||
replace: "{_enableHangStatus:$1=false,"
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
224
src/plugins/rpcEditor/ReplaceSettings.tsx
Normal file
224
src/plugins/rpcEditor/ReplaceSettings.tsx
Normal file
|
@ -0,0 +1,224 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { CheckedTextInput } from "@components/CheckedTextInput";
|
||||
import { Margins } from "@utils/margins";
|
||||
import { identity } from "@utils/misc";
|
||||
import { Card, Forms, PresenceStore, React, Select, SnowflakeUtils, Switch, TextInput, UserStore } from "@webpack/common";
|
||||
|
||||
import { Activity, ActivityType, AppIdSetting, makeEmptyAppId } from ".";
|
||||
|
||||
interface SettingsProps {
|
||||
appIds: AppIdSetting[];
|
||||
update: () => void;
|
||||
save: () => void;
|
||||
}
|
||||
|
||||
function isValidSnowflake(v: string) {
|
||||
const regex = /^\d{17,20}$/;
|
||||
return regex.test(v) && !Number.isNaN(SnowflakeUtils.extractTimestamp(v));
|
||||
}
|
||||
|
||||
export function ReplaceTutorial() {
|
||||
const activities: Activity[] = PresenceStore.getActivities(UserStore.getCurrentUser().id);
|
||||
return (
|
||||
<>
|
||||
<Forms.FormTitle tag="h3">IDs of currently running activities</Forms.FormTitle>
|
||||
{
|
||||
activities.length === 0 ? <Forms.FormText>No running activities</Forms.FormText> : activities.map(activity => { return activity.flags !== 48 ? <Forms.FormText>{activity.name}: {activity.application_id}</Forms.FormText> : null; /* hide spotify */ })
|
||||
}
|
||||
<Forms.FormTitle tag="h3" className={Margins.top8}>Available variables</Forms.FormTitle>
|
||||
<Forms.FormText>
|
||||
In all fields (except stream URL), you can put in variables that'll automatically be replaced by their original content:
|
||||
<pre style={{ fontFamily: "monospace" }}>
|
||||
:name:, :details:, :state:
|
||||
<br />
|
||||
:large_image:, :large_text:, :small_image:, :small_text:
|
||||
</pre>
|
||||
</Forms.FormText>
|
||||
<Forms.FormTitle tag="h3" className={Margins.top8}>More details</Forms.FormTitle>
|
||||
<Forms.FormText>
|
||||
Leave a field empty to leave it as is.
|
||||
<br />
|
||||
Set a field to "null" to hide it on the presence.
|
||||
<br />
|
||||
You may need to reload Discord for changes to apply.
|
||||
</Forms.FormText>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
|
||||
async function onChange(val: string | boolean, index: number, key: string) {
|
||||
if (index === appIds.length - 1)
|
||||
appIds.push(makeEmptyAppId());
|
||||
|
||||
appIds[index][key] = val;
|
||||
|
||||
save();
|
||||
update();
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{
|
||||
appIds.map((setting, i) =>
|
||||
<Card style={{ padding: "1em", opacity: !setting.enabled ? "60%" : "" }}>
|
||||
{
|
||||
isValidSnowflake(setting.appId) ?
|
||||
<Switch
|
||||
value={setting.enabled}
|
||||
onChange={value => {
|
||||
onChange(value, i, "enabled");
|
||||
}}
|
||||
className={Margins.bottom8}
|
||||
hideBorder={true}
|
||||
>
|
||||
Apply edits to app
|
||||
</Switch> : <Forms.FormTitle tag="h3">Add new application</Forms.FormTitle>
|
||||
}
|
||||
<Forms.FormTitle className={`${Margins.top8} ${Margins.bottom8}`}>Application ID</Forms.FormTitle>
|
||||
<CheckedTextInput
|
||||
value={setting.appId}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "appId");
|
||||
}}
|
||||
validate={v =>
|
||||
!v || isValidSnowflake(v) || "Invalid application ID"
|
||||
}
|
||||
/>
|
||||
{
|
||||
isValidSnowflake(setting.appId) && <>
|
||||
<Forms.FormTitle className={Margins.top8}>New activity type</Forms.FormTitle>
|
||||
<Select
|
||||
options={[
|
||||
{ label: "Playing", value: ActivityType.PLAYING },
|
||||
{ label: "Watching", value: ActivityType.WATCHING },
|
||||
{ label: "Listening", value: ActivityType.LISTENING },
|
||||
{ label: "Competing", value: ActivityType.COMPETING },
|
||||
{ label: "Streaming", value: ActivityType.STREAMING }
|
||||
]}
|
||||
select={value => {
|
||||
onChange(value, i, "newActivityType");
|
||||
}}
|
||||
className={Margins.top8}
|
||||
isSelected={value => setting.newActivityType === value}
|
||||
serialize={identity}
|
||||
/>
|
||||
{
|
||||
setting.newActivityType === ActivityType.STREAMING &&
|
||||
<>
|
||||
<Forms.FormTitle className={`${Margins.top8} ${Margins.bottom8}`}>Stream URL (must be YouTube or Twitch)</Forms.FormTitle>
|
||||
<CheckedTextInput
|
||||
value={setting.newStreamUrl}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newStreamUrl");
|
||||
}}
|
||||
validate={v => {
|
||||
return /https?:\/\/(www\.)?(twitch\.tv|youtube\.com)\/\w+/.test(v) || "Invalid stream URL";
|
||||
}}
|
||||
/>
|
||||
|
||||
</>
|
||||
}
|
||||
{
|
||||
setting.newActivityType !== ActivityType.STREAMING &&
|
||||
<>
|
||||
<Forms.FormTitle className={Margins.top8}>New name {setting.newActivityType === ActivityType.PLAYING && "(first line)"}</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newName}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newName");
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
<Forms.FormTitle className={Margins.top8}>New details {setting.newActivityType === ActivityType.PLAYING ? "(second line)" : "(first line)"}</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newDetails}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newDetails");
|
||||
}}
|
||||
/>
|
||||
<Forms.FormTitle className={Margins.top8}>New state {setting.newActivityType === ActivityType.PLAYING ? "(third line)" : "(second line)"}</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newState}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newState");
|
||||
}}
|
||||
/>
|
||||
{
|
||||
!setting.disableAssets &&
|
||||
<>
|
||||
<Forms.FormText style={{ fontSize: "1.05rem", fontWeight: "500" }} className={Margins.top8}>Large image</Forms.FormText>
|
||||
<Forms.FormTitle className={Margins.top8}>Text {setting.newActivityType !== ActivityType.PLAYING && "(also third line)"}</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newLargeImageText}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newLargeImageText");
|
||||
}}
|
||||
/>
|
||||
<Forms.FormTitle className={Margins.top8}>URL</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newLargeImageUrl}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newLargeImageUrl");
|
||||
}}
|
||||
/>
|
||||
<Forms.FormText style={{ fontSize: "1.05rem", fontWeight: "500" }} className={Margins.top8}>Small image</Forms.FormText>
|
||||
<Forms.FormTitle className={Margins.top8}>Text</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newSmallImageText}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newSmallImageText");
|
||||
}}
|
||||
/>
|
||||
<Forms.FormTitle className={Margins.top8}>URL</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newSmallImageUrl}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newSmallImageUrl");
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
<Switch
|
||||
value={setting.disableAssets}
|
||||
onChange={value => {
|
||||
onChange(value, i, "disableAssets");
|
||||
}}
|
||||
className={Margins.top8}
|
||||
hideBorder={true}
|
||||
style={{ marginBottom: "0" }}
|
||||
>
|
||||
Hide assets (large & small images)
|
||||
</Switch>
|
||||
<Switch
|
||||
value={setting.disableTimestamps}
|
||||
onChange={value => {
|
||||
onChange(value, i, "disableTimestamps");
|
||||
}}
|
||||
className={Margins.top8}
|
||||
hideBorder={true}
|
||||
style={{ marginBottom: "0" }}
|
||||
>
|
||||
Hide timestamps
|
||||
</Switch>
|
||||
</>
|
||||
}
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
154
src/plugins/rpcEditor/index.tsx
Normal file
154
src/plugins/rpcEditor/index.tsx
Normal file
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { DataStore } from "@api/index";
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
import { Devs } from "@utils/constants";
|
||||
import { useForceUpdater } from "@utils/react";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { React } from "@webpack/common";
|
||||
|
||||
import { ReplaceSettings, ReplaceTutorial } from "./ReplaceSettings";
|
||||
|
||||
const APP_IDS_KEY = "ReplaceActivityType_appids";
|
||||
export type AppIdSetting = {
|
||||
disableAssets: boolean;
|
||||
disableTimestamps: boolean;
|
||||
appId: string;
|
||||
enabled: boolean;
|
||||
newActivityType: ActivityType;
|
||||
newName: string,
|
||||
newDetails: string,
|
||||
newState: string,
|
||||
newLargeImageUrl: string,
|
||||
newLargeImageText: string,
|
||||
newSmallImageUrl: string,
|
||||
newSmallImageText: string;
|
||||
newStreamUrl: string;
|
||||
};
|
||||
|
||||
export interface Activity {
|
||||
state: string;
|
||||
details: string;
|
||||
timestamps?: {
|
||||
start?: number;
|
||||
end?: number;
|
||||
};
|
||||
url?: string;
|
||||
assets: ActivityAssets;
|
||||
buttons?: Array<string>;
|
||||
name: string;
|
||||
application_id: string;
|
||||
metadata?: {
|
||||
button_urls?: Array<string>;
|
||||
};
|
||||
type: number;
|
||||
flags: number;
|
||||
}
|
||||
|
||||
interface ActivityAssets {
|
||||
large_image: string;
|
||||
large_text: string;
|
||||
small_image: string;
|
||||
small_text: string;
|
||||
}
|
||||
|
||||
export const enum ActivityType {
|
||||
PLAYING = 0,
|
||||
STREAMING = 1,
|
||||
LISTENING = 2,
|
||||
WATCHING = 3,
|
||||
COMPETING = 5
|
||||
}
|
||||
|
||||
export const makeEmptyAppId: () => AppIdSetting = () => ({
|
||||
appId: "",
|
||||
enabled: true,
|
||||
newActivityType: ActivityType.PLAYING,
|
||||
newName: "",
|
||||
newDetails: "",
|
||||
newState: "",
|
||||
newLargeImageUrl: "",
|
||||
newLargeImageText: "",
|
||||
newSmallImageUrl: "",
|
||||
newSmallImageText: "",
|
||||
newStreamUrl: "",
|
||||
disableTimestamps: false,
|
||||
disableAssets: false
|
||||
});
|
||||
|
||||
let appIds = [makeEmptyAppId()];
|
||||
|
||||
const settings = definePluginSettings({
|
||||
replacedAppIds: {
|
||||
type: OptionType.COMPONENT,
|
||||
description: "",
|
||||
component: () => {
|
||||
const update = useForceUpdater();
|
||||
return (
|
||||
<>
|
||||
<ReplaceSettings
|
||||
appIds={appIds}
|
||||
update={update}
|
||||
save={async () => DataStore.set(APP_IDS_KEY, appIds)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export default definePlugin({
|
||||
name: "RPCEditor",
|
||||
description: "Edit the type and content of any Rich Presence",
|
||||
authors: [Devs.Nyako, Devs.nin0dev],
|
||||
patches: [
|
||||
{
|
||||
find: '="LocalActivityStore",',
|
||||
replacement: {
|
||||
match: /LOCAL_ACTIVITY_UPDATE:function\((\i)\)\{/,
|
||||
replace: "$&$self.patchActivity($1.activity);",
|
||||
}
|
||||
}
|
||||
],
|
||||
settings,
|
||||
settingsAboutComponent: () => <ReplaceTutorial />,
|
||||
|
||||
async start() {
|
||||
appIds = await DataStore.get(APP_IDS_KEY) ?? [makeEmptyAppId()];
|
||||
},
|
||||
parseField(text: string, originalActivity: Activity): string {
|
||||
if (text === "null") return "";
|
||||
return text
|
||||
.replaceAll(":name:", originalActivity.name)
|
||||
.replaceAll(":details:", originalActivity.details)
|
||||
.replaceAll(":state:", originalActivity.state)
|
||||
.replaceAll(":large_image:", originalActivity.assets.large_image)
|
||||
.replaceAll(":large_text:", originalActivity.assets.large_text)
|
||||
.replaceAll(":small_image:", originalActivity.assets.small_image)
|
||||
.replaceAll(":small_text:", originalActivity.assets.small_text);
|
||||
},
|
||||
patchActivity(activity: Activity) {
|
||||
if (!activity) return;
|
||||
appIds.forEach(app => {
|
||||
if (app.enabled && app.appId === activity.application_id) {
|
||||
const oldActivity = { ...activity };
|
||||
activity.type = app.newActivityType;
|
||||
if (app.newName) activity.name = this.parseField(app.newName, oldActivity);
|
||||
if (app.newActivityType === ActivityType.STREAMING && app.newStreamUrl) activity.url = app.newStreamUrl;
|
||||
if (app.newDetails) activity.details = this.parseField(app.newDetails, oldActivity);
|
||||
if (app.newState) activity.state = this.parseField(app.newState, oldActivity);
|
||||
if (app.newLargeImageText) activity.assets.large_text = this.parseField(app.newLargeImageText, oldActivity);
|
||||
if (app.newLargeImageUrl) activity.assets.large_image = this.parseField(app.newLargeImageUrl, oldActivity);
|
||||
if (app.newSmallImageText) activity.assets.small_text = this.parseField(app.newSmallImageText, oldActivity);
|
||||
if (app.newSmallImageUrl) activity.assets.small_image = this.parseField(app.newSmallImageUrl, oldActivity);
|
||||
// @ts-ignore here we are intentionally nulling assets
|
||||
if (app.disableAssets) activity.assets = {};
|
||||
if (app.disableTimestamps) activity.timestamps = {};
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
14
src/plugins/rpcEditor/style.css
Normal file
14
src/plugins/rpcEditor/style.css
Normal file
|
@ -0,0 +1,14 @@
|
|||
.vc-rpceditor-horizontal {
|
||||
display: flex;
|
||||
justify-content: space-evenly;
|
||||
|
||||
}
|
||||
|
||||
.vc-rpceditor-horizontal div {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
|
||||
.vc-rpceditor-horizontal div:first-child {
|
||||
padding-right: 5px;
|
||||
}
|
7
src/plugins/userVoiceShow/README.md
Normal file
7
src/plugins/userVoiceShow/README.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# User Voice Show
|
||||
|
||||
Shows an indicator when a user is in a Voice Channel
|
||||
|
||||
![a preview of the indicator in the user profile](https://github.com/user-attachments/assets/48f825e4-fad5-40d7-bb4f-41d5e595aae0)
|
||||
|
||||
![a preview of the indicator in the member list](https://github.com/user-attachments/assets/51be081d-7bbb-45c5-8533-d565228e50c1)
|
170
src/plugins/userVoiceShow/components.tsx
Normal file
170
src/plugins/userVoiceShow/components.tsx
Normal file
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { classNameFactory } from "@api/Styles";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { classes } from "@utils/misc";
|
||||
import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
|
||||
import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, showToast, Text, Toasts, Tooltip, useCallback, useMemo, UserStore, useStateFromStores } from "@webpack/common";
|
||||
import { Channel } from "discord-types/general";
|
||||
|
||||
const cl = classNameFactory("vc-uvs-");
|
||||
|
||||
const { selectVoiceChannel } = findByPropsLazy("selectChannel", "selectVoiceChannel");
|
||||
const VoiceStateStore = findStoreLazy("VoiceStateStore");
|
||||
const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers");
|
||||
|
||||
interface IconProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
size?: number;
|
||||
}
|
||||
|
||||
function SpeakerIcon(props: IconProps) {
|
||||
props.size ??= 16;
|
||||
|
||||
return (
|
||||
<div
|
||||
{...props}
|
||||
role={props.onClick != null ? "button" : undefined}
|
||||
className={classes(cl("speaker"), props.onClick != null ? cl("clickable") : undefined)}
|
||||
>
|
||||
<svg
|
||||
width={props.size}
|
||||
height={props.size}
|
||||
viewBox="0 0 24 24"
|
||||
fill="currentColor"
|
||||
>
|
||||
<path d="M12 3a1 1 0 0 0-1-1h-.06a1 1 0 0 0-.74.32L5.92 7H3a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h2.92l4.28 4.68a1 1 0 0 0 .74.32H11a1 1 0 0 0 1-1V3ZM15.1 20.75c-.58.14-1.1-.33-1.1-.92v-.03c0-.5.37-.92.85-1.05a7 7 0 0 0 0-13.5A1.11 1.11 0 0 1 14 4.2v-.03c0-.6.52-1.06 1.1-.92a9 9 0 0 1 0 17.5Z" />
|
||||
<path d="M15.16 16.51c-.57.28-1.16-.2-1.16-.83v-.14c0-.43.28-.8.63-1.02a3 3 0 0 0 0-5.04c-.35-.23-.63-.6-.63-1.02v-.14c0-.63.59-1.1 1.16-.83a5 5 0 0 1 0 9.02Z" />
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LockedSpeakerIcon(props: IconProps) {
|
||||
props.size ??= 16;
|
||||
|
||||
return (
|
||||
<div
|
||||
{...props}
|
||||
role={props.onClick != null ? "button" : undefined}
|
||||
className={classes(cl("speaker"), props.onClick != null ? cl("clickable") : undefined)}
|
||||
>
|
||||
<svg
|
||||
width={props.size}
|
||||
height={props.size}
|
||||
viewBox="0 0 24 24"
|
||||
fill="currentColor"
|
||||
>
|
||||
<path fillRule="evenodd" clipRule="evenodd" d="M16 4h.5v-.5a2.5 2.5 0 0 1 5 0V4h.5a1 1 0 0 1 1 1v4a1 1 0 0 1-1 1h-6a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1Zm4-.5V4h-2v-.5a1 1 0 1 1 2 0Z" />
|
||||
<path d="M11 2a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1h-.06a1 1 0 0 1-.74-.32L5.92 17H3a1 1 0 0 1-1-1V8a1 1 0 0 1 1-1h2.92l4.28-4.68a1 1 0 0 1 .74-.32H11ZM20.5 12c-.28 0-.5.22-.52.5a7 7 0 0 1-5.13 6.25c-.48.13-.85.55-.85 1.05v.03c0 .6.52 1.06 1.1.92a9 9 0 0 0 6.89-8.25.48.48 0 0 0-.49-.5h-1ZM16.5 12c-.28 0-.5.23-.54.5a3 3 0 0 1-1.33 2.02c-.35.23-.63.6-.63 1.02v.14c0 .63.59 1.1 1.16.83a5 5 0 0 0 2.82-4.01c.02-.28-.2-.5-.48-.5h-1Z" />
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface VoiceChannelTooltipProps {
|
||||
channel: Channel;
|
||||
}
|
||||
|
||||
function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
|
||||
const voiceStates = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStatesForChannel(channel.id));
|
||||
const users = useMemo(
|
||||
() => Object.values<any>(voiceStates).map(voiceState => UserStore.getUser(voiceState.userId)).filter(user => user != null),
|
||||
[voiceStates]
|
||||
);
|
||||
|
||||
const guild = useMemo(
|
||||
() => channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId()),
|
||||
[channel]
|
||||
);
|
||||
|
||||
const guildIcon = useMemo(() => {
|
||||
return guild?.icon == null ? undefined : IconUtils.getGuildIconURL({
|
||||
id: guild.id,
|
||||
icon: guild.icon,
|
||||
size: 30
|
||||
});
|
||||
}, [guild]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{guild != null && (
|
||||
<div className={cl("guild-name")}>
|
||||
{guildIcon != null && <img className={cl("guild-icon")} src={guildIcon} alt="" />}
|
||||
<Text variant="text-sm/bold">{guild.name}</Text>
|
||||
</div>
|
||||
)}
|
||||
<Text variant="text-sm/semibold">{channel.name}</Text>
|
||||
<div className={cl("vc-members")}>
|
||||
<SpeakerIcon size={18} />
|
||||
<UserSummaryItem
|
||||
users={users}
|
||||
renderIcon={false}
|
||||
max={7}
|
||||
size={18}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
interface VoiceChannelIndicatorProps {
|
||||
userId: string;
|
||||
}
|
||||
|
||||
const clickTimers = {} as Record<string, any>;
|
||||
|
||||
export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChannelIndicatorProps) => {
|
||||
const channelId = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStateForUser(userId)?.channelId as string | undefined);
|
||||
const channel = useMemo(() => channelId == null ? undefined : ChannelStore.getChannel(channelId), [channelId]);
|
||||
|
||||
const onClick = useCallback((e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (channel == null || channelId == null) return;
|
||||
|
||||
if (!PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel)) {
|
||||
showToast("You cannot view the user's Voice Channel", Toasts.Type.FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(clickTimers[channelId]);
|
||||
delete clickTimers[channelId];
|
||||
|
||||
if (e.detail > 1) {
|
||||
if (!PermissionStore.can(PermissionsBits.CONNECT, channel)) {
|
||||
showToast("You cannot join the user's Voice Channel", Toasts.Type.FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
selectVoiceChannel(channelId);
|
||||
} else {
|
||||
clickTimers[channelId] = setTimeout(() => {
|
||||
NavigationRouter.transitionTo(`/channels/${channel.getGuildId() ?? "@me"}/${channelId}`);
|
||||
delete clickTimers[channelId];
|
||||
}, 250);
|
||||
}
|
||||
}, [channelId]);
|
||||
|
||||
const isLocked = useMemo(() => {
|
||||
return !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel);
|
||||
}, [channelId]);
|
||||
|
||||
if (channel == null) return null;
|
||||
|
||||
return (
|
||||
<Tooltip
|
||||
text={<VoiceChannelTooltip channel={channel} />}
|
||||
tooltipClassName={cl("tooltip-container")}
|
||||
>
|
||||
{props =>
|
||||
isLocked ?
|
||||
<LockedSpeakerIcon {...props} onClick={onClick} />
|
||||
: <SpeakerIcon {...props} onClick={onClick} />
|
||||
}
|
||||
</Tooltip>
|
||||
);
|
||||
}, { noop: true });
|
|
@ -1,27 +0,0 @@
|
|||
.vc-uvs-button>div {
|
||||
white-space: normal !important;
|
||||
}
|
||||
|
||||
.vc-uvs-button {
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
height: unset;
|
||||
}
|
||||
|
||||
.vc-uvs-header {
|
||||
color: var(--header-primary);
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.vc-uvs-modal-margin {
|
||||
margin: 0 12px;
|
||||
}
|
||||
|
||||
.vc-uvs-modal-margin div {
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.vc-uvs-popout-margin-self>[class^="section"] {
|
||||
padding-top: 0;
|
||||
padding-bottom: 12px;
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2023 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 "./VoiceChannelSection.css";
|
||||
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
import { Button, Forms, PermissionStore, Toasts } from "@webpack/common";
|
||||
import { Channel } from "discord-types/general";
|
||||
|
||||
const ChannelActions = findByPropsLazy("selectChannel", "selectVoiceChannel");
|
||||
|
||||
const CONNECT = 1n << 20n;
|
||||
|
||||
interface VoiceChannelFieldProps {
|
||||
channel: Channel;
|
||||
label: string;
|
||||
showHeader: boolean;
|
||||
}
|
||||
|
||||
export const VoiceChannelSection = ({ channel, label, showHeader }: VoiceChannelFieldProps) => (
|
||||
// @TODO The div is supposed to be a UserPopoutSection
|
||||
<div>
|
||||
{showHeader && <Forms.FormTitle className="vc-uvs-header">In a voice channel</Forms.FormTitle>}
|
||||
<Button
|
||||
className="vc-uvs-button"
|
||||
color={Button.Colors.TRANSPARENT}
|
||||
size={Button.Sizes.SMALL}
|
||||
|
||||
onClick={() => {
|
||||
if (PermissionStore.can(CONNECT, channel))
|
||||
ChannelActions.selectVoiceChannel(channel.id);
|
||||
else
|
||||
Toasts.show({
|
||||
message: "Insufficient permissions to enter the channel.",
|
||||
id: "user-voice-show-insufficient-permissions",
|
||||
type: Toasts.Type.FAILURE,
|
||||
options: {
|
||||
position: Toasts.Position.BOTTOM,
|
||||
}
|
||||
});
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
|
@ -16,85 +16,85 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import "./style.css";
|
||||
|
||||
import { addDecorator, removeDecorator } from "@api/MemberListDecorators";
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { findStoreLazy } from "@webpack";
|
||||
import { ChannelStore, GuildStore, UserStore } from "@webpack/common";
|
||||
import { User } from "discord-types/general";
|
||||
|
||||
import { VoiceChannelSection } from "./components/VoiceChannelSection";
|
||||
|
||||
const VoiceStateStore = findStoreLazy("VoiceStateStore");
|
||||
import { VoiceChannelIndicator } from "./components";
|
||||
|
||||
const settings = definePluginSettings({
|
||||
showInUserProfileModal: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Show a user's voice channel in their profile modal",
|
||||
description: "Show a user's Voice Channel indicator in their profile next to the name",
|
||||
default: true,
|
||||
restartNeeded: true
|
||||
},
|
||||
showVoiceChannelSectionHeader: {
|
||||
showInVoiceMemberList: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: 'Whether to show "IN A VOICE CHANNEL" above the join button',
|
||||
description: "Show a user's Voice Channel indicator in the member and DMs list",
|
||||
default: true,
|
||||
restartNeeded: true
|
||||
}
|
||||
});
|
||||
|
||||
interface UserProps {
|
||||
user: User;
|
||||
}
|
||||
|
||||
const VoiceChannelField = ErrorBoundary.wrap(({ user }: UserProps) => {
|
||||
const { channelId } = VoiceStateStore.getVoiceStateForUser(user.id) ?? {};
|
||||
if (!channelId) return null;
|
||||
|
||||
const channel = ChannelStore.getChannel(channelId);
|
||||
if (!channel) return null;
|
||||
|
||||
const guild = GuildStore.getGuild(channel.guild_id);
|
||||
|
||||
if (!guild) return null; // When in DM call
|
||||
|
||||
const result = `${guild.name} | ${channel.name}`;
|
||||
|
||||
return (
|
||||
<VoiceChannelSection
|
||||
channel={channel}
|
||||
label={result}
|
||||
showHeader={settings.store.showVoiceChannelSectionHeader}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
export default definePlugin({
|
||||
name: "UserVoiceShow",
|
||||
description: "Shows whether a User is currently in a voice channel somewhere in their profile",
|
||||
authors: [Devs.LordElias],
|
||||
description: "Shows an indicator when a user is in a Voice Channel",
|
||||
authors: [Devs.LordElias, Devs.Nuckyz],
|
||||
settings,
|
||||
|
||||
patchModal({ user }: UserProps) {
|
||||
if (!settings.store.showInUserProfileModal)
|
||||
return null;
|
||||
|
||||
return (
|
||||
<div className="vc-uvs-modal-margin">
|
||||
<VoiceChannelField user={user} />
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
patchProfilePopout: ({ user }: UserProps) => {
|
||||
const isSelfUser = user.id === UserStore.getCurrentUser().id;
|
||||
return (
|
||||
<div className={isSelfUser ? "vc-uvs-popout-margin-self" : ""}>
|
||||
<VoiceChannelField user={user} />
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
patches: [
|
||||
// @TODO Maybe patch UserVoiceShow in simplified profile popout
|
||||
// @TODO Patch new profile modal
|
||||
// User Popout, Full Size Profile, Direct Messages Side Profile
|
||||
{
|
||||
find: ".Messages.USER_PROFILE_LOAD_ERROR",
|
||||
replacement: {
|
||||
match: /(\.fetchError.+?\?)null/,
|
||||
replace: (_, rest) => `${rest}$self.VoiceChannelIndicator({userId:arguments[0]?.userId})`
|
||||
},
|
||||
predicate: () => settings.store.showInUserProfileModal
|
||||
},
|
||||
// To use without the MemberList decorator API
|
||||
/* // Guild Members List
|
||||
{
|
||||
find: ".lostPermission)",
|
||||
replacement: {
|
||||
match: /\.lostPermission\).+?(?=avatar:)/,
|
||||
replace: "$&children:[$self.VoiceChannelIndicator({userId:arguments[0]?.user?.id})],"
|
||||
},
|
||||
predicate: () => settings.store.showVoiceChannelIndicator
|
||||
},
|
||||
// Direct Messages List
|
||||
{
|
||||
find: "PrivateChannel.renderAvatar",
|
||||
replacement: {
|
||||
match: /\.Messages\.CLOSE_DM.+?}\)(?=])/,
|
||||
replace: "$&,$self.VoiceChannelIndicator({userId:arguments[0]?.user?.id})"
|
||||
},
|
||||
predicate: () => settings.store.showVoiceChannelIndicator
|
||||
}, */
|
||||
// Friends List
|
||||
{
|
||||
find: ".avatar,animate:",
|
||||
replacement: {
|
||||
match: /\.subtext,children:.+?}\)\]}\)(?=])/,
|
||||
replace: "$&,$self.VoiceChannelIndicator({userId:arguments[0]?.user?.id})"
|
||||
},
|
||||
predicate: () => settings.store.showInVoiceMemberList
|
||||
}
|
||||
],
|
||||
|
||||
start() {
|
||||
if (settings.store.showInVoiceMemberList) {
|
||||
addDecorator("UserVoiceShow", ({ user }) => user == null ? null : <VoiceChannelIndicator userId={user.id} />);
|
||||
}
|
||||
},
|
||||
|
||||
stop() {
|
||||
removeDecorator("UserVoiceShow");
|
||||
},
|
||||
|
||||
VoiceChannelIndicator
|
||||
});
|
||||
|
|
37
src/plugins/userVoiceShow/style.css
Normal file
37
src/plugins/userVoiceShow/style.css
Normal file
|
@ -0,0 +1,37 @@
|
|||
.vc-uvs-speaker {
|
||||
color: var(--interactive-normal);
|
||||
padding: 0 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.vc-uvs-clickable {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.vc-uvs-clickable:hover {
|
||||
color: var(--interactive-hover);
|
||||
}
|
||||
|
||||
.vc-uvs-tooltip-container {
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
.vc-uvs-guild-name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.vc-uvs-guild-icon {
|
||||
border-radius: 100%;
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.vc-uvs-vc-members {
|
||||
display: flex;
|
||||
margin: 8px 0;
|
||||
flex-direction: row;
|
||||
gap: 6px;
|
||||
}
|
Loading…
Reference in a new issue