/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2024 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 .
*/
import "./style.css";
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { DataStore } from "@api/index";
import { addButton, removeButton } from "@api/MessagePopover";
import ErrorBoundary from "@components/ErrorBoundary";
import { classes } from "@utils/misc";
import { openModal } from "@utils/modal";
import definePlugin from "@utils/types";
import { findByProps, findExportedComponentLazy } from "@webpack";
import { ChannelStore, Menu } from "@webpack/common";
import { Message } from "discord-types/general";
import { Popover as NoteButtonPopover, Popover } from "./components/icons/NoteButton";
import { NoteModal } from "./components/modals/Notebook";
import noteHandler, { noteHandlerCache } from "./NoteHandler";
import { DataStoreToCache, HolyNoteStore } from "./utils";
const HeaderBarIcon = findExportedComponentLazy("Icon", "Divider");
const messageContextMenuPatch: NavContextMenuPatchCallback = async (children, { message }: { message: Message; }) => {
children.push(
{Object.keys(noteHandler.getAllNotes()).map((notebook: string, index: number) => (
noteHandler.addNote(message, notebook)}
/>
))}
);
};
function ToolBarHeader() {
const iconClasses = findByProps("iconWrapper", "clickable");
return (
Popover(e)}
onClick={() => openModal(props => )}
/>
);
}
export default definePlugin({
name: "HolyNotes",
description: "Holy Notes allows you to save messages",
authors: [{ id: 347096063569559553n, name: "wolfieeeeeeee" }],
dependencies: ["MessagePopoverAPI", "ChatInputButtonAPI"],
patches: [
{
find: "toolbar:function",
replacement: {
match: /(function \i\(\i\){)(.{1,200}toolbar.{1,100}mobileToolbar)/,
replace: "$1$self.toolbarAction(arguments[0]);$2"
}
}
],
toolboxActions: {
async "Open Notes"() {
openModal(props => );
}
},
contextMenus: {
"message": messageContextMenuPatch
},
toolbarAction(e) {
if (Array.isArray(e.toolbar))
return e.toolbar.push(
);
e.toolbar = [
,
e.toolbar,
];
},
async start() {
if (await DataStore.keys(HolyNoteStore).then(keys => !keys.includes("Main"))) return noteHandler.newNoteBook("Main");
if (!noteHandlerCache.has("Main")) await DataStoreToCache();
addButton("HolyNotes", message => {
return {
label: "Save Note",
icon: NoteButtonPopover,
message: message,
channel: ChannelStore.getChannel(message.channel_id),
onClick: () => noteHandler.addNote(message, "Main")
};
});
},
async stop() {
removeButton("HolyNotes");
}
});