diff --git a/src/api/Badges.ts b/src/api/Badges.ts index 7a041f1ee..0957bdbe5 100644 --- a/src/api/Badges.ts +++ b/src/api/Badges.ts @@ -100,20 +100,3 @@ export interface BadgeUserArgs { userId: string; guildId: string; } - -interface ConnectedAccount { - type: string; - id: string; - name: string; - verified: boolean; -} - -interface Profile { - connectedAccounts: ConnectedAccount[]; - premiumType: number; - premiumSince: string; - premiumGuildSince?: any; - lastFetched: number; - profileFetchFailed: boolean; - application?: any; -} diff --git a/src/api/ChatButtons.tsx b/src/api/ChatButtons.tsx index fcb76fffc..b8878e768 100644 --- a/src/api/ChatButtons.tsx +++ b/src/api/ChatButtons.tsx @@ -74,9 +74,9 @@ export interface ChatBarProps { }; } -export type ChatBarButton = (props: ChatBarProps & { isMainChat: boolean; }) => JSX.Element | null; +export type ChatBarButtonFactory = (props: ChatBarProps & { isMainChat: boolean; }) => JSX.Element | null; -const buttonFactories = new Map(); +const buttonFactories = new Map(); const logger = new Logger("ChatButtons"); export function _injectButtons(buttons: ReactNode[], props: ChatBarProps) { @@ -91,7 +91,7 @@ export function _injectButtons(buttons: ReactNode[], props: ChatBarProps) { } } -export const addChatBarButton = (id: string, button: ChatBarButton) => buttonFactories.set(id, button); +export const addChatBarButton = (id: string, button: ChatBarButtonFactory) => buttonFactories.set(id, button); export const removeChatBarButton = (id: string) => buttonFactories.delete(id); export interface ChatBarButtonProps { diff --git a/src/api/MemberListDecorators.ts b/src/api/MemberListDecorators.ts index e148bb0a4..0431d76c2 100644 --- a/src/api/MemberListDecorators.ts +++ b/src/api/MemberListDecorators.ts @@ -38,12 +38,12 @@ interface DecoratorProps { user: User; [key: string]: any; } -export type Decorator = (props: DecoratorProps) => JSX.Element | null; +export type MemberListDecoratorFactory = (props: DecoratorProps) => JSX.Element | null; type OnlyIn = "guilds" | "dms"; -export const decorators = new Map(); +export const decorators = new Map(); -export function addDecorator(identifier: string, decorator: Decorator, onlyIn?: OnlyIn) { +export function addDecorator(identifier: string, decorator: MemberListDecoratorFactory, onlyIn?: OnlyIn) { decorators.set(identifier, { decorator, onlyIn }); } diff --git a/src/api/MessageAccessories.ts b/src/api/MessageAccessories.ts index 19026cfbe..ddc96906d 100644 --- a/src/api/MessageAccessories.ts +++ b/src/api/MessageAccessories.ts @@ -16,17 +16,17 @@ * along with this program. If not, see . */ -export type AccessoryCallback = (props: Record) => JSX.Element | null | Array; -export type Accessory = { - callback: AccessoryCallback; +export type MessageAccessoryFactory = (props: Record) => JSX.Element | null | Array; +export type MessageAccessory = { + callback: MessageAccessoryFactory; position?: number; }; -export const accessories = new Map(); +export const accessories = new Map(); export function addAccessory( identifier: string, - callback: AccessoryCallback, + callback: MessageAccessoryFactory, position?: number ) { accessories.set(identifier, { diff --git a/src/api/MessageDecorations.ts b/src/api/MessageDecorations.ts index d212b15b1..8de16dc91 100644 --- a/src/api/MessageDecorations.ts +++ b/src/api/MessageDecorations.ts @@ -18,7 +18,7 @@ import { Channel, Message } from "discord-types/general/index.js"; -interface DecorationProps { +export interface MessageDecorationProps { author: { /** * Will be username if the user has no nickname @@ -44,11 +44,11 @@ interface DecorationProps { message: Message; [key: string]: any; } -export type Decoration = (props: DecorationProps) => JSX.Element | null; +export type MessageDecorationFactory = (props: MessageDecorationProps) => JSX.Element | null; -export const decorations = new Map(); +export const decorations = new Map(); -export function addDecoration(identifier: string, decoration: Decoration) { +export function addDecoration(identifier: string, decoration: MessageDecorationFactory) { decorations.set(identifier, decoration); } @@ -56,7 +56,7 @@ export function removeDecoration(identifier: string) { decorations.delete(identifier); } -export function __addDecorationsToMessage(props: DecorationProps): (JSX.Element | null)[] { +export function __addDecorationsToMessage(props: MessageDecorationProps): (JSX.Element | null)[] { return [...decorations.values()].map(decoration => { return decoration(props); }); diff --git a/src/api/MessageEvents.ts b/src/api/MessageEvents.ts index d6eba748f..12c651e3e 100644 --- a/src/api/MessageEvents.ts +++ b/src/api/MessageEvents.ts @@ -73,11 +73,11 @@ export interface MessageExtra { openWarningPopout: (props: any) => any; } -export type SendListener = (channelId: string, messageObj: MessageObject, extra: MessageExtra) => Promisable; -export type EditListener = (channelId: string, messageId: string, messageObj: MessageObject) => Promisable; +export type MessageSendListener = (channelId: string, messageObj: MessageObject, extra: MessageExtra) => Promisable; +export type MessageEditListener = (channelId: string, messageId: string, messageObj: MessageObject) => Promisable; -const sendListeners = new Set(); -const editListeners = new Set(); +const sendListeners = new Set(); +const editListeners = new Set(); export async function _handlePreSend(channelId: string, messageObj: MessageObject, extra: MessageExtra, replyOptions: MessageReplyOptions) { extra.replyOptions = replyOptions; @@ -111,29 +111,29 @@ export async function _handlePreEdit(channelId: string, messageId: string, messa /** * Note: This event fires off before a message is sent, allowing you to edit the message. */ -export function addPreSendListener(listener: SendListener) { +export function addPreSendListener(listener: MessageSendListener) { sendListeners.add(listener); return listener; } /** * Note: This event fires off before a message's edit is applied, allowing you to further edit the message. */ -export function addPreEditListener(listener: EditListener) { +export function addPreEditListener(listener: MessageEditListener) { editListeners.add(listener); return listener; } -export function removePreSendListener(listener: SendListener) { +export function removePreSendListener(listener: MessageSendListener) { return sendListeners.delete(listener); } -export function removePreEditListener(listener: EditListener) { +export function removePreEditListener(listener: MessageEditListener) { return editListeners.delete(listener); } // Message clicks -type ClickListener = (message: Message, channel: Channel, event: MouseEvent) => void; +export type MessageClickListener = (message: Message, channel: Channel, event: MouseEvent) => void; -const listeners = new Set(); +const listeners = new Set(); export function _handleClick(message: Message, channel: Channel, event: MouseEvent) { // message object may be outdated, so (try to) fetch latest one @@ -147,11 +147,11 @@ export function _handleClick(message: Message, channel: Channel, event: MouseEve } } -export function addClickListener(listener: ClickListener) { +export function addClickListener(listener: MessageClickListener) { listeners.add(listener); return listener; } -export function removeClickListener(listener: ClickListener) { +export function removeClickListener(listener: MessageClickListener) { return listeners.delete(listener); } diff --git a/src/api/MessagePopover.tsx b/src/api/MessagePopover.tsx index eb68ed2d6..4009dfc66 100644 --- a/src/api/MessagePopover.tsx +++ b/src/api/MessagePopover.tsx @@ -33,13 +33,13 @@ export interface ButtonItem { onContextMenu?: MouseEventHandler; } -export type getButtonItem = (message: Message) => ButtonItem | null; +export type MessagePopoverButtonFactory = (message: Message) => ButtonItem | null; -export const buttons = new Map(); +export const buttons = new Map(); export function addButton( identifier: string, - item: getButtonItem, + item: MessagePopoverButtonFactory, ) { buttons.set(identifier, item); } diff --git a/src/plugins/invisibleChat.desktop/index.tsx b/src/plugins/invisibleChat.desktop/index.tsx index 1af8f4e5d..ae5928868 100644 --- a/src/plugins/invisibleChat.desktop/index.tsx +++ b/src/plugins/invisibleChat.desktop/index.tsx @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { addChatBarButton, ChatBarButton } from "@api/ChatButtons"; +import { addChatBarButton, ChatBarButtonFactory } from "@api/ChatButtons"; import { addButton, removeButton } from "@api/MessagePopover"; import { updateMessage } from "@api/MessageUpdater"; import { definePluginSettings } from "@api/Settings"; @@ -66,7 +66,7 @@ function Indicator() { } -const ChatBarIcon: ChatBarButton = ({ isMainChat }) => { +const ChatBarIcon: ChatBarButtonFactory = ({ isMainChat }) => { if (!isMainChat) return null; return ( diff --git a/src/plugins/previewMessage/index.tsx b/src/plugins/previewMessage/index.tsx index fe6b227a5..6f9553dec 100644 --- a/src/plugins/previewMessage/index.tsx +++ b/src/plugins/previewMessage/index.tsx @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { addChatBarButton, ChatBarButton, removeChatBarButton } from "@api/ChatButtons"; +import { addChatBarButton, ChatBarButtonFactory, removeChatBarButton } from "@api/ChatButtons"; import { generateId, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; import definePlugin, { StartAt } from "@utils/types"; @@ -73,7 +73,7 @@ const getAttachments = async (channelId: string) => ); -const PreviewButton: ChatBarButton = ({ isMainChat, isEmpty, type: { attachments } }) => { +const PreviewButton: ChatBarButtonFactory = ({ isMainChat, isEmpty, type: { attachments } }) => { const channelId = SelectedChannelStore.getChannelId(); const draft = useStateFromStores([DraftStore], () => getDraft(channelId)); diff --git a/src/plugins/sendTimestamps/index.tsx b/src/plugins/sendTimestamps/index.tsx index ac7c5edb5..31dbf4df2 100644 --- a/src/plugins/sendTimestamps/index.tsx +++ b/src/plugins/sendTimestamps/index.tsx @@ -18,7 +18,7 @@ import "./styles.css"; -import { addChatBarButton, ChatBarButton, removeChatBarButton } from "@api/ChatButtons"; +import { addChatBarButton, ChatBarButtonFactory, removeChatBarButton } from "@api/ChatButtons"; import { addPreSendListener, removePreSendListener } from "@api/MessageEvents"; import { definePluginSettings } from "@api/Settings"; import { classNameFactory } from "@api/Styles"; @@ -123,7 +123,7 @@ function PickerModal({ rootProps, close }: { rootProps: ModalProps, close(): voi ); } -const ChatBarIcon: ChatBarButton = ({ isMainChat }) => { +const ChatBarIcon: ChatBarButtonFactory = ({ isMainChat }) => { if (!isMainChat) return null; return ( diff --git a/src/plugins/silentMessageToggle/index.tsx b/src/plugins/silentMessageToggle/index.tsx index 0a8b9cd8d..2e70b1d29 100644 --- a/src/plugins/silentMessageToggle/index.tsx +++ b/src/plugins/silentMessageToggle/index.tsx @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -import { addChatBarButton, ChatBarButton, removeChatBarButton } from "@api/ChatButtons"; -import { addPreSendListener, removePreSendListener, SendListener } from "@api/MessageEvents"; +import { addChatBarButton, ChatBarButtonFactory, removeChatBarButton } from "@api/ChatButtons"; +import { addPreSendListener, removePreSendListener, MessageSendListener } from "@api/MessageEvents"; import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; @@ -41,7 +41,7 @@ const settings = definePluginSettings({ } }); -const SilentMessageToggle: ChatBarButton = ({ isMainChat }) => { +const SilentMessageToggle: ChatBarButtonFactory = ({ isMainChat }) => { const [enabled, setEnabled] = useState(lastState); function setEnabledValue(value: boolean) { @@ -50,7 +50,7 @@ const SilentMessageToggle: ChatBarButton = ({ isMainChat }) => { } useEffect(() => { - const listener: SendListener = (_, message) => { + const listener: MessageSendListener = (_, message) => { if (enabled) { if (settings.store.autoDisable) setEnabledValue(false); if (!message.content.startsWith("@silent ")) message.content = "@silent " + message.content; diff --git a/src/plugins/silentTyping/index.tsx b/src/plugins/silentTyping/index.tsx index ad28999aa..e2509fbf7 100644 --- a/src/plugins/silentTyping/index.tsx +++ b/src/plugins/silentTyping/index.tsx @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { addChatBarButton, ChatBarButton, removeChatBarButton } from "@api/ChatButtons"; +import { addChatBarButton, ChatBarButtonFactory, removeChatBarButton } from "@api/ChatButtons"; import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu"; import { definePluginSettings } from "@api/Settings"; @@ -43,7 +43,7 @@ const settings = definePluginSettings({ } }); -const SilentTypingToggle: ChatBarButton = ({ isMainChat }) => { +const SilentTypingToggle: ChatBarButtonFactory = ({ isMainChat }) => { const { isEnabled, showIcon } = settings.use(["isEnabled", "showIcon"]); const toggle = () => settings.store.isEnabled = !settings.store.isEnabled; diff --git a/src/plugins/translate/TranslateIcon.tsx b/src/plugins/translate/TranslateIcon.tsx index fa1d9abf6..755fb17ee 100644 --- a/src/plugins/translate/TranslateIcon.tsx +++ b/src/plugins/translate/TranslateIcon.tsx @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { ChatBarButton } from "@api/ChatButtons"; +import { ChatBarButtonFactory } from "@api/ChatButtons"; import { classes } from "@utils/misc"; import { openModal } from "@utils/modal"; import { Alerts, Forms, Tooltip, useEffect, useState } from "@webpack/common"; @@ -40,7 +40,7 @@ export function TranslateIcon({ height = 24, width = 24, className }: { height?: export let setShouldShowTranslateEnabledTooltip: undefined | ((show: boolean) => void); -export const TranslateChatBarIcon: ChatBarButton = ({ isMainChat }) => { +export const TranslateChatBarIcon: ChatBarButtonFactory = ({ isMainChat }) => { const { autoTranslate, showChatBarButton } = settings.use(["autoTranslate", "showChatBarButton"]); const [shouldShowTranslateEnabledTooltip, setter] = useState(false); diff --git a/src/utils/types.ts b/src/utils/types.ts index dd3c11576..e49df31d2 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -16,8 +16,15 @@ * along with this program. If not, see . */ +import { ProfileBadge } from "@api/Badges"; +import { ChatBarButtonFactory } from "@api/ChatButtons"; import { Command } from "@api/Commands"; import { NavContextMenuPatchCallback } from "@api/ContextMenu"; +import { MemberListDecoratorFactory } from "@api/MemberListDecorators"; +import { MessageAccessoryFactory } from "@api/MessageAccessories"; +import { MessageDecorationFactory } from "@api/MessageDecorations"; +import { MessageClickListener, MessageEditListener, MessageSendListener } from "@api/MessageEvents"; +import { MessagePopoverButtonFactory } from "@api/MessagePopover"; import { FluxEvents } from "@webpack/types"; import { Promisable } from "type-fest"; @@ -141,6 +148,20 @@ export interface PluginDef { toolboxActions?: Record void>; tags?: string[]; + + userProfileBadge?: ProfileBadge; + + onMessageClick?: MessageClickListener; + onBeforeMessageSend?: MessageSendListener; + onBeforeMessageEdit?: MessageEditListener; + + renderMessagePopoverButton?: MessagePopoverButtonFactory; + renderMessageAccessory?: MessageAccessoryFactory; + renderMessageDecoration?: MessageDecorationFactory; + + renderMemberListDecorator?: MemberListDecoratorFactory; + + renderChatBarButton?: ChatBarButtonFactory; } export const enum StartAt {