Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new plugin YoutubeDescription #2427

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/plugins/youtubeDescription/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# YoutubeDescription

Adds descriptions to youtube video embeds

![demo](https://github.com/Vendicated/Vencord/assets/82430093/a69a48fa-d1a5-490d-a917-5c60e3fc38a8)
49 changes: 49 additions & 0 deletions src/plugins/youtubeDescription/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 { isNonNullish } from "@utils/guards";
import definePlugin from "@utils/types";
import { useState } from "@webpack/common";
import { Embed } from "discord-types/general";

interface ToggleableDescriptionProps { embed: Embed, original: () => any; }

export default definePlugin({
name: "YoutubeDescription",
description: "Adds descriptions to youtube video embeds",
authors: [Devs.arHSM],
patches: [
{
find: ".default.Messages.SUPPRESS_ALL_EMBEDS",
replacement: {
match: /case (\i\.MessageEmbedTypes\.VIDEO):(case \i\.MessageEmbedTypes\.\i:)*break;default:(\i)=(?:(this\.renderDescription)\(\))\}/,
replace: "$2 break; case $1: $3 = $self.ToggleableDescriptionWrapper({ embed: this.props.embed, original: $4.bind(this) }); break; default: $3 = $4() }"
}
}
],
ToggleableDescription({ embed, original }: ToggleableDescriptionProps) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be wrapped in an ErrorBoundary, then you also wouldn't need your Wrapper function

Suggested change
ToggleableDescription({ embed, original }: ToggleableDescriptionProps) {
ToggleableDescription: ErrorBoundary.wrap(({ embed, original }: ToggleableDescriptionProps) => {

const [isOpen, setOpen] = useState(false);

console.warn(embed);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this console.log

Suggested change
console.warn(embed);


return !isNonNullish(embed.rawDescription)
? null
: embed.rawDescription.length > 20
? <div
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this nested ternary isn't too great.. it'd be way nicer for readability to convert it into simple if statements, like

if (!embed.rawDescription)
	return null;
if (embed.rawDescription.length <= 20)
	return original();

return (
	<div>
		....

style={{ cursor: "pointer", marginTop: isOpen ? "0px" : "8px" }}
onClick={() => setOpen(o => !o)}
>
{isOpen
? original()
: embed.rawDescription.substring(0, 20) + "..."}
</div>
: original();
},
ToggleableDescriptionWrapper(props: ToggleableDescriptionProps) {
return <this.ToggleableDescription {...props}></this.ToggleableDescription>;
}
});