mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 01:46:23 +00:00
Merge branch 'dev' into immediate-finds
This commit is contained in:
commit
bebb98d1c7
14 changed files with 320 additions and 304 deletions
|
@ -120,7 +120,7 @@ const settings = definePluginSettings({
|
|||
stateString: {
|
||||
type: OptionType.STRING,
|
||||
description: "Activity state format string",
|
||||
default: "{artist}"
|
||||
default: "{artist} · {album}"
|
||||
},
|
||||
largeImageType: {
|
||||
type: OptionType.SELECT,
|
||||
|
|
|
@ -11,37 +11,11 @@ import type { TrackData } from ".";
|
|||
|
||||
const exec = promisify(execFile);
|
||||
|
||||
// function exec(file: string, args: string[] = []) {
|
||||
// return new Promise<{ code: number | null, stdout: string | null, stderr: string | null; }>((resolve, reject) => {
|
||||
// const process = spawn(file, args, { stdio: [null, "pipe", "pipe"] });
|
||||
|
||||
// let stdout: string | null = null;
|
||||
// process.stdout.on("data", (chunk: string) => { stdout ??= ""; stdout += chunk; });
|
||||
// let stderr: string | null = null;
|
||||
// process.stderr.on("data", (chunk: string) => { stdout ??= ""; stderr += chunk; });
|
||||
|
||||
// process.on("exit", code => { resolve({ code, stdout, stderr }); });
|
||||
// process.on("error", err => reject(err));
|
||||
// });
|
||||
// }
|
||||
|
||||
async function applescript(cmds: string[]) {
|
||||
const { stdout } = await exec("osascript", cmds.map(c => ["-e", c]).flat());
|
||||
return stdout;
|
||||
}
|
||||
|
||||
function makeSearchUrl(type: string, query: string) {
|
||||
const url = new URL("https://tools.applemediaservices.com/api/apple-media/music/US/search.json");
|
||||
url.searchParams.set("types", type);
|
||||
url.searchParams.set("limit", "1");
|
||||
url.searchParams.set("term", query);
|
||||
return url;
|
||||
}
|
||||
|
||||
const requestOptions: RequestInit = {
|
||||
headers: { "user-agent": "Mozilla/5.0 (Windows NT 10.0; rv:125.0) Gecko/20100101 Firefox/125.0" },
|
||||
};
|
||||
|
||||
interface RemoteData {
|
||||
appleMusicLink?: string,
|
||||
songLink?: string,
|
||||
|
@ -51,6 +25,24 @@ interface RemoteData {
|
|||
|
||||
let cachedRemoteData: { id: string, data: RemoteData; } | { id: string, failures: number; } | null = null;
|
||||
|
||||
const APPLE_MUSIC_BUNDLE_REGEX = /<script type="module" crossorigin src="([a-zA-Z0-9.\-/]+)"><\/script>/;
|
||||
const APPLE_MUSIC_TOKEN_REGEX = /\w+="([A-Za-z0-9-_]*\.[A-Za-z0-9-_]*\.[A-Za-z0-9-_]*)",\w+="x-apple-jingle-correlation-key"/;
|
||||
|
||||
let cachedToken: string | undefined = undefined;
|
||||
|
||||
const getToken = async () => {
|
||||
if (cachedToken) return cachedToken;
|
||||
|
||||
const html = await fetch("https://music.apple.com/").then(r => r.text());
|
||||
const bundleUrl = new URL(html.match(APPLE_MUSIC_BUNDLE_REGEX)![1], "https://music.apple.com/");
|
||||
|
||||
const bundle = await fetch(bundleUrl).then(r => r.text());
|
||||
const token = bundle.match(APPLE_MUSIC_TOKEN_REGEX)![1];
|
||||
|
||||
cachedToken = token;
|
||||
return token;
|
||||
};
|
||||
|
||||
async function fetchRemoteData({ id, name, artist, album }: { id: string, name: string, artist: string, album: string; }) {
|
||||
if (id === cachedRemoteData?.id) {
|
||||
if ("data" in cachedRemoteData) return cachedRemoteData.data;
|
||||
|
@ -58,21 +50,39 @@ async function fetchRemoteData({ id, name, artist, album }: { id: string, name:
|
|||
}
|
||||
|
||||
try {
|
||||
const [songData, artistData] = await Promise.all([
|
||||
fetch(makeSearchUrl("songs", artist + " " + album + " " + name), requestOptions).then(r => r.json()),
|
||||
fetch(makeSearchUrl("artists", artist.split(/ *[,&] */)[0]), requestOptions).then(r => r.json())
|
||||
]);
|
||||
const dataUrl = new URL("https://amp-api-edge.music.apple.com/v1/catalog/us/search");
|
||||
dataUrl.searchParams.set("platform", "web");
|
||||
dataUrl.searchParams.set("l", "en-US");
|
||||
dataUrl.searchParams.set("limit", "1");
|
||||
dataUrl.searchParams.set("with", "serverBubbles");
|
||||
dataUrl.searchParams.set("types", "songs");
|
||||
dataUrl.searchParams.set("term", `${name} ${artist} ${album}`);
|
||||
dataUrl.searchParams.set("include[songs]", "artists");
|
||||
|
||||
const appleMusicLink = songData?.songs?.data[0]?.attributes.url;
|
||||
const songLink = songData?.songs?.data[0]?.id ? `https://song.link/i/${songData?.songs?.data[0]?.id}` : undefined;
|
||||
const token = await getToken();
|
||||
|
||||
const albumArtwork = songData?.songs?.data[0]?.attributes.artwork.url.replace("{w}", "512").replace("{h}", "512");
|
||||
const artistArtwork = artistData?.artists?.data[0]?.attributes.artwork.url.replace("{w}", "512").replace("{h}", "512");
|
||||
const songData = await fetch(dataUrl, {
|
||||
headers: {
|
||||
"accept": "*/*",
|
||||
"accept-language": "en-US,en;q=0.9",
|
||||
"authorization": `Bearer ${token}`,
|
||||
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
|
||||
"origin": "https://music.apple.com",
|
||||
},
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => data.results.song.data[0]);
|
||||
|
||||
cachedRemoteData = {
|
||||
id,
|
||||
data: { appleMusicLink, songLink, albumArtwork, artistArtwork }
|
||||
data: {
|
||||
appleMusicLink: songData.attributes.url,
|
||||
songLink: `https://song.link/i/${songData.id}`,
|
||||
albumArtwork: songData.attributes.artwork.url.replace("{w}x{h}", "512x512"),
|
||||
artistArtwork: songData.relationships.artists.data[0].attributes.artwork.url.replace("{w}x{h}", "512x512"),
|
||||
}
|
||||
};
|
||||
|
||||
return cachedRemoteData.data;
|
||||
} catch (e) {
|
||||
console.error("[AppleMusicRichPresence] Failed to fetch remote data:", e);
|
||||
|
|
|
@ -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,"
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
|
@ -33,7 +33,7 @@ interface URLReplacementRule {
|
|||
// Do not forget to add protocols to the ALLOWED_PROTOCOLS constant
|
||||
const UrlReplacementRules: Record<string, URLReplacementRule> = {
|
||||
spotify: {
|
||||
match: /^https:\/\/open\.spotify\.com\/(?:intl-[a-z]{2}\/)?(track|album|artist|playlist|user|episode)\/(.+)(?:\?.+?)?$/,
|
||||
match: /^https:\/\/open\.spotify\.com\/(?:intl-[a-z]{2}\/)?(track|album|artist|playlist|user|episode|prerelease)\/(.+)(?:\?.+?)?$/,
|
||||
replace: (_, type, id) => `spotify://${type}/${id}`,
|
||||
description: "Open Spotify links in the Spotify app",
|
||||
shortlinkMatch: /^https:\/\/spotify\.link\/.+$/,
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
# TimeBarAllActivities
|
||||
|
||||
Adds the Spotify time bar to all activities if they have start and end timestamps.
|
||||
|
||||
![](https://github.com/user-attachments/assets/9fbbe33c-8218-43c9-8b8d-f907a4e809fe)
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { findComponentByCode } from "@webpack";
|
||||
import { RequiredDeep } from "type-fest";
|
||||
|
||||
interface Activity {
|
||||
timestamps?: ActivityTimestamps;
|
||||
}
|
||||
|
||||
interface ActivityTimestamps {
|
||||
start?: string;
|
||||
end?: string;
|
||||
}
|
||||
|
||||
interface TimebarComponentProps {
|
||||
activity: Activity;
|
||||
}
|
||||
|
||||
const ActivityTimeBar = findComponentByCode<ActivityTimestamps>(".bar", ".progress", "(100*");
|
||||
|
||||
function isActivityTimestamped(activity: Activity): activity is RequiredDeep<Activity> {
|
||||
return activity.timestamps != null && activity.timestamps.start != null && activity.timestamps.end != null;
|
||||
}
|
||||
|
||||
export const settings = definePluginSettings({
|
||||
hideActivityDetailText: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Hide the large title text next to the activity",
|
||||
default: true,
|
||||
},
|
||||
hideActivityTimerBadges: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Hide the timer badges next to the activity",
|
||||
default: true,
|
||||
}
|
||||
});
|
||||
|
||||
export default definePlugin({
|
||||
name: "TimeBarAllActivities",
|
||||
description: "Adds the Spotify time bar to all activities if they have start and end timestamps",
|
||||
authors: [Devs.fawn, Devs.niko],
|
||||
settings,
|
||||
patches: [
|
||||
{
|
||||
find: ".gameState,children:",
|
||||
replacement: [
|
||||
// Insert Spotify time bar component
|
||||
{
|
||||
match: /\(0,.{0,30}activity:(\i),className:\i\.badges\}\)/g,
|
||||
replace: "$&,$self.TimebarComponent({activity:$1})"
|
||||
},
|
||||
// Hide the large title on listening activities, to make them look more like Spotify (also visible from hovering over the large icon)
|
||||
{
|
||||
match: /(\i).type===(\i\.\i)\.WATCHING/,
|
||||
replace: "($self.settings.store.hideActivityDetailText&&$self.isActivityTimestamped($1)&&$1.type===$2.LISTENING)||$&"
|
||||
}
|
||||
]
|
||||
},
|
||||
// Hide the "badge" timers that count the time since the activity starts
|
||||
{
|
||||
find: ".TvIcon).otherwise",
|
||||
replacement: {
|
||||
match: /null!==\(\i=null===\(\i=(\i)\.timestamps\).{0,50}created_at/,
|
||||
replace: "($self.settings.store.hideActivityTimerBadges&&$self.isActivityTimestamped($1))?null:$&"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
isActivityTimestamped,
|
||||
|
||||
TimebarComponent: ErrorBoundary.wrap(({ activity }: TimebarComponentProps) => {
|
||||
if (!isActivityTimestamped(activity)) return null;
|
||||
|
||||
return <ActivityTimeBar start={activity.timestamps.start} end={activity.timestamps.end} />;
|
||||
}, { noop: true })
|
||||
});
|
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)
|
168
src/plugins/userVoiceShow/components.tsx
Normal file
168
src/plugins/userVoiceShow/components.tsx
Normal file
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* 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 { findByProps, findComponentByCode, findStore } 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 } = findByProps("selectChannel", "selectVoiceChannel");
|
||||
const VoiceStateStore = findStore("VoiceStateStore");
|
||||
const UserSummaryItem = findComponentByCode("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]);
|
||||
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 { findByProps } from "@webpack";
|
||||
import { Button, Forms, PermissionStore, Toasts } from "@webpack/common";
|
||||
import { Channel } from "discord-types/general";
|
||||
|
||||
const ChannelActions = findByProps("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 { findStore } from "@webpack";
|
||||
import { ChannelStore, GuildStore, UserStore } from "@webpack/common";
|
||||
import { User } from "discord-types/general";
|
||||
|
||||
import { VoiceChannelSection } from "./components/VoiceChannelSection";
|
||||
|
||||
const VoiceStateStore = findStore("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;
|
||||
}
|
|
@ -267,7 +267,7 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
|||
id: 841509053422632990n
|
||||
},
|
||||
F53: {
|
||||
name: "F53",
|
||||
name: "Cassie (Code)",
|
||||
id: 280411966126948353n
|
||||
},
|
||||
AutumnVN: {
|
||||
|
|
Loading…
Reference in a new issue