mirror of
https://github.com/Equicord/Equicord.git
synced 2025-02-23 08:39:24 -05:00
feat(plugin): MessageBurst (#142)
* add myself to EquicordDevs list * implement MessageMerger plugin * change lastMessageContent to lastMessage better variable name * refactor and cleanup code * rebrand and add option * implement time checking * better description * add plugin to plugin list within README had to redo this because prettier kept attempting to format it --------- Co-authored-by: thororen <78185467+thororen1234@users.noreply.github.com>
This commit is contained in:
parent
df68579658
commit
b07618ddaa
3 changed files with 79 additions and 0 deletions
|
@ -87,6 +87,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch
|
|||
- LoginWithQR by nexpid
|
||||
- MediaPlaybackSpeed by D3SOX
|
||||
- Meow by Samwich
|
||||
- MessageBurst by port
|
||||
- MessageColors by Hen
|
||||
- MessageLinkTooltip by Kyuuhachi
|
||||
- MessageLoggerEnhanced by Aria
|
||||
|
|
74
src/equicordplugins/messageBurst/index.ts
Normal file
74
src/equicordplugins/messageBurst/index.ts
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2025 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
import { EquicordDevs } from "@utils/constants";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { ChannelStore, MessageActions, MessageStore, UserStore } from "@webpack/common";
|
||||
import { Channel, Message } from "discord-types/general";
|
||||
|
||||
function shouldEdit(channel: Channel, message: Message, timePeriod: number) {
|
||||
let should = true;
|
||||
|
||||
if (channel.isGroupDM()) {
|
||||
if (channel.name === message.content) {
|
||||
should = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (message.author.id !== UserStore.getCurrentUser().id) {
|
||||
should = false;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const timestamp = new Date(message.timestamp);
|
||||
const now = new Date();
|
||||
|
||||
if ((now.getTime() - timestamp.getTime()) > (timePeriod * 1000)) {
|
||||
should = false;
|
||||
}
|
||||
|
||||
return {
|
||||
should: should,
|
||||
content: message.content
|
||||
};
|
||||
}
|
||||
|
||||
export default definePlugin({
|
||||
name: "MessageBurst",
|
||||
description: "Merges messages sent within a time period with your previous sent message if no one else sends a message before you.",
|
||||
authors: [EquicordDevs.port22exposed],
|
||||
settings: definePluginSettings({
|
||||
timePeriod: {
|
||||
type: OptionType.NUMBER,
|
||||
description: "The duration of bursts (in seconds).",
|
||||
default: 3
|
||||
}
|
||||
}),
|
||||
onBeforeMessageSend(channelId, message) {
|
||||
const messages = MessageStore.getMessages(channelId)._map;
|
||||
|
||||
if (!messages) {
|
||||
return;
|
||||
}
|
||||
|
||||
const entries = Object.entries(messages);
|
||||
const [lastMessageId, lastMessage] = entries[entries.length - 1];
|
||||
|
||||
const channel = ChannelStore.getChannel(channelId);
|
||||
|
||||
const { should, content } = shouldEdit(channel, lastMessage as Message, this.settings.store.timePeriod);
|
||||
|
||||
console.log(should, content, this.settings.store.timePeriod);
|
||||
|
||||
if (should) {
|
||||
MessageActions.editMessage(channelId, lastMessageId, {
|
||||
content: `${content}\n${message.content}`
|
||||
});
|
||||
message.content = "";
|
||||
}
|
||||
},
|
||||
});
|
|
@ -1004,6 +1004,10 @@ export const EquicordDevs = Object.freeze({
|
|||
name: "okiso",
|
||||
id: 274178934143451137n,
|
||||
},
|
||||
port22exposed: {
|
||||
name: "port",
|
||||
id: 1318383159645311009n,
|
||||
},
|
||||
} satisfies Record<string, Dev>);
|
||||
|
||||
// iife so #__PURE__ works correctly
|
||||
|
|
Loading…
Add table
Reference in a new issue