mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-15 09:33:03 -04:00
fix(MessageBurst): cleanup and add new option (#143)
* remove debug logs never was necessary * do not edit last message if the message is a reply * implement shouldMergeWithAttachment
This commit is contained in:
parent
b07618ddaa
commit
9253d734fe
1 changed files with 15 additions and 4 deletions
|
@ -10,7 +10,7 @@ import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { ChannelStore, MessageActions, MessageStore, UserStore } from "@webpack/common";
|
import { ChannelStore, MessageActions, MessageStore, UserStore } from "@webpack/common";
|
||||||
import { Channel, Message } from "discord-types/general";
|
import { Channel, Message } from "discord-types/general";
|
||||||
|
|
||||||
function shouldEdit(channel: Channel, message: Message, timePeriod: number) {
|
function shouldEdit(channel: Channel, message: Message, timePeriod: number, shouldMergeWithAttachment: boolean) {
|
||||||
let should = true;
|
let should = true;
|
||||||
|
|
||||||
if (channel.isGroupDM()) {
|
if (channel.isGroupDM()) {
|
||||||
|
@ -23,6 +23,14 @@ function shouldEdit(channel: Channel, message: Message, timePeriod: number) {
|
||||||
should = false;
|
should = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (document.querySelector('[class^="replyBar__"]')) {
|
||||||
|
should = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.attachments.length > 0 && !shouldMergeWithAttachment) {
|
||||||
|
should = false;
|
||||||
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const timestamp = new Date(message.timestamp);
|
const timestamp = new Date(message.timestamp);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
@ -46,6 +54,11 @@ export default definePlugin({
|
||||||
type: OptionType.NUMBER,
|
type: OptionType.NUMBER,
|
||||||
description: "The duration of bursts (in seconds).",
|
description: "The duration of bursts (in seconds).",
|
||||||
default: 3
|
default: 3
|
||||||
|
},
|
||||||
|
shouldMergeWithAttachment: {
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
description: "Should the message be merged if the last message has an attachment?",
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
onBeforeMessageSend(channelId, message) {
|
onBeforeMessageSend(channelId, message) {
|
||||||
|
@ -60,9 +73,7 @@ export default definePlugin({
|
||||||
|
|
||||||
const channel = ChannelStore.getChannel(channelId);
|
const channel = ChannelStore.getChannel(channelId);
|
||||||
|
|
||||||
const { should, content } = shouldEdit(channel, lastMessage as Message, this.settings.store.timePeriod);
|
const { should, content } = shouldEdit(channel, lastMessage as Message, this.settings.store.timePeriod, this.settings.store.shouldMergeWithAttachment);
|
||||||
|
|
||||||
console.log(should, content, this.settings.store.timePeriod);
|
|
||||||
|
|
||||||
if (should) {
|
if (should) {
|
||||||
MessageActions.editMessage(channelId, lastMessageId, {
|
MessageActions.editMessage(channelId, lastMessageId, {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue