Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
3c02d6e1b4 | ||
|
a2a33ca62d | ||
|
d8cd557fb2 | ||
|
7568bbaed0 | ||
|
9023d45d9e | ||
|
bee70390a9 | ||
|
3e3d05fc26 | ||
|
6300198a54 | ||
|
458c7ed4c5 | ||
|
d888a0a291 |
18
.github/workflows/codeberg-mirror.yml
vendored
Normal file
18
.github/workflows/codeberg-mirror.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: Sync to Codeberg
|
||||
on:
|
||||
push:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "0 */6 * * *"
|
||||
|
||||
jobs:
|
||||
codeberg:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: pixta-dev/repository-mirroring-action@674e65a7d483ca28dafaacba0d07351bdcc8bd75 # v1.1.1
|
||||
with:
|
||||
target_repo_url: "git@codeberg.org:Ven/cord.git"
|
||||
ssh_private_key: ${{ secrets.CODEBERG_SSH_PRIVATE_KEY }}
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "vencord",
|
||||
"private": "true",
|
||||
"version": "1.2.5",
|
||||
"version": "1.2.6",
|
||||
"description": "The cutest Discord client mod",
|
||||
"homepage": "https://github.com/Vendicated/Vencord#readme",
|
||||
"bugs": {
|
||||
|
@ -16,6 +16,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import "../checkNodeVersion.js";
|
||||
|
||||
import { exec, execSync } from "child_process";
|
||||
import { existsSync, readFileSync } from "fs";
|
||||
import { readdir, readFile } from "fs/promises";
|
||||
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2022 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/>.
|
||||
*/
|
||||
|
||||
// A script to automatically generate a list of all plugins.
|
||||
// Just copy paste the entire file into a running Vencord install and it will prompt you
|
||||
// to save the file
|
||||
|
||||
// eslint-disable-next-line spaced-comment
|
||||
/// <reference types="../src/modules"/>
|
||||
|
||||
(() => {
|
||||
/**
|
||||
* @type {typeof import("~plugins").default}
|
||||
*/
|
||||
const Plugins = Vencord.Plugins.plugins;
|
||||
|
||||
const header = `
|
||||
<!-- This file is auto generated, do not edit -->
|
||||
|
||||
# Vencord Plugins
|
||||
`;
|
||||
|
||||
let tableOfContents = "\n\n";
|
||||
|
||||
let list = "\n\n";
|
||||
|
||||
for (const p of Object.values(Plugins).sort((a, b) => a.name.localeCompare(b.name))) {
|
||||
tableOfContents += `- [${p.name}](#${p.name.replaceAll(" ", "-")})\n`;
|
||||
|
||||
list += `## ${p.name}
|
||||
|
||||
${p.description}
|
||||
|
||||
**Authors**: ${p.authors.map(a => a.name).join(", ")}
|
||||
`;
|
||||
|
||||
if (p.commands?.length) {
|
||||
list += "\n\n#### Commands\n";
|
||||
for (const cmd of p.commands) {
|
||||
list += `${cmd.name} - ${cmd.description}\n\n`;
|
||||
}
|
||||
}
|
||||
list += "\n\n";
|
||||
}
|
||||
|
||||
copy(header + tableOfContents + list);
|
||||
})();
|
@ -19,7 +19,7 @@
|
||||
import { Dirent, readdirSync, readFileSync, writeFileSync } from "fs";
|
||||
import { access, readFile } from "fs/promises";
|
||||
import { join } from "path";
|
||||
import { BigIntLiteral, createSourceFile, Identifier, isArrayLiteralExpression, isCallExpression, isExportAssignment, isIdentifier, isObjectLiteralExpression, isPropertyAccessExpression, isPropertyAssignment, isStringLiteral, isVariableStatement, NamedDeclaration, NodeArray, ObjectLiteralExpression, ScriptTarget, StringLiteral, SyntaxKind } from "typescript";
|
||||
import { BigIntLiteral, createSourceFile, Identifier, isArrayLiteralExpression, isCallExpression, isExportAssignment, isIdentifier, isObjectLiteralExpression, isPropertyAccessExpression, isPropertyAssignment, isSatisfiesExpression, isStringLiteral, isVariableStatement, NamedDeclaration, NodeArray, ObjectLiteralExpression, ScriptTarget, StringLiteral, SyntaxKind } from "typescript";
|
||||
|
||||
interface Dev {
|
||||
name: string;
|
||||
@ -66,9 +66,9 @@ function parseDevs() {
|
||||
|
||||
const value = devsDeclaration.initializer.arguments[0];
|
||||
|
||||
if (!isObjectLiteralExpression(value)) return;
|
||||
if (!isSatisfiesExpression(value) || !isObjectLiteralExpression(value.expression)) throw new Error("Failed to parse devs: not an object literal");
|
||||
|
||||
for (const prop of value.properties) {
|
||||
for (const prop of value.expression.properties) {
|
||||
const name = (prop.name as Identifier).text;
|
||||
const value = isPropertyAssignment(prop) ? prop.initializer : prop;
|
||||
|
||||
@ -130,7 +130,9 @@ async function parseFile(fileName: string) {
|
||||
if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal");
|
||||
data.authors = value.elements.map(e => {
|
||||
if (!isPropertyAccessExpression(e)) throw fail("authors array contains non-property access expressions");
|
||||
return devs[getName(e)!];
|
||||
const d = devs[getName(e)!];
|
||||
if (!d) throw fail(`couldn't look up author ${getName(e)}`);
|
||||
return d;
|
||||
});
|
||||
break;
|
||||
case "tags":
|
||||
|
@ -266,7 +266,12 @@ export function definePluginSettings<D extends SettingsDefinition, C extends Set
|
||||
def,
|
||||
checks: checks ?? {},
|
||||
pluginName: "",
|
||||
|
||||
withPrivateSettings<T>() {
|
||||
return this as DefinedSettings<D, C> & { store: T; };
|
||||
}
|
||||
};
|
||||
|
||||
return definedSettings;
|
||||
}
|
||||
|
||||
|
12
src/components/ExpandableHeader.css
Normal file
12
src/components/ExpandableHeader.css
Normal file
@ -0,0 +1,12 @@
|
||||
.vc-expandableheader-center-flex {
|
||||
display: flex;
|
||||
justify-items: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.vc-expandableheader-btn {
|
||||
all: unset;
|
||||
cursor: pointer;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
108
src/components/ExpandableHeader.tsx
Normal file
108
src/components/ExpandableHeader.tsx
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 { classNameFactory } from "@api/Styles";
|
||||
import { Text, Tooltip, useState } from "@webpack/common";
|
||||
export const cl = classNameFactory("vc-expandableheader-");
|
||||
import "./ExpandableHeader.css";
|
||||
|
||||
export interface ExpandableHeaderProps {
|
||||
onMoreClick?: () => void;
|
||||
moreTooltipText?: string;
|
||||
onDropDownClick?: (state: boolean) => void;
|
||||
defaultState?: boolean;
|
||||
headerText: string;
|
||||
children: React.ReactNode;
|
||||
buttons?: React.ReactNode[];
|
||||
}
|
||||
|
||||
export default function ExpandableHeader({ children, onMoreClick, buttons, moreTooltipText, defaultState = false, onDropDownClick, headerText }: ExpandableHeaderProps) {
|
||||
const [showContent, setShowContent] = useState(defaultState);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: "8px"
|
||||
}}>
|
||||
<Text
|
||||
tag="h2"
|
||||
variant="eyebrow"
|
||||
style={{
|
||||
color: "var(--header-primary)",
|
||||
display: "inline"
|
||||
}}
|
||||
>
|
||||
{headerText}
|
||||
</Text>
|
||||
|
||||
<div className={cl("center-flex")}>
|
||||
{
|
||||
buttons ?? null
|
||||
}
|
||||
|
||||
{
|
||||
onMoreClick && // only show more button if callback is provided
|
||||
<Tooltip text={moreTooltipText}>
|
||||
{tooltipProps => (
|
||||
<button
|
||||
{...tooltipProps}
|
||||
className={cl("btn")}
|
||||
onClick={onMoreClick}>
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path fill="var(--text-normal)" d="M7 12.001C7 10.8964 6.10457 10.001 5 10.001C3.89543 10.001 3 10.8964 3 12.001C3 13.1055 3.89543 14.001 5 14.001C6.10457 14.001 7 13.1055 7 12.001ZM14 12.001C14 10.8964 13.1046 10.001 12 10.001C10.8954 10.001 10 10.8964 10 12.001C10 13.1055 10.8954 14.001 12 14.001C13.1046 14.001 14 13.1055 14 12.001ZM19 10.001C20.1046 10.001 21 10.8964 21 12.001C21 13.1055 20.1046 14.001 19 14.001C17.8954 14.001 17 13.1055 17 12.001C17 10.8964 17.8954 10.001 19 10.001Z" />
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
</Tooltip>
|
||||
}
|
||||
|
||||
|
||||
<Tooltip text={showContent ? "Hide " + headerText : "Show " + headerText}>
|
||||
{tooltipProps => (
|
||||
<button
|
||||
{...tooltipProps}
|
||||
className={cl("btn")}
|
||||
onClick={() => {
|
||||
setShowContent(v => !v);
|
||||
onDropDownClick?.(showContent);
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
transform={showContent ? "scale(1 -1)" : "scale(1 1)"}
|
||||
>
|
||||
<path fill="var(--text-normal)" d="M16.59 8.59003L12 13.17L7.41 8.59003L6 10L12 16L18 10L16.59 8.59003Z" />
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
{showContent && children}
|
||||
</>
|
||||
);
|
||||
}
|
@ -22,11 +22,12 @@ import { Devs } from "@utils/constants";
|
||||
import { ApngBlendOp, ApngDisposeOp, getGifEncoder, importApngJs } from "@utils/dependencies";
|
||||
import { getCurrentGuild } from "@utils/discord";
|
||||
import { proxyLazy } from "@utils/lazy";
|
||||
import { Logger } from "@utils/Logger";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { findByCodeLazy, findByPropsLazy, findLazy, findStoreLazy } from "@webpack";
|
||||
import { ChannelStore, EmojiStore, FluxDispatcher, Parser, PermissionStore, UserStore } from "@webpack/common";
|
||||
import type { Message } from "discord-types/general";
|
||||
import type { ReactNode } from "react";
|
||||
import type { ReactElement, ReactNode } from "react";
|
||||
|
||||
const DRAFT_TYPE = 0;
|
||||
const promptToUpload = findByCodeLazy("UPLOAD_FILE_LIMIT_ERROR");
|
||||
@ -392,70 +393,137 @@ export default definePlugin({
|
||||
});
|
||||
},
|
||||
|
||||
patchFakeNitroEmojisOrRemoveStickersLinks(content: Array<any>, inline: boolean) {
|
||||
if (content.length > 1 && !settings.store.transformCompoundSentence) return content;
|
||||
trimContent(content: Array<any>) {
|
||||
const firstContent = content[0];
|
||||
if (typeof firstContent === "string") content[0] = firstContent.trimStart();
|
||||
if (content[0] === "") content.shift();
|
||||
|
||||
const newContent: Array<any> = [];
|
||||
const lastIndex = content.length - 1;
|
||||
const lastContent = content[lastIndex];
|
||||
if (typeof lastContent === "string") content[lastIndex] = lastContent.trimEnd();
|
||||
if (content[lastIndex] === "") content.pop();
|
||||
},
|
||||
|
||||
clearEmptyArrayItems(array: Array<any>) {
|
||||
return array.filter(item => item != null);
|
||||
},
|
||||
|
||||
ensureChildrenIsArray(child: ReactElement) {
|
||||
if (!Array.isArray(child.props.children)) child.props.children = [child.props.children];
|
||||
},
|
||||
|
||||
patchFakeNitroEmojisOrRemoveStickersLinks(content: Array<any>, inline: boolean) {
|
||||
// If content has more than one child or it's a single ReactElement like a header or list
|
||||
if ((content.length > 1 || typeof content[0]?.type === "string") && !settings.store.transformCompoundSentence) return content;
|
||||
|
||||
let nextIndex = content.length;
|
||||
|
||||
for (const element of content) {
|
||||
if (element.props?.trusted == null) {
|
||||
newContent.push(element);
|
||||
continue;
|
||||
}
|
||||
|
||||
const transformLinkChild = (child: ReactElement) => {
|
||||
if (settings.store.transformEmojis) {
|
||||
const fakeNitroMatch = element.props.href.match(fakeNitroEmojiRegex);
|
||||
const fakeNitroMatch = child.props.href.match(fakeNitroEmojiRegex);
|
||||
if (fakeNitroMatch) {
|
||||
let url: URL | null = null;
|
||||
try {
|
||||
url = new URL(element.props.href);
|
||||
url = new URL(child.props.href);
|
||||
} catch { }
|
||||
|
||||
const emojiName = EmojiStore.getCustomEmojiById(fakeNitroMatch[1])?.name ?? url?.searchParams.get("name") ?? "FakeNitroEmoji";
|
||||
|
||||
newContent.push(Parser.defaultRules.customEmoji.react({
|
||||
jumboable: !inline && content.length === 1,
|
||||
return Parser.defaultRules.customEmoji.react({
|
||||
jumboable: !inline && content.length === 1 && typeof content[0].type !== "string",
|
||||
animated: fakeNitroMatch[2] === "gif",
|
||||
emojiId: fakeNitroMatch[1],
|
||||
name: emojiName,
|
||||
fake: true
|
||||
}, void 0, { key: String(nextIndex++) }));
|
||||
|
||||
continue;
|
||||
}, void 0, { key: String(nextIndex++) });
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.store.transformStickers) {
|
||||
if (fakeNitroStickerRegex.test(element.props.href)) continue;
|
||||
if (fakeNitroStickerRegex.test(child.props.href)) return null;
|
||||
|
||||
const gifMatch = element.props.href.match(fakeNitroGifStickerRegex);
|
||||
const gifMatch = child.props.href.match(fakeNitroGifStickerRegex);
|
||||
if (gifMatch) {
|
||||
// There is no way to differentiate a regular gif attachment from a fake nitro animated sticker, so we check if the StickerStore contains the id of the fake sticker
|
||||
if (StickerStore.getStickerById(gifMatch[1])) continue;
|
||||
if (StickerStore.getStickerById(gifMatch[1])) return null;
|
||||
}
|
||||
}
|
||||
|
||||
newContent.push(element);
|
||||
return child;
|
||||
};
|
||||
|
||||
const transformChild = (child: ReactElement) => {
|
||||
if (child?.props?.trusted != null) return transformLinkChild(child);
|
||||
if (child?.props?.children != null) {
|
||||
if (!Array.isArray(child.props.children)) {
|
||||
child.props.children = modifyChild(child.props.children);
|
||||
return child;
|
||||
}
|
||||
|
||||
const firstContent = newContent[0];
|
||||
if (typeof firstContent === "string") newContent[0] = firstContent.trimStart();
|
||||
child.props.children = modifyChildren(child.props.children);
|
||||
if (child.props.children.length === 0) return null;
|
||||
return child;
|
||||
}
|
||||
|
||||
return newContent;
|
||||
return child;
|
||||
};
|
||||
|
||||
const modifyChild = (child: ReactElement) => {
|
||||
const newChild = transformChild(child);
|
||||
|
||||
if (newChild?.type === "ul" || newChild?.type === "ol") {
|
||||
this.ensureChildrenIsArray(newChild);
|
||||
if (newChild.props.children.length === 0) return null;
|
||||
|
||||
let listHasAnItem = false;
|
||||
for (const [index, child] of newChild.props.children.entries()) {
|
||||
if (child == null) {
|
||||
delete newChild.props.children[index];
|
||||
continue;
|
||||
}
|
||||
|
||||
this.ensureChildrenIsArray(child);
|
||||
if (child.props.children.length > 0) listHasAnItem = true;
|
||||
else delete newChild.props.children[index];
|
||||
}
|
||||
|
||||
if (!listHasAnItem) return null;
|
||||
|
||||
newChild.props.children = this.clearEmptyArrayItems(newChild.props.children);
|
||||
}
|
||||
|
||||
return newChild;
|
||||
};
|
||||
|
||||
const modifyChildren = (children: Array<ReactElement>) => {
|
||||
for (const [index, child] of children.entries()) children[index] = modifyChild(child);
|
||||
|
||||
children = this.clearEmptyArrayItems(children);
|
||||
this.trimContent(children);
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
try {
|
||||
return modifyChildren(window._.cloneDeep(content));
|
||||
} catch (err) {
|
||||
new Logger("FakeNitro").error(err);
|
||||
return content;
|
||||
}
|
||||
},
|
||||
|
||||
patchFakeNitroStickers(stickers: Array<any>, message: Message) {
|
||||
const itemsToMaybePush: Array<string> = [];
|
||||
|
||||
const contentItems = message.content.split(/\s/);
|
||||
if (contentItems.length === 1 && !settings.store.transformCompoundSentence) itemsToMaybePush.push(contentItems[0]);
|
||||
else itemsToMaybePush.push(...contentItems);
|
||||
if (settings.store.transformCompoundSentence) itemsToMaybePush.push(...contentItems);
|
||||
else if (contentItems.length === 1) itemsToMaybePush.push(contentItems[0]);
|
||||
|
||||
itemsToMaybePush.push(...message.attachments.filter(attachment => attachment.content_type === "image/gif").map(attachment => attachment.url));
|
||||
|
||||
for (const item of itemsToMaybePush) {
|
||||
if (!settings.store.transformCompoundSentence && !item.startsWith("http")) continue;
|
||||
|
||||
const imgMatch = item.match(fakeNitroStickerRegex);
|
||||
if (imgMatch) {
|
||||
let url: URL | null = null;
|
||||
@ -492,10 +560,13 @@ export default definePlugin({
|
||||
},
|
||||
|
||||
shouldIgnoreEmbed(embed: Message["embeds"][number], message: Message) {
|
||||
if (message.content.split(/\s/).length > 1 && !settings.store.transformCompoundSentence) return false;
|
||||
const contentItems = message.content.split(/\s/);
|
||||
if (contentItems.length > 1 && !settings.store.transformCompoundSentence) return false;
|
||||
|
||||
switch (embed.type) {
|
||||
case "image": {
|
||||
if (!settings.store.transformCompoundSentence && !contentItems.includes(embed.url!) && !contentItems.includes(embed.image!.proxyURL)) return false;
|
||||
|
||||
if (settings.store.transformEmojis) {
|
||||
if (fakeNitroEmojiRegex.test(embed.url!)) return true;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import { get, set } from "@api/DataStore";
|
||||
import { addButton, removeButton } from "@api/MessagePopover";
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin from "@utils/types";
|
||||
import { ChannelStore, FluxDispatcher } from "@webpack/common";
|
||||
import { ChannelStore } from "@webpack/common";
|
||||
|
||||
let style: HTMLStyleElement;
|
||||
|
||||
@ -101,11 +101,5 @@ export default definePlugin({
|
||||
|
||||
await saveHiddenMessages(ids);
|
||||
await this.buildCss();
|
||||
|
||||
// update is necessary to rerender the PopOver
|
||||
FluxDispatcher.dispatch({
|
||||
type: "MESSAGE_UPDATE",
|
||||
message: { id }
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -225,6 +225,8 @@ function MessageEmbedAccessory({ message }: { message: Message; }) {
|
||||
} else {
|
||||
const msg = { ...message } as any;
|
||||
delete msg.embeds;
|
||||
delete msg.interaction;
|
||||
|
||||
messageFetchQueue.push(() => fetchMessage(channelID, messageID)
|
||||
.then(m => m && FluxDispatcher.dispatch({
|
||||
type: "MESSAGE_UPDATE",
|
||||
|
@ -17,10 +17,11 @@
|
||||
*/
|
||||
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import ExpandableHeader from "@components/ExpandableHeader";
|
||||
import { proxyLazy } from "@utils/lazy";
|
||||
import { classes } from "@utils/misc";
|
||||
import { filters, findBulk } from "@webpack";
|
||||
import { i18n, PermissionsBits, Text, Tooltip, useMemo, UserStore, useState } from "@webpack/common";
|
||||
import { i18n, PermissionsBits, Text, Tooltip, useMemo, UserStore } from "@webpack/common";
|
||||
import type { Guild, GuildMember } from "discord-types/general";
|
||||
|
||||
import { PermissionsSortOrder, settings } from "..";
|
||||
@ -47,7 +48,6 @@ const Classes = proxyLazy(() => {
|
||||
|
||||
function UserPermissionsComponent({ guild, guildMember }: { guild: Guild; guildMember: GuildMember; }) {
|
||||
const stns = settings.use(["permissionsSortOrder"]);
|
||||
const [viewPermissions, setViewPermissions] = useState(settings.store.defaultPermissionsDropdownState);
|
||||
|
||||
const [rolePermissions, userPermissions] = useMemo(() => {
|
||||
const userPermissions: UserPermissions = [];
|
||||
@ -97,12 +97,19 @@ function UserPermissionsComponent({ guild, guildMember }: { guild: Guild; guildM
|
||||
const { root, role, roleRemoveButton, roleNameOverflow, roles, rolePill, rolePillBorder, roleCircle, roleName } = Classes;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className={cl("userperms-title-container")}>
|
||||
<Text className={cl("userperms-title")} variant="eyebrow">Permissions</Text>
|
||||
|
||||
<div className={cl("userperms-btns-container")}>
|
||||
<Tooltip text={`Sorting by ${stns.permissionsSortOrder === PermissionsSortOrder.HighestRole ? "Highest Role" : "Lowest Role"}`}>
|
||||
<ExpandableHeader
|
||||
headerText="Permissions"
|
||||
moreTooltipText="Role Details"
|
||||
onMoreClick={() =>
|
||||
openRolesAndUsersPermissionsModal(
|
||||
rolePermissions,
|
||||
guild,
|
||||
guildMember.nick || UserStore.getUser(guildMember.userId).username
|
||||
)
|
||||
}
|
||||
defaultState={settings.store.defaultPermissionsDropdownState}
|
||||
buttons={[
|
||||
(<Tooltip text={`Sorting by ${stns.permissionsSortOrder === PermissionsSortOrder.HighestRole ? "Highest Role" : "Lowest Role"}`}>
|
||||
{tooltipProps => (
|
||||
<button
|
||||
{...tooltipProps}
|
||||
@ -121,54 +128,9 @@ function UserPermissionsComponent({ guild, guildMember }: { guild: Guild; guildM
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip text="Role Details">
|
||||
{tooltipProps => (
|
||||
<button
|
||||
{...tooltipProps}
|
||||
className={cl("userperms-permdetails-btn")}
|
||||
onClick={() =>
|
||||
openRolesAndUsersPermissionsModal(
|
||||
rolePermissions,
|
||||
guild,
|
||||
guildMember.nick || UserStore.getUser(guildMember.userId).username
|
||||
)
|
||||
}
|
||||
>
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path fill="var(--text-normal)" d="M7 12.001C7 10.8964 6.10457 10.001 5 10.001C3.89543 10.001 3 10.8964 3 12.001C3 13.1055 3.89543 14.001 5 14.001C6.10457 14.001 7 13.1055 7 12.001ZM14 12.001C14 10.8964 13.1046 10.001 12 10.001C10.8954 10.001 10 10.8964 10 12.001C10 13.1055 10.8954 14.001 12 14.001C13.1046 14.001 14 13.1055 14 12.001ZM19 10.001C20.1046 10.001 21 10.8964 21 12.001C21 13.1055 20.1046 14.001 19 14.001C17.8954 14.001 17 13.1055 17 12.001C17 10.8964 17.8954 10.001 19 10.001Z" />
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip text={viewPermissions ? "Hide Permissions" : "View Permissions"}>
|
||||
{tooltipProps => (
|
||||
<button
|
||||
{...tooltipProps}
|
||||
className={cl("userperms-toggleperms-btn")}
|
||||
onClick={() => setViewPermissions(v => !v)}
|
||||
>
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
transform={viewPermissions ? "scale(1 -1)" : "scale(1 1)"}
|
||||
>
|
||||
<path fill="var(--text-normal)" d="M16.59 8.59003L12 13.17L7.41 8.59003L6 10L12 16L18 10L16.59 8.59003Z" />
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{viewPermissions && userPermissions.length > 0 && (
|
||||
</Tooltip>)
|
||||
]}>
|
||||
{userPermissions.length > 0 && (
|
||||
<div className={classes(root, roles)}>
|
||||
{userPermissions.map(({ permission, roleColor }) => (
|
||||
<div className={classes(role, rolePill, rolePillBorder)}>
|
||||
@ -190,7 +152,7 @@ function UserPermissionsComponent({ guild, guildMember }: { guild: Guild; guildM
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ExpandableHeader>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -17,28 +17,44 @@
|
||||
*/
|
||||
|
||||
import { classes } from "@utils/misc";
|
||||
import { LazyComponent } from "@utils/react";
|
||||
import { findByProps } from "@webpack";
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
import { Tooltip } from "@webpack/common";
|
||||
|
||||
export default LazyComponent(() => {
|
||||
const { button, dangerous } = findByProps("button", "wrapper", "disabled", "separator");
|
||||
const iconClasses = findByPropsLazy("button", "wrapper", "disabled", "separator");
|
||||
|
||||
return function MessageButton(props) {
|
||||
return props.type === "delete"
|
||||
? (
|
||||
<div className={classes(button, dangerous)} aria-label="Delete Review" onClick={props.callback}>
|
||||
<svg aria-hidden="false" width="16" height="16" viewBox="0 0 20 20">
|
||||
<path fill="currentColor" d="M15 3.999V2H9V3.999H3V5.999H21V3.999H15Z"></path>
|
||||
<path fill="currentColor" d="M5 6.99902V18.999C5 20.101 5.897 20.999 7 20.999H17C18.103 20.999 19 20.101 19 18.999V6.99902H5ZM11 17H9V11H11V17ZM15 17H13V11H15V17Z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
)
|
||||
: (
|
||||
<div className={button} aria-label="Report Review" onClick={() => props.callback()}>
|
||||
<svg aria-hidden="false" width="16" height="16" viewBox="0 0 20 20">
|
||||
<path fill="currentColor" d="M20,6.002H14V3.002C14,2.45 13.553,2.002 13,2.002H4C3.447,2.002 3,2.45 3,3.002V22.002H5V14.002H10.586L8.293,16.295C8.007,16.581 7.922,17.011 8.076,17.385C8.23,17.759 8.596,18.002 9,18.002H20C20.553,18.002 21,17.554 21,17.002V7.002C21,6.45 20.553,6.002 20,6.002Z"></path>
|
||||
export function DeleteButton({ onClick }: { onClick(): void; }) {
|
||||
return (
|
||||
<Tooltip text="Delete Review">
|
||||
{props => (
|
||||
<div
|
||||
{...props}
|
||||
className={classes(iconClasses.button, iconClasses.dangerous)}
|
||||
onClick={onClick}
|
||||
>
|
||||
<svg width="16" height="16" viewBox="0 0 20 20">
|
||||
<path fill="currentColor" d="M15 3.999V2H9V3.999H3V5.999H21V3.999H15Z" />
|
||||
<path fill="currentColor" d="M5 6.99902V18.999C5 20.101 5.897 20.999 7 20.999H17C18.103 20.999 19 20.101 19 18.999V6.99902H5ZM11 17H9V11H11V17ZM15 17H13V11H15V17Z" />
|
||||
</svg>
|
||||
</div>
|
||||
)}
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function ReportButton({ onClick }: { onClick(): void; }) {
|
||||
return (
|
||||
<Tooltip text="Report Review">
|
||||
{props => (
|
||||
<div
|
||||
{...props}
|
||||
className={iconClasses.button}
|
||||
onClick={onClick}
|
||||
>
|
||||
<svg width="16" height="16" viewBox="0 0 20 20">
|
||||
<path fill="currentColor" d="M20,6.002H14V3.002C14,2.45 13.553,2.002 13,2.002H4C3.447,2.002 3,2.45 3,3.002V22.002H5V14.002H10.586L8.293,16.295C8.007,16.581 7.922,17.011 8.076,17.385C8.23,17.759 8.596,18.002 9,18.002H20C20.553,18.002 21,17.554 21,17.002V7.002C21,6.45 20.553,6.002 20,6.002Z" />
|
||||
</svg>
|
||||
</div>
|
||||
)}
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
@ -18,7 +18,8 @@
|
||||
|
||||
import { MaskedLinkStore, Tooltip } from "@webpack/common";
|
||||
|
||||
import { Badge } from "../entities/Badge";
|
||||
import { Badge } from "../entities";
|
||||
import { cl } from "../utils";
|
||||
|
||||
export default function ReviewBadge(badge: Badge) {
|
||||
return (
|
||||
@ -26,13 +27,13 @@ export default function ReviewBadge(badge: Badge) {
|
||||
text={badge.name}>
|
||||
{({ onMouseEnter, onMouseLeave }) => (
|
||||
<img
|
||||
className={cl("badge")}
|
||||
width="24px"
|
||||
height="24px"
|
||||
onMouseEnter={onMouseEnter}
|
||||
onMouseLeave={onMouseLeave}
|
||||
src={badge.icon}
|
||||
alt={badge.description}
|
||||
style={{ verticalAlign: "middle", marginLeft: "4px" }}
|
||||
onClick={() =>
|
||||
MaskedLinkStore.openUntrustedLink({
|
||||
href: badge.redirectURL,
|
||||
|
@ -16,16 +16,16 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Settings } from "@api/Settings";
|
||||
import { classes } from "@utils/misc";
|
||||
import { LazyComponent } from "@utils/react";
|
||||
import { filters, findBulk } from "@webpack";
|
||||
import { Alerts, moment, Timestamp, UserStore } from "@webpack/common";
|
||||
|
||||
import { Review } from "../entities/Review";
|
||||
import { deleteReview, reportReview } from "../Utils/ReviewDBAPI";
|
||||
import { canDeleteReview, openUserProfileModal, showToast } from "../Utils/Utils";
|
||||
import MessageButton from "./MessageButton";
|
||||
import { Review, ReviewType } from "../entities";
|
||||
import { deleteReview, reportReview } from "../reviewDbApi";
|
||||
import { settings } from "../settings";
|
||||
import { canDeleteReview, cl, openUserProfileModal, showToast } from "../utils";
|
||||
import { DeleteButton, ReportButton } from "./MessageButton";
|
||||
import ReviewBadge from "./ReviewBadge";
|
||||
|
||||
export default LazyComponent(() => {
|
||||
@ -36,11 +36,13 @@ export default LazyComponent(() => {
|
||||
{ container, isHeader },
|
||||
{ avatar, clickable, username, messageContent, wrapper, cozy },
|
||||
buttonClasses,
|
||||
botTag
|
||||
] = findBulk(
|
||||
p("cozyMessage"),
|
||||
p("container", "isHeader"),
|
||||
p("avatar", "zalgo"),
|
||||
p("button", "wrapper", "selected"),
|
||||
p("botTag")
|
||||
);
|
||||
|
||||
const dateFormat = new Intl.DateTimeFormat();
|
||||
@ -79,21 +81,21 @@ export default LazyComponent(() => {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={classes(cozyMessage, wrapper, message, groupStart, cozy, "user-review")} style={
|
||||
<div className={classes(cozyMessage, wrapper, message, groupStart, cozy, cl("review"))} style={
|
||||
{
|
||||
marginLeft: "0px",
|
||||
paddingLeft: "52px",
|
||||
paddingLeft: "52px", // wth is this
|
||||
paddingRight: "16px"
|
||||
}
|
||||
}>
|
||||
|
||||
<div>
|
||||
<img
|
||||
className={classes(avatar, clickable)}
|
||||
onClick={openModal}
|
||||
src={review.sender.profilePhoto || "/assets/1f0bfc0865d324c2587920a7d80c609b.png?size=128"}
|
||||
style={{ left: "0px" }}
|
||||
/>
|
||||
<div style={{ display: "inline-flex", justifyContent: "center", alignItems: "center" }}>
|
||||
<span
|
||||
className={classes(clickable, username)}
|
||||
style={{ color: "var(--channels-default)", fontSize: "14px" }}
|
||||
@ -101,10 +103,21 @@ export default LazyComponent(() => {
|
||||
>
|
||||
{review.sender.username}
|
||||
</span>
|
||||
|
||||
{review.type === ReviewType.System && (
|
||||
<span
|
||||
className={classes(botTag.botTagVerified, botTag.botTagRegular, botTag.botTag, botTag.px, botTag.rem)}
|
||||
style={{ marginLeft: "4px" }}>
|
||||
<span className={botTag.botText}>
|
||||
System
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{review.sender.badges.map(badge => <ReviewBadge {...badge} />)}
|
||||
|
||||
{
|
||||
!Settings.plugins.ReviewDB.hideTimestamps && (
|
||||
!settings.store.hideTimestamps && review.type !== ReviewType.System && (
|
||||
<Timestamp timestamp={moment(review.timestamp * 1000)} >
|
||||
{dateFormat.format(review.timestamp * 1000)}
|
||||
</Timestamp>)
|
||||
@ -116,17 +129,19 @@ export default LazyComponent(() => {
|
||||
>
|
||||
{review.comment}
|
||||
</p>
|
||||
{review.id !== 0 && (
|
||||
<div className={classes(container, isHeader, buttons)} style={{
|
||||
padding: "0px",
|
||||
}}>
|
||||
<div className={buttonClasses.wrapper} >
|
||||
<MessageButton type="report" callback={reportRev} />
|
||||
<ReportButton onClick={reportRev} />
|
||||
|
||||
{canDeleteReview(review, UserStore.getCurrentUser().id) && (
|
||||
<MessageButton type="delete" callback={delReview} />
|
||||
<DeleteButton onClick={delReview} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
104
src/plugins/reviewDB/components/ReviewModal.tsx
Normal file
104
src/plugins/reviewDB/components/ReviewModal.tsx
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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 ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
||||
import { useForceUpdater } from "@utils/react";
|
||||
import { Paginator, Text, useRef, useState } from "@webpack/common";
|
||||
|
||||
import { Response, REVIEWS_PER_PAGE } from "../reviewDbApi";
|
||||
import { settings } from "../settings";
|
||||
import { cl } from "../utils";
|
||||
import ReviewComponent from "./ReviewComponent";
|
||||
import ReviewsView, { ReviewsInputComponent } from "./ReviewsView";
|
||||
|
||||
function Modal({ modalProps, discordId, name }: { modalProps: any; discordId: string; name: string; }) {
|
||||
const [data, setData] = useState<Response>();
|
||||
const [signal, refetch] = useForceUpdater(true);
|
||||
const [page, setPage] = useState(1);
|
||||
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
|
||||
const reviewCount = data?.reviewCount;
|
||||
const ownReview = data?.reviews.find(r => r.sender.discordID === settings.store.user?.discordID);
|
||||
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<ModalRoot {...modalProps} size={ModalSize.MEDIUM}>
|
||||
<ModalHeader>
|
||||
<Text variant="heading-lg/semibold" className={cl("modal-header")}>
|
||||
{name}'s Reviews
|
||||
{!!reviewCount && <span> ({reviewCount} Reviews)</span>}
|
||||
</Text>
|
||||
<ModalCloseButton onClick={modalProps.onClose} />
|
||||
</ModalHeader>
|
||||
|
||||
<ModalContent scrollerRef={ref}>
|
||||
<div className={cl("modal-reviews")}>
|
||||
<ReviewsView
|
||||
discordId={discordId}
|
||||
name={name}
|
||||
page={page}
|
||||
refetchSignal={signal}
|
||||
onFetchReviews={setData}
|
||||
scrollToTop={() => ref.current?.scrollTo({ top: 0, behavior: "smooth" })}
|
||||
hideOwnReview
|
||||
/>
|
||||
</div>
|
||||
</ModalContent>
|
||||
|
||||
<ModalFooter className={cl("modal-footer")}>
|
||||
<div>
|
||||
{ownReview && (
|
||||
<ReviewComponent
|
||||
refetch={refetch}
|
||||
review={ownReview}
|
||||
/>
|
||||
)}
|
||||
<ReviewsInputComponent
|
||||
isAuthor={ownReview != null}
|
||||
discordId={discordId}
|
||||
name={name}
|
||||
refetch={refetch}
|
||||
/>
|
||||
|
||||
{!!reviewCount && (
|
||||
<Paginator
|
||||
currentPage={page}
|
||||
maxVisiblePages={5}
|
||||
pageSize={REVIEWS_PER_PAGE}
|
||||
totalCount={reviewCount}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</ModalFooter>
|
||||
</ModalRoot>
|
||||
</ErrorBoundary>
|
||||
);
|
||||
}
|
||||
|
||||
export function openReviewsModal(discordId: string, name: string) {
|
||||
openModal(props => (
|
||||
<Modal
|
||||
modalProps={props}
|
||||
discordId={discordId}
|
||||
name={name}
|
||||
/>
|
||||
));
|
||||
}
|
@ -16,42 +16,113 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Settings } from "@api/Settings";
|
||||
import { classes } from "@utils/misc";
|
||||
import { useAwaiter } from "@utils/react";
|
||||
import { useAwaiter, useForceUpdater } from "@utils/react";
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
import { Forms, React, Text, UserStore } from "@webpack/common";
|
||||
import { Forms, React, UserStore } from "@webpack/common";
|
||||
import type { KeyboardEvent } from "react";
|
||||
|
||||
import { addReview, getReviews } from "../Utils/ReviewDBAPI";
|
||||
import { authorize, showToast } from "../Utils/Utils";
|
||||
import { Review } from "../entities";
|
||||
import { addReview, getReviews, Response, REVIEWS_PER_PAGE } from "../reviewDbApi";
|
||||
import { settings } from "../settings";
|
||||
import { authorize, cl, showToast } from "../utils";
|
||||
import ReviewComponent from "./ReviewComponent";
|
||||
|
||||
const Classes = findByPropsLazy("inputDefault", "editable");
|
||||
|
||||
export default function ReviewsView({ userId }: { userId: string; }) {
|
||||
const { token } = Settings.plugins.ReviewDB;
|
||||
const [refetchCount, setRefetchCount] = React.useState(0);
|
||||
const [reviews, _, isLoading] = useAwaiter(() => getReviews(userId), {
|
||||
fallbackValue: [],
|
||||
deps: [refetchCount],
|
||||
interface UserProps {
|
||||
discordId: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Props extends UserProps {
|
||||
onFetchReviews(data: Response): void;
|
||||
refetchSignal?: unknown;
|
||||
showInput?: boolean;
|
||||
page?: number;
|
||||
scrollToTop?(): void;
|
||||
hideOwnReview?: boolean;
|
||||
}
|
||||
|
||||
export default function ReviewsView({
|
||||
discordId,
|
||||
name,
|
||||
onFetchReviews,
|
||||
refetchSignal,
|
||||
scrollToTop,
|
||||
page = 1,
|
||||
showInput = false,
|
||||
hideOwnReview = false,
|
||||
}: Props) {
|
||||
const [signal, refetch] = useForceUpdater(true);
|
||||
|
||||
const [reviewData] = useAwaiter(() => getReviews(discordId, (page - 1) * REVIEWS_PER_PAGE), {
|
||||
fallbackValue: null,
|
||||
deps: [refetchSignal, signal, page],
|
||||
onSuccess: data => {
|
||||
scrollToTop?.();
|
||||
onFetchReviews(data!);
|
||||
}
|
||||
});
|
||||
const username = UserStore.getUser(userId)?.username ?? "";
|
||||
|
||||
const dirtyRefetch = () => setRefetchCount(refetchCount + 1);
|
||||
if (!reviewData) return null;
|
||||
|
||||
if (isLoading) return null;
|
||||
return (
|
||||
<>
|
||||
<ReviewList
|
||||
refetch={refetch}
|
||||
reviews={reviewData!.reviews}
|
||||
hideOwnReview={hideOwnReview}
|
||||
/>
|
||||
|
||||
{showInput && (
|
||||
<ReviewsInputComponent
|
||||
name={name}
|
||||
discordId={discordId}
|
||||
refetch={refetch}
|
||||
isAuthor={reviewData!.reviews?.some(r => r.sender.discordID === UserStore.getCurrentUser().id)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ReviewList({ refetch, reviews, hideOwnReview }: { refetch(): void; reviews: Review[]; hideOwnReview: boolean; }) {
|
||||
const myId = UserStore.getCurrentUser().id;
|
||||
|
||||
return (
|
||||
<div className={cl("view")}>
|
||||
{reviews?.map(review =>
|
||||
(review.sender.discordID !== myId || !hideOwnReview) &&
|
||||
<ReviewComponent
|
||||
key={review.id}
|
||||
review={review}
|
||||
refetch={refetch}
|
||||
/>
|
||||
)}
|
||||
|
||||
{reviews?.length === 0 && (
|
||||
<Forms.FormText className={cl("placeholder")}>
|
||||
Looks like nobody reviewed this user yet. You could be the first!
|
||||
</Forms.FormText>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ReviewsInputComponent({ discordId, isAuthor, refetch, name }: { discordId: string, name: string; isAuthor: boolean; refetch(): void; }) {
|
||||
const { token } = settings.store;
|
||||
|
||||
function onKeyPress({ key, target }: KeyboardEvent<HTMLTextAreaElement>) {
|
||||
if (key === "Enter") {
|
||||
addReview({
|
||||
userid: userId,
|
||||
userid: discordId,
|
||||
comment: (target as HTMLInputElement).value,
|
||||
star: -1
|
||||
}).then(res => {
|
||||
if (res?.success) {
|
||||
(target as HTMLInputElement).value = ""; // clear the input
|
||||
dirtyRefetch();
|
||||
refetch();
|
||||
} else if (res?.message) {
|
||||
showToast(res.message);
|
||||
}
|
||||
@ -60,42 +131,19 @@ export default function ReviewsView({ userId }: { userId: string; }) {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="vc-reviewdb-view">
|
||||
<Text
|
||||
tag="h2"
|
||||
variant="eyebrow"
|
||||
style={{
|
||||
marginBottom: "8px",
|
||||
color: "var(--header-primary)"
|
||||
}}
|
||||
>
|
||||
User Reviews
|
||||
</Text>
|
||||
{reviews?.map(review =>
|
||||
<ReviewComponent
|
||||
key={review.id}
|
||||
review={review}
|
||||
refetch={dirtyRefetch}
|
||||
/>
|
||||
)}
|
||||
{reviews?.length === 0 && (
|
||||
<Forms.FormText style={{ paddingRight: "12px", paddingTop: "0px", paddingLeft: "0px", paddingBottom: "4px", fontWeight: "bold", fontStyle: "italic" }}>
|
||||
Looks like nobody reviewed this user yet. You could be the first!
|
||||
</Forms.FormText>
|
||||
)}
|
||||
<textarea
|
||||
className={classes(Classes.inputDefault, "enter-comment")}
|
||||
className={classes(Classes.inputDefault, "enter-comment", cl("input"))}
|
||||
onKeyDownCapture={e => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault(); // prevent newlines
|
||||
}
|
||||
}}
|
||||
placeholder={
|
||||
token
|
||||
? (reviews?.some(r => r.sender.discordID === UserStore.getCurrentUser().id)
|
||||
? `Update review for @${username}`
|
||||
: `Review @${username}`)
|
||||
: "You need to authorize to review users!"
|
||||
!token
|
||||
? "You need to authorize to review users!"
|
||||
: isAuthor
|
||||
? `Update review for @${name}`
|
||||
: `Review @${name}`
|
||||
}
|
||||
onKeyDown={onKeyPress}
|
||||
onClick={() => {
|
||||
@ -104,17 +152,6 @@ export default function ReviewsView({ userId }: { userId: string; }) {
|
||||
authorize();
|
||||
}
|
||||
}}
|
||||
|
||||
style={{
|
||||
marginTop: "6px",
|
||||
resize: "none",
|
||||
marginBottom: "12px",
|
||||
overflow: "hidden",
|
||||
background: "transparent",
|
||||
border: "1px solid var(--profile-message-input-border-color)",
|
||||
fontSize: "14px",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -22,23 +22,55 @@ export const enum UserType {
|
||||
Admin = 1
|
||||
}
|
||||
|
||||
export const enum ReviewType {
|
||||
User = 0,
|
||||
Server = 1,
|
||||
Support = 2,
|
||||
System = 3
|
||||
}
|
||||
|
||||
export interface Badge {
|
||||
name: string;
|
||||
description: string;
|
||||
icon: string;
|
||||
redirectURL: string;
|
||||
type: number;
|
||||
}
|
||||
|
||||
export interface BanInfo {
|
||||
id: string;
|
||||
discordID: string;
|
||||
reviewID: number;
|
||||
reviewContent: string;
|
||||
banEndDate: string;
|
||||
banEndDate: number;
|
||||
}
|
||||
|
||||
export interface ReviewDBUser {
|
||||
ID: number
|
||||
discordID: string
|
||||
username: string
|
||||
profilePhoto: string
|
||||
clientMod: string
|
||||
warningCount: number
|
||||
badges: any[]
|
||||
banInfo: BanInfo | null
|
||||
lastReviewID: number
|
||||
type: UserType
|
||||
ID: number;
|
||||
discordID: string;
|
||||
username: string;
|
||||
profilePhoto: string;
|
||||
clientMod: string;
|
||||
warningCount: number;
|
||||
badges: any[];
|
||||
banInfo: BanInfo | null;
|
||||
lastReviewID: number;
|
||||
type: UserType;
|
||||
}
|
||||
|
||||
export interface ReviewAuthor {
|
||||
id: number,
|
||||
discordID: string,
|
||||
username: string,
|
||||
profilePhoto: string,
|
||||
badges: Badge[];
|
||||
}
|
||||
|
||||
export interface Review {
|
||||
comment: string,
|
||||
id: number,
|
||||
star: number,
|
||||
sender: ReviewAuthor,
|
||||
timestamp: number;
|
||||
type?: ReviewType;
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2022 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/>.
|
||||
*/
|
||||
|
||||
|
||||
export interface Badge {
|
||||
name: string;
|
||||
description: string;
|
||||
icon: string;
|
||||
redirectURL : string;
|
||||
type: number;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2022 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 { Badge } from "./Badge";
|
||||
|
||||
export interface Sender {
|
||||
id : number,
|
||||
discordID: string,
|
||||
username: string,
|
||||
profilePhoto: string,
|
||||
badges: Badge[]
|
||||
}
|
||||
|
||||
export interface Review {
|
||||
comment: string,
|
||||
id: number,
|
||||
star: number,
|
||||
sender: Sender,
|
||||
timestamp: number
|
||||
}
|
@ -18,23 +18,40 @@
|
||||
|
||||
import "./style.css";
|
||||
|
||||
import { Settings } from "@api/Settings";
|
||||
import { addContextMenuPatch, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import ExpandableHeader from "@components/ExpandableHeader";
|
||||
import { OpenExternalIcon } from "@components/Icons";
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { Alerts, Button } from "@webpack/common";
|
||||
import { User } from "discord-types/general";
|
||||
import definePlugin from "@utils/types";
|
||||
import { Alerts, Menu, useState } from "@webpack/common";
|
||||
import { Guild, User } from "discord-types/general";
|
||||
|
||||
import { openReviewsModal } from "./components/ReviewModal";
|
||||
import ReviewsView from "./components/ReviewsView";
|
||||
import { UserType } from "./entities/User";
|
||||
import { getCurrentUserInfo } from "./Utils/ReviewDBAPI";
|
||||
import { authorize, showToast } from "./Utils/Utils";
|
||||
import { UserType } from "./entities";
|
||||
import { getCurrentUserInfo } from "./reviewDbApi";
|
||||
import { settings } from "./settings";
|
||||
import { showToast } from "./utils";
|
||||
|
||||
const guildPopoutPatch: NavContextMenuPatchCallback = (children, props: { guild: Guild, onClose(): void; }) => () => {
|
||||
children.push(
|
||||
<Menu.MenuItem
|
||||
label="View Reviews"
|
||||
id="vc-rdb-server-reviews"
|
||||
icon={OpenExternalIcon}
|
||||
action={() => openReviewsModal(props.guild.id, props.guild.name)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default definePlugin({
|
||||
name: "ReviewDB",
|
||||
description: "Review other users (Adds a new settings to profiles)",
|
||||
authors: [Devs.mantikafasi, Devs.Ven],
|
||||
|
||||
settings,
|
||||
|
||||
patches: [
|
||||
{
|
||||
find: "disableBorderColor:!0",
|
||||
@ -45,100 +62,86 @@ export default definePlugin({
|
||||
}
|
||||
],
|
||||
|
||||
options: {
|
||||
authorize: {
|
||||
type: OptionType.COMPONENT,
|
||||
description: "Authorize with ReviewDB",
|
||||
component: () => (
|
||||
<Button onClick={authorize}>
|
||||
Authorize with ReviewDB
|
||||
</Button>
|
||||
)
|
||||
},
|
||||
notifyReviews: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Notify about new reviews on startup",
|
||||
default: true,
|
||||
},
|
||||
showWarning: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Display warning to be respectful at the top of the reviews list",
|
||||
default: true,
|
||||
},
|
||||
hideTimestamps: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Hide timestamps on reviews",
|
||||
default: false,
|
||||
},
|
||||
website: {
|
||||
type: OptionType.COMPONENT,
|
||||
description: "ReviewDB website",
|
||||
component: () => (
|
||||
<Button onClick={() => {
|
||||
window.open("https://reviewdb.mantikafasi.dev");
|
||||
}}>
|
||||
ReviewDB website
|
||||
</Button>
|
||||
)
|
||||
},
|
||||
supportServer: {
|
||||
type: OptionType.COMPONENT,
|
||||
description: "ReviewDB Support Server",
|
||||
component: () => (
|
||||
<Button onClick={() => {
|
||||
window.open("https://discord.gg/eWPBSbvznt");
|
||||
}}>
|
||||
ReviewDB Support Server
|
||||
</Button>
|
||||
)
|
||||
},
|
||||
},
|
||||
|
||||
async start() {
|
||||
const settings = Settings.plugins.ReviewDB;
|
||||
if (!settings.notifyReviews || !settings.token) return;
|
||||
const s = settings.store;
|
||||
const { token, lastReviewId, notifyReviews } = s;
|
||||
|
||||
if (!notifyReviews || !token) return;
|
||||
|
||||
setTimeout(async () => {
|
||||
const user = await getCurrentUserInfo(settings.token);
|
||||
if (settings.lastReviewId < user.lastReviewID) {
|
||||
settings.lastReviewId = user.lastReviewID;
|
||||
const user = await getCurrentUserInfo(token);
|
||||
if (lastReviewId && lastReviewId < user.lastReviewID) {
|
||||
s.lastReviewId = user.lastReviewID;
|
||||
if (user.lastReviewID !== 0)
|
||||
showToast("You have new reviews on your profile!");
|
||||
}
|
||||
|
||||
if (user.banInfo) {
|
||||
const endDate = new Date(user.banInfo.banEndDate);
|
||||
if (endDate > new Date() && (settings.user?.banInfo?.banEndDate ?? 0) < endDate) {
|
||||
addContextMenuPatch("guild-header-popout", guildPopoutPatch);
|
||||
|
||||
if (user.banInfo) {
|
||||
const endDate = new Date(user.banInfo.banEndDate).getTime();
|
||||
if (endDate > Date.now() && (s.user?.banInfo?.banEndDate ?? 0) < endDate) {
|
||||
Alerts.show({
|
||||
title: "You have been banned from ReviewDB",
|
||||
body: <>
|
||||
body: (
|
||||
<>
|
||||
<p>
|
||||
You are banned from ReviewDB {(user.type === UserType.Banned) ? "permanently" : "until " + endDate.toLocaleString()}
|
||||
You are banned from ReviewDB {
|
||||
user.type === UserType.Banned
|
||||
? "permanently"
|
||||
: "until " + endDate.toLocaleString()
|
||||
}
|
||||
</p>
|
||||
<p>
|
||||
Offending Review: {user.banInfo.reviewContent}
|
||||
</p>
|
||||
<p>
|
||||
Continued offenses will result in a permanent ban.
|
||||
</p>
|
||||
</>,
|
||||
{user.banInfo.reviewContent && (
|
||||
<p>Offending Review: {user.banInfo.reviewContent}</p>
|
||||
)}
|
||||
<p>Continued offenses will result in a permanent ban.</p>
|
||||
</>
|
||||
),
|
||||
cancelText: "Appeal",
|
||||
confirmText: "Ok",
|
||||
onCancel: () => {
|
||||
window.open("https://forms.gle/Thj3rDYaMdKoMMuq6");
|
||||
}
|
||||
onCancel: () =>
|
||||
VencordNative.native.openExternal(
|
||||
"https://reviewdb.mantikafasi.dev/api/redirect?"
|
||||
+ new URLSearchParams({
|
||||
token: settings.store.token!,
|
||||
page: "dashboard/appeal"
|
||||
})
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
settings.user = user;
|
||||
s.user = user;
|
||||
}, 4000);
|
||||
},
|
||||
|
||||
getReviewsComponent: (user: User) => (
|
||||
<ErrorBoundary message="Failed to render Reviews">
|
||||
<ReviewsView userId={user.id} />
|
||||
</ErrorBoundary>
|
||||
)
|
||||
stop() {
|
||||
removeContextMenuPatch("guild-header-popout", guildPopoutPatch);
|
||||
},
|
||||
|
||||
getReviewsComponent: ErrorBoundary.wrap((user: User) => {
|
||||
const [reviewCount, setReviewCount] = useState<number>();
|
||||
|
||||
return (
|
||||
<ExpandableHeader
|
||||
headerText="User Reviews"
|
||||
onMoreClick={() => openReviewsModal(user.id, user.username)}
|
||||
moreTooltipText={
|
||||
reviewCount && reviewCount > 50
|
||||
? `View all ${reviewCount} reviews`
|
||||
: "Open Review Modal"
|
||||
}
|
||||
onDropDownClick={state => settings.store.reviewsDropdownState = !state}
|
||||
defaultState={settings.store.reviewsDropdownState}
|
||||
>
|
||||
<ReviewsView
|
||||
discordId={user.id}
|
||||
name={user.username}
|
||||
onFetchReviews={r => setReviewCount(r.reviewCount)}
|
||||
showInput
|
||||
/>
|
||||
</ExpandableHeader>
|
||||
);
|
||||
}, { message: "Failed to render Reviews" })
|
||||
});
|
||||
|
@ -16,34 +16,52 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Settings } from "@api/Settings";
|
||||
|
||||
import { Review } from "../entities/Review";
|
||||
import { ReviewDBUser } from "../entities/User";
|
||||
import { authorize, showToast } from "./Utils";
|
||||
import { Review, ReviewDBUser } from "./entities";
|
||||
import { settings } from "./settings";
|
||||
import { authorize, showToast } from "./utils";
|
||||
|
||||
const API_URL = "https://manti.vendicated.dev";
|
||||
|
||||
const getToken = () => Settings.plugins.ReviewDB.token;
|
||||
export const REVIEWS_PER_PAGE = 50;
|
||||
|
||||
interface Response {
|
||||
export interface Response {
|
||||
success: boolean,
|
||||
message: string;
|
||||
reviews: Review[];
|
||||
updated: boolean;
|
||||
hasNextPage: boolean;
|
||||
reviewCount: number;
|
||||
}
|
||||
|
||||
const WarningFlag = 0b00000010;
|
||||
|
||||
export async function getReviews(id: string): Promise<Review[]> {
|
||||
var flags = 0;
|
||||
if (!Settings.plugins.ReviewDB.showWarning) flags |= WarningFlag;
|
||||
const req = await fetch(API_URL + `/api/reviewdb/users/${id}/reviews?flags=${flags}`);
|
||||
export async function getReviews(id: string, offset = 0): Promise<Response> {
|
||||
let flags = 0;
|
||||
if (!settings.store.showWarning) flags |= WarningFlag;
|
||||
|
||||
const params = new URLSearchParams({
|
||||
flags: String(flags),
|
||||
offset: String(offset)
|
||||
});
|
||||
const req = await fetch(`${API_URL}/api/reviewdb/users/${id}/reviews?${params}`);
|
||||
|
||||
const res = (req.status === 200)
|
||||
? await req.json() as Response
|
||||
: {
|
||||
success: false,
|
||||
message: "An Error occured while fetching reviews. Please try again later.",
|
||||
reviews: [],
|
||||
updated: false,
|
||||
hasNextPage: false,
|
||||
reviewCount: 0
|
||||
};
|
||||
|
||||
const res = (req.status === 200) ? await req.json() as Response : { success: false, message: "An Error occured while fetching reviews. Please try again later.", reviews: [], updated: false };
|
||||
if (!res.success) {
|
||||
showToast(res.message);
|
||||
return [
|
||||
return {
|
||||
...res,
|
||||
reviews: [
|
||||
{
|
||||
id: 0,
|
||||
comment: "An Error occured while fetching reviews. Please try again later.",
|
||||
@ -57,13 +75,15 @@ export async function getReviews(id: string): Promise<Review[]> {
|
||||
badges: []
|
||||
}
|
||||
}
|
||||
];
|
||||
]
|
||||
};
|
||||
}
|
||||
return res.reviews;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function addReview(review: any): Promise<Response | null> {
|
||||
review.token = getToken();
|
||||
review.token = settings.store.token;
|
||||
|
||||
if (!review.token) {
|
||||
showToast("Please authorize to add a review.");
|
||||
@ -93,7 +113,7 @@ export function deleteReview(id: number): Promise<Response> {
|
||||
Accept: "application/json",
|
||||
}),
|
||||
body: JSON.stringify({
|
||||
token: getToken(),
|
||||
token: settings.store.token,
|
||||
reviewid: id
|
||||
})
|
||||
}).then(r => r.json());
|
||||
@ -108,16 +128,16 @@ export async function reportReview(id: number) {
|
||||
}),
|
||||
body: JSON.stringify({
|
||||
reviewid: id,
|
||||
token: getToken()
|
||||
token: settings.store.token
|
||||
})
|
||||
}).then(r => r.json()) as Response;
|
||||
showToast(await res.message);
|
||||
|
||||
showToast(res.message);
|
||||
}
|
||||
|
||||
export function getCurrentUserInfo(token: string): Promise<ReviewDBUser> {
|
||||
return fetch(API_URL + "/api/reviewdb/users", {
|
||||
body: JSON.stringify({ token }),
|
||||
method: "POST",
|
||||
})
|
||||
.then(r => r.json());
|
||||
}).then(r => r.json());
|
||||
}
|
82
src/plugins/reviewDB/settings.tsx
Normal file
82
src/plugins/reviewDB/settings.tsx
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 { definePluginSettings } from "@api/Settings";
|
||||
import { OptionType } from "@utils/types";
|
||||
import { Button } from "@webpack/common";
|
||||
|
||||
import { ReviewDBUser } from "./entities";
|
||||
import { authorize } from "./utils";
|
||||
|
||||
export const settings = definePluginSettings({
|
||||
authorize: {
|
||||
type: OptionType.COMPONENT,
|
||||
description: "Authorize with ReviewDB",
|
||||
component: () => (
|
||||
<Button onClick={authorize}>
|
||||
Authorize with ReviewDB
|
||||
</Button>
|
||||
)
|
||||
},
|
||||
notifyReviews: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Notify about new reviews on startup",
|
||||
default: true,
|
||||
},
|
||||
showWarning: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Display warning to be respectful at the top of the reviews list",
|
||||
default: true,
|
||||
},
|
||||
hideTimestamps: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Hide timestamps on reviews",
|
||||
default: false,
|
||||
},
|
||||
website: {
|
||||
type: OptionType.COMPONENT,
|
||||
description: "ReviewDB website",
|
||||
component: () => (
|
||||
<Button onClick={() => {
|
||||
let url = "https://reviewdb.mantikafasi.dev/";
|
||||
if (settings.store.token)
|
||||
url += "/api/redirect?token=" + encodeURIComponent(settings.store.token);
|
||||
|
||||
VencordNative.native.openExternal(url);
|
||||
}}>
|
||||
ReviewDB website
|
||||
</Button>
|
||||
)
|
||||
},
|
||||
supportServer: {
|
||||
type: OptionType.COMPONENT,
|
||||
description: "ReviewDB Support Server",
|
||||
component: () => (
|
||||
<Button onClick={() => {
|
||||
VencordNative.native.openExternal("https://discord.gg/eWPBSbvznt");
|
||||
}}>
|
||||
ReviewDB Support Server
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
}).withPrivateSettings<{
|
||||
token?: string;
|
||||
user?: ReviewDBUser;
|
||||
lastReviewId?: number;
|
||||
reviewsDropdownState?: boolean;
|
||||
}>();
|
@ -1,3 +1,51 @@
|
||||
[class|="section"]:not([class|="lastSection"]) + .vc-reviewdb-view {
|
||||
[class|="section"]:not([class|="lastSection"]) + .vc-rdb-view {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.vc-rdb-badge {
|
||||
vertical-align: middle;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.vc-rdb-input {
|
||||
margin-top: 6px;
|
||||
margin-bottom: 12px;
|
||||
resize: none;
|
||||
overflow: hidden;
|
||||
background: transparent;
|
||||
border: 1px solid var(--profile-message-input-border-color);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.vc-rdb-placeholder {
|
||||
margin-bottom: 4px;
|
||||
font-weight: bold;
|
||||
font-style: italic;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.vc-rdb-modal-footer {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.vc-rdb-modal-footer > div {
|
||||
width: 100%;
|
||||
margin: 6px 16px;
|
||||
}
|
||||
|
||||
.vc-rdb-modal-footer .vc-rdb-input {
|
||||
margin-bottom: 0;
|
||||
background: var(--input-background);
|
||||
}
|
||||
|
||||
.vc-rdb-modal-footer [class|="pageControlContainer"] {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.vc-rdb-modal-header {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.vc-rdb-modal-reviews {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
@ -16,14 +16,16 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Settings } from "@api/Settings";
|
||||
import { classNameFactory } from "@api/Styles";
|
||||
import { Logger } from "@utils/Logger";
|
||||
import { openModal } from "@utils/modal";
|
||||
import { findByProps } from "@webpack";
|
||||
import { FluxDispatcher, React, SelectedChannelStore, Toasts, UserUtils } from "@webpack/common";
|
||||
|
||||
import { Review } from "../entities/Review";
|
||||
import { UserType } from "../entities/User";
|
||||
import { Review, UserType } from "./entities";
|
||||
import { settings } from "./settings";
|
||||
|
||||
export const cl = classNameFactory("vc-rdb-");
|
||||
|
||||
export async function openUserProfileModal(userId: string) {
|
||||
await UserUtils.fetchUser(userId);
|
||||
@ -57,7 +59,7 @@ export function authorize(callback?: any) {
|
||||
});
|
||||
const { token, success } = await res.json();
|
||||
if (success) {
|
||||
Settings.plugins.ReviewDB.token = token;
|
||||
settings.store.token = token;
|
||||
showToast("Successfully logged in!");
|
||||
callback?.();
|
||||
} else if (res.status === 1) {
|
||||
@ -82,8 +84,9 @@ export function showToast(text: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export const sleep = (ms: number) => new Promise(r => setTimeout(r, ms));
|
||||
|
||||
export function canDeleteReview(review: Review, userId: string) {
|
||||
if (review.sender.discordID === userId || Settings.plugins.ReviewDB.user?.type === UserType.Admin) return true;
|
||||
return (
|
||||
review.sender.discordID === userId
|
||||
|| settings.store.user?.type === UserType.Admin
|
||||
);
|
||||
}
|
@ -31,6 +31,12 @@ import settings from "./settings";
|
||||
|
||||
const REMEMBER_DISMISS_KEY = "Vencord-SupportHelper-Dismiss";
|
||||
|
||||
const AllowedChannelIds = [
|
||||
SUPPORT_CHANNEL_ID,
|
||||
"1024286218801926184", // Vencord > #bot-spam
|
||||
"1033680203433660458", // Vencord > #v
|
||||
];
|
||||
|
||||
export default definePlugin({
|
||||
name: "SupportHelper",
|
||||
required: true,
|
||||
@ -41,7 +47,7 @@ export default definePlugin({
|
||||
commands: [{
|
||||
name: "vencord-debug",
|
||||
description: "Send Vencord Debug info",
|
||||
predicate: ctx => ctx.channel.id === SUPPORT_CHANNEL_ID,
|
||||
predicate: ctx => AllowedChannelIds.includes(ctx.channel.id),
|
||||
execute() {
|
||||
const { RELEASE_CHANNEL } = window.GLOBAL_ENV;
|
||||
|
||||
@ -52,21 +58,26 @@ export default definePlugin({
|
||||
return `Web (${navigator.userAgent})`;
|
||||
})();
|
||||
|
||||
const isApiPlugin = (plugin: string) => plugin.endsWith("API") || plugins[plugin].required;
|
||||
|
||||
const enabledPlugins = Object.keys(plugins).filter(p => Vencord.Plugins.isPluginEnabled(p) && !isApiPlugin(p));
|
||||
const enabledApiPlugins = Object.keys(plugins).filter(p => Vencord.Plugins.isPluginEnabled(p) && isApiPlugin(p));
|
||||
|
||||
const debugInfo = `
|
||||
**Vencord Debug Info**
|
||||
>>> Discord Branch: ${RELEASE_CHANNEL}
|
||||
Client: ${client}
|
||||
Platform: ${window.navigator.platform}
|
||||
Vencord: ${gitHash}${settings.additionalInfo}
|
||||
Outdated: ${isOutdated}
|
||||
OpenAsar: ${"openasar" in window}
|
||||
|
||||
> Discord Branch: ${RELEASE_CHANNEL}
|
||||
> Client: ${client}
|
||||
> Platform: ${window.navigator.platform}
|
||||
> Vencord Version: ${gitHash}${settings.additionalInfo}
|
||||
> OpenAsar: ${"openasar" in window}
|
||||
> Outdated: ${isOutdated}
|
||||
> Enabled Plugins:
|
||||
${makeCodeblock(Object.keys(plugins).filter(Vencord.Plugins.isPluginEnabled).join(", "))}
|
||||
Enabled Plugins (${enabledPlugins.length + enabledApiPlugins.length}):
|
||||
${makeCodeblock(enabledPlugins.join(", ") + "\n\n" + enabledApiPlugins.join(", "))}
|
||||
`;
|
||||
|
||||
return {
|
||||
content: debugInfo.trim()
|
||||
content: debugInfo.trim().replaceAll("```\n", "```")
|
||||
};
|
||||
}
|
||||
}],
|
||||
|
@ -59,17 +59,20 @@ function speak(text: string, settings: any = Settings.plugins.VcNarrator) {
|
||||
speechSynthesis.speak(speech);
|
||||
}
|
||||
|
||||
function clean(str: string, fallback: string) {
|
||||
function clean(str: string) {
|
||||
const replacer = Settings.plugins.VcNarrator.latinOnly
|
||||
? /[^\p{Script=Latin}\p{Number}\p{Punctuation}\s]/gu
|
||||
: /[^\p{Letter}\p{Number}\p{Punctuation}\s]/gu;
|
||||
|
||||
return str.normalize("NFKC")
|
||||
.replace(/[^\w ]/g, "")
|
||||
.trim()
|
||||
|| fallback;
|
||||
.replace(replacer, "")
|
||||
.trim();
|
||||
}
|
||||
|
||||
function formatText(str: string, user: string, channel: string) {
|
||||
return str
|
||||
.replaceAll("{{USER}}", clean(user, user ? "Someone" : ""))
|
||||
.replaceAll("{{CHANNEL}}", clean(channel, "channel"));
|
||||
.replaceAll("{{USER}}", clean(user) || user ? "Someone" : "")
|
||||
.replaceAll("{{CHANNEL}}", clean(channel) || "channel");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -235,6 +238,11 @@ export default definePlugin({
|
||||
type: OptionType.BOOLEAN,
|
||||
default: false
|
||||
},
|
||||
latinOnly: {
|
||||
description: "Strip non latin characters from names before saying them",
|
||||
type: OptionType.BOOLEAN,
|
||||
default: false
|
||||
},
|
||||
joinMessage: {
|
||||
type: OptionType.STRING,
|
||||
description: "Join Message",
|
||||
|
@ -67,6 +67,7 @@ interface AwaiterOpts<T> {
|
||||
fallbackValue: T;
|
||||
deps?: unknown[];
|
||||
onError?(e: any): void;
|
||||
onSuccess?(value: T): void;
|
||||
}
|
||||
/**
|
||||
* Await a promise
|
||||
@ -94,8 +95,16 @@ export function useAwaiter<T>(factory: () => Promise<T>, providedOpts?: AwaiterO
|
||||
if (!state.pending) setState({ ...state, pending: true });
|
||||
|
||||
factory()
|
||||
.then(value => isAlive && setState({ value, error: null, pending: false }))
|
||||
.catch(error => isAlive && (setState({ value: null, error, pending: false }), opts.onError?.(error)));
|
||||
.then(value => {
|
||||
if (!isAlive) return;
|
||||
setState({ value, error: null, pending: false });
|
||||
opts.onSuccess?.(value);
|
||||
})
|
||||
.catch(error => {
|
||||
if (!isAlive) return;
|
||||
setState({ value: null, error, pending: false });
|
||||
opts.onError?.(error);
|
||||
});
|
||||
|
||||
return () => void (isAlive = false);
|
||||
}, opts.deps);
|
||||
|
@ -277,6 +277,8 @@ export interface DefinedSettings<D extends SettingsDefinition = SettingsDefiniti
|
||||
* will be an empty string until plugin is initialized
|
||||
*/
|
||||
pluginName: string;
|
||||
|
||||
withPrivateSettings<T>(): this & { store: T; };
|
||||
}
|
||||
|
||||
export type PartialExcept<T, R extends keyof T> = Partial<T> & Required<Pick<T, R>>;
|
||||
|
@ -43,6 +43,7 @@ export let ButtonLooks: t.ButtonLooks;
|
||||
export let Popout: t.Popout;
|
||||
export let Dialog: t.Dialog;
|
||||
export let TabBar: any;
|
||||
export let Paginator: t.Paginator;
|
||||
// token lagger real
|
||||
/** css colour resolver stuff, no clue what exactly this does, just copied usage from Discord */
|
||||
export let useToken: t.useToken;
|
||||
@ -53,6 +54,6 @@ export const Flex = waitForComponent<t.Flex>("Flex", ["Justify", "Align", "Wrap"
|
||||
export const ButtonWrapperClasses = findByPropsLazy("buttonWrapper", "buttonContent") as Record<string, string>;
|
||||
|
||||
waitFor("FormItem", m => {
|
||||
({ useToken, Card, Button, FormSwitch: Switch, Tooltip, TextInput, TextArea, Text, Select, SearchableSelect, Slider, ButtonLooks, TabBar, Popout, Dialog } = m);
|
||||
({ useToken, Card, Button, FormSwitch: Switch, Tooltip, TextInput, TextArea, Text, Select, SearchableSelect, Slider, ButtonLooks, TabBar, Popout, Dialog, Paginator } = m);
|
||||
Forms = m;
|
||||
});
|
||||
|
10
src/webpack/common/types/components.d.ts
vendored
10
src/webpack/common/types/components.d.ts
vendored
@ -387,3 +387,13 @@ export type useToken = (color: {
|
||||
css: string;
|
||||
resolve: Resolve;
|
||||
}) => ReturnType<Resolve>;
|
||||
|
||||
export type Paginator = ComponentType<{
|
||||
currentPage: number;
|
||||
maxVisiblePages: number;
|
||||
pageSize: number;
|
||||
totalCount: number;
|
||||
|
||||
onPageChange?(page: number): void;
|
||||
hideMaxPage?: boolean;
|
||||
}>;
|
||||
|
@ -28,7 +28,12 @@ let webpackChunk: any[];
|
||||
|
||||
const logger = new Logger("WebpackInterceptor", "#8caaee");
|
||||
|
||||
Object.defineProperty(window, WEBPACK_CHUNK, {
|
||||
if (window[WEBPACK_CHUNK]) {
|
||||
logger.info(`Patching ${WEBPACK_CHUNK}.push (was already existant, likely from cache!)`);
|
||||
_initWebpack(window[WEBPACK_CHUNK]);
|
||||
patchPush();
|
||||
} else {
|
||||
Object.defineProperty(window, WEBPACK_CHUNK, {
|
||||
get: () => webpackChunk,
|
||||
set: v => {
|
||||
if (v?.push !== Array.prototype.push) {
|
||||
@ -42,7 +47,8 @@ Object.defineProperty(window, WEBPACK_CHUNK, {
|
||||
webpackChunk = v;
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function patchPush() {
|
||||
function handlePush(chunk: any) {
|
||||
|
Reference in New Issue
Block a user