-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(coremods): message popover plaintext patch
- Loading branch information
1 parent
26acb64
commit 225b94b
Showing
4 changed files
with
68 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { Channel, Message } from "discord-types/general"; | ||
import type { GetButtonItem, IconButtonProps } from "../../../types/coremods/message"; | ||
import { Logger } from "../../modules/logger"; | ||
|
||
const logger = Logger.api("MessagePopover"); | ||
|
||
export const buttons = new Map<GetButtonItem, string>(); | ||
|
||
/** | ||
* Adds a button to any MessagePopover | ||
* @param item The function that creates the button to add | ||
* @param key Optional key for button | ||
* @returns A callback to remove the button from set. | ||
*/ | ||
export function addButton(item: GetButtonItem, key?: string): () => void { | ||
buttons.set(item, `${key || "repluggedButton"}-${Math.random().toString(36).substring(2)}`); | ||
|
||
return () => removeButton(item); | ||
} | ||
|
||
/** | ||
* Removes a button from MessagePopover | ||
* @param item The function that creates the button to add | ||
* @returns | ||
*/ | ||
export function removeButton(item: GetButtonItem): void { | ||
buttons.delete(item); | ||
} | ||
|
||
/** | ||
* @internal | ||
* @hidden | ||
*/ | ||
export function _buildPopoverElements( | ||
msg: Message, | ||
channel: Channel, | ||
IconButton: React.FC<IconButtonProps>, | ||
): React.ReactElement[] { | ||
const items = [] as React.ReactElement[]; | ||
|
||
buttons.forEach((key, getItem) => { | ||
try { | ||
const item = getItem(msg, channel); | ||
try { | ||
if (item) { | ||
item.key = key; | ||
items.push(<IconButton {...item} />); | ||
} | ||
} catch (err) { | ||
logger.error(`Error in making the button [${item?.key}]`, err, item); | ||
} | ||
} catch (err) { | ||
logger.error("Error while running GetButtonItem function", err, getItem); | ||
} | ||
}); | ||
|
||
return items; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters