Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
verticalsync committed Apr 25, 2024
2 parents a69630d + b728503 commit 0b1ae76
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 157 deletions.
8 changes: 4 additions & 4 deletions src/suncordplugins/messageLoggerEnhanced/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,15 @@ export default definePlugin({

// https://regex101.com/r/TMV1vY/1
{
find: ".removeAttachmentHoverButton",
find: ".removeMosaicItemHoverButton",
replacement: {
match: /(\i=(\i)=>{)(.{1,250}isSingleMosaicItem)/,
match: /(\i=(\i)=>{)(.{1,3550}isSingleMosaicItem)/,
replace: "$1 let forceUpdate=Vencord.Util.useForceUpdater();$self.patchAttachments($2,forceUpdate);$3"
}
},

{
find: "handleImageLoad=",
find: "handleImageLoad)",
replacement: {
match: /(render\(\){)(.{1,100}zoomThumbnailPlaceholder)/,
replace: "$1$self.checkImage(this);$2"
Expand Down Expand Up @@ -568,7 +568,7 @@ export default definePlugin({
attachments: new Map<string, LoggedAttachment>(),
patchAttachments(props: { attachment: LoggedAttachment, message: LoggedMessage; }, forceUpdate: () => void) {
const { attachment, message } = props;
if (!message.deleted || !LoggedMessageManager.hasMessageInLogs(message.id))
if (!message?.deleted || !LoggedMessageManager.hasMessageInLogs(message.id))
return; // Flogger.log("ignoring", message.id);

if (this.attachments.has(attachment.id))
Expand Down
22 changes: 5 additions & 17 deletions src/suncordplugins/soundBoardLogger/components/CloneSoundModal.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
/*
* Vencord, a modification for Discord's desktop app
* Vencord, a Discord client mod
* 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/>.
*/
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { Flex } from "@components/Flex";
import { Margins } from "@utils/margins";
import { classes } from "@utils/misc";
import { closeModal, ModalCloseButton, ModalContent, ModalHeader, ModalRoot, openModal } from "@utils/modal";
import { closeModal, ModalCloseButton,ModalContent, ModalHeader, ModalRoot, openModal } from "@utils/modal";
import { LazyComponent } from "@utils/react";
import { find, findByPropsLazy } from "@webpack";
import { Button, Clickable, Forms, GuildStore, PermissionsBits, PermissionStore, Popout, SearchableSelect, showToast, Text, TextInput, Toasts, useMemo, UserStore, useState } from "@webpack/common";
import { Guild } from "discord-types/general";
import { HtmlHTMLAttributes } from "react";

import { cl, getEmojiUrl, SoundEvent } from "../utils";
import { cl, getEmojiUrl,SoundEvent } from "../utils";

export function openCloneSoundModal(item) {
const key = openModal(props =>
Expand Down
18 changes: 3 additions & 15 deletions src/suncordplugins/soundBoardLogger/components/Icons.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
/*
* Vencord, a modification for Discord's desktop app
* Vencord, a Discord client mod
* 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/>.
*/
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { ChatBarButton } from "@api/ChatButtons";
import { classes } from "@utils/misc";
Expand Down
20 changes: 4 additions & 16 deletions src/suncordplugins/soundBoardLogger/components/MoreUsersModal.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
/*
* Vencord, a modification for Discord's desktop app
* Vencord, a Discord client mod
* 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/>.
*/
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import ErrorBoundary from "@components/ErrorBoundary";
import { Flex } from "@components/Flex";
import { closeModal, ModalContent, ModalRoot, openModal } from "@utils/modal";
import { Clickable, Forms } from "@webpack/common";

import { cl, getEmojiUrl, SoundLogEntry, User } from "../utils";
import { cl, getEmojiUrl,SoundLogEntry, User } from "../utils";

export function openMoreUsersModal(item: SoundLogEntry, users: User[], onClickUser: Function) {
const key = openModal(props => (
Expand Down
18 changes: 3 additions & 15 deletions src/suncordplugins/soundBoardLogger/components/SoundBoardLog.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
/*
* Vencord, a modification for Discord's desktop app
* Vencord, a Discord client mod
* 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/>.
*/
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import ErrorBoundary from "@components/ErrorBoundary";
import { Flex } from "@components/Flex";
Expand Down
21 changes: 5 additions & 16 deletions src/suncordplugins/soundBoardLogger/components/UserModal.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
/*
* Vencord, a modification for Discord's desktop app
* Vencord, a Discord client mod
* 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/>.
*/
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { Flex } from "@components/Flex";
import { CopyIcon } from "@components/Icons";
Expand All @@ -23,6 +11,7 @@ import { Margins } from "@utils/margins";
import { classes, copyWithToast } from "@utils/misc";
import { closeModal, ModalContent, ModalRoot, openModal } from "@utils/modal";
import { Clickable, Forms, Text, Timestamp } from "@webpack/common";
import moment from "moment";

import { AvatarStyles, cl, downloadAudio, getEmojiUrl, playSound, SoundLogEntry, User, UserSummaryItem } from "../utils";
import { DownloadIcon, IconWithTooltip, PlayIcon } from "./Icons";
Expand Down Expand Up @@ -64,7 +53,7 @@ export default function UserModal({ item, user, sounds, closeModal }: { item: So
<Flex flexDirection="column" style={{ gap: "7px", height: "68px", justifyContent: "space-between" }}>
<Text variant="text-md/bold" style={{ height: "20px" }}>{item.soundId}</Text>
<Text variant="text-md/normal">Played {currentUser.plays.length} {currentUser.plays.length === 1 ? "time" : "times"}.</Text>
<Text variant="text-md/normal">Last played: <Timestamp timestamp={new Date(currentUser.plays[currentUser.plays.length - 1])} /></Text>
<Text variant="text-md/normal">Last played: <Timestamp timestamp={new Date(moment(currentUser.plays.at(-1)).toDate())} /></Text>
</Flex>
</Flex>
<Text variant="heading-lg/semibold" tag="h2" className={classes(Margins.top16, Margins.bottom8)}>
Expand Down
15 changes: 5 additions & 10 deletions src/suncordplugins/soundBoardLogger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { addChatBarButton, removeChatBarButton } from "@api/ChatButtons";
import { disableStyle, enableStyle } from "@api/Styles";
import { Devs } from "@utils/constants";
import { Devs, SuncordDevs } from "@utils/constants";
import definePlugin from "@utils/types";
import { FluxDispatcher } from "@webpack/common";

Expand All @@ -20,15 +20,10 @@ import { getListeners } from "./utils";
export default definePlugin({
name: "SoundBoardLogger",
authors: [
{
id: 712653921692155965n,
name: "Moxxie",
},
{
id: 843448897737064448n,
name: "Fres",
},
Devs.echo
Devs.Moxxie,
Devs.Fres,
Devs.echo,
SuncordDevs.thororen
],
settings,
patches: [
Expand Down
27 changes: 12 additions & 15 deletions src/suncordplugins/soundBoardLogger/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
/*
* Vencord, a modification for Discord's desktop app
* Vencord, a Discord client mod
* 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/>.
*/
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { definePluginSettings } from "@api/Settings";
import { OptionType } from "@utils/types";
Expand Down Expand Up @@ -76,6 +64,15 @@ const settings = definePluginSettings({
}

},
FileType: {
description: "the format that you want to save your file",
type: OptionType.SELECT,
options: [
{ label: ".ogg", value: ".ogg", default: true },
{ label: ".mp3", value: ".mp3" },
{ label: ".wav", value: ".wav" },
],
},
IconLocation: {
description: "choose where to show the SoundBoard Log icon (requires restart)",
type: OptionType.SELECT,
Expand Down
18 changes: 3 additions & 15 deletions src/suncordplugins/soundBoardLogger/store.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
/*
* Vencord, a modification for Discord's desktop app
* Vencord, a Discord client mod
* 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/>.
*/
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { DataStore } from "@api/index";

Expand Down
10 changes: 5 additions & 5 deletions src/suncordplugins/soundBoardLogger/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
text-align: center;
margin-top: 10px;
padding-left: 10px;
padding-right: 10px;
padding-right: 10px
}

.vc-soundlog-more-user-profile,
Expand All @@ -37,6 +37,7 @@
flex: 2;
}


.vc-soundlog-sound-emoji {
width: 24px;
height: 24px;
Expand All @@ -55,8 +56,7 @@
width: fit-content;
}

/* stylelint-disable-next-line selector-class-pattern */
.vc-soundlog-more-soundId,
.vc-soundlog-more-soundid,
.vc-soundlog-user-name {
text-transform: none;
flex-grow: 0;
Expand All @@ -69,8 +69,7 @@
text-wrap: nowrap;
}

/* stylelint-disable-next-line selector-class-pattern */
.vc-soundlog-more-soundId {
.vc-soundlog-more-soundid {
background: unset;
}

Expand All @@ -86,6 +85,7 @@
top: 0;
}


.vc-soundlog-more-emoji,
.vc-soundlog-user-avatar {
height: 32px;
Expand Down
32 changes: 9 additions & 23 deletions src/suncordplugins/soundBoardLogger/utils.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
/*
* 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/>.
*/
* Vencord, a Discord client mod
* Copyright (c) 2023 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { classNameFactory } from "@api/Styles";
import { proxyLazy } from "@utils/lazy";
Expand All @@ -23,6 +11,8 @@ import { saveFile } from "@utils/web";
import { findByCode, findByProps, findByPropsLazy } from "@webpack";
import type { User } from "discord-types/general";

import settings from "./settings";

export { User };

export interface SoundEvent {
Expand Down Expand Up @@ -60,16 +50,13 @@ export const playSound = id => {
audio.play();
};

const saveFileModule = findByPropsLazy("saveFile");

export async function downloadAudio(id: string): Promise<void> {
const filename = id + ".ogg";
const uri = `https://cdn.discordapp.com/soundboard-sounds/${id}`;
const data = await fetch(uri).then(e => e.arrayBuffer());
const filename = id + settings.store.FileType;
const data = await fetch(`https://cdn.discordapp.com/soundboard-sounds/${id}`).then(e => e.arrayBuffer());


if (IS_DISCORD_DESKTOP) {
saveFileModule.saveFile(uri, filename);
DiscordNative.fileManager.saveWithDialog(data, filename);
} else {
saveFile(new File([data], filename, { type: "audio/ogg" }));
}
Expand All @@ -92,4 +79,3 @@ export function removeListener(fn): void {
// Taken from https://github.com/Vendicated/Vencord/blob/86e94343cca10b950f2dc8d18d496d6db9f3b728/src/components/PluginSettings/PluginModal.tsx#L45
export const UserSummaryItem = LazyComponent(() => findByCode("defaultRenderUser", "showDefaultAvatarsForNullUsers"));
export const AvatarStyles = findByPropsLazy("moreUsers", "emptyUser", "avatarContainer", "clickableAvatar");
// a
Loading

0 comments on commit 0b1ae76

Please sign in to comment.