mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-11 07:33:05 -04:00
i fixed some stuff (#218)
* i fixed some stuff * Update index.tsx * removed useless stuff * Update pnpm-lock.yaml * Update index.tsx * Update http.ts --------- Co-authored-by: thororen1234 <78185467+thororen1234@users.noreply.github.com>
This commit is contained in:
parent
1e311b8d9c
commit
1e5a600213
3 changed files with 63 additions and 30 deletions
|
@ -8,11 +8,10 @@ import { showNotification } from "@api/Notifications";
|
|||
import { definePluginSettings } from "@api/Settings";
|
||||
import { EquicordDevs } from "@utils/constants";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { findStoreLazy } from "@webpack";
|
||||
import {
|
||||
ChannelStore,
|
||||
FluxDispatcher,
|
||||
GuildStore,
|
||||
MessageStore,
|
||||
NavigationRouter,
|
||||
PresenceStore,
|
||||
RelationshipStore,
|
||||
|
@ -20,22 +19,19 @@ import {
|
|||
UserStore
|
||||
} from "@webpack/common";
|
||||
|
||||
const UserGuildSettingsStore = findStoreLazy("UserGuildSettingsStore");
|
||||
|
||||
const settings = definePluginSettings({
|
||||
friends: {
|
||||
type: OptionType.BOOLEAN,
|
||||
default: true,
|
||||
description: "Notify when friends message you (non-@ mentions)"
|
||||
default: false,
|
||||
description: "Notify when friends send messages in servers"
|
||||
},
|
||||
mentions: {
|
||||
type: OptionType.BOOLEAN,
|
||||
default: true,
|
||||
description: "Notify when someone @mentions you directly"
|
||||
},
|
||||
replies: {
|
||||
type: OptionType.BOOLEAN,
|
||||
default: true,
|
||||
description: "Notify when someone replies to your messages"
|
||||
},
|
||||
dms: {
|
||||
type: OptionType.BOOLEAN,
|
||||
default: true,
|
||||
|
@ -44,11 +40,16 @@ const settings = definePluginSettings({
|
|||
showInActive: {
|
||||
type: OptionType.BOOLEAN,
|
||||
default: false,
|
||||
description: "Show notifications even for current active channel"
|
||||
description: "Show notifications even for currently active channel"
|
||||
},
|
||||
ignoreMuted: {
|
||||
type: OptionType.BOOLEAN,
|
||||
default: true,
|
||||
description: "Skip notifications from muted servers, channels, or users"
|
||||
}
|
||||
});
|
||||
|
||||
function formatContent(message: any) {
|
||||
function formatContent(message) {
|
||||
let content = message.content || "";
|
||||
message.mentions?.forEach(user => {
|
||||
content = content.replace(new RegExp(`<@!?${user.id}>`, "g"), `@${user.username}`);
|
||||
|
@ -56,40 +57,75 @@ function formatContent(message: any) {
|
|||
return content.slice(0, 200) + (content.length > 200 ? "..." : "");
|
||||
}
|
||||
|
||||
function checkIfMuted(channel) {
|
||||
if (!settings.store.ignoreMuted) return false;
|
||||
if (!channel) return false;
|
||||
|
||||
if (channel.isMuted?.()) return true;
|
||||
|
||||
const isDM = [1, 3].includes(channel.type);
|
||||
if (isDM) {
|
||||
const recipientIds = channel.recipients || [];
|
||||
for (const userId of recipientIds) {
|
||||
if (RelationshipStore.isBlocked(userId)) return true;
|
||||
}
|
||||
|
||||
if (UserGuildSettingsStore?.getMutedChannels?.()?.includes?.(channel.id)) return true;
|
||||
}
|
||||
|
||||
if (channel.guild_id) {
|
||||
const guild = GuildStore.getGuild(channel.guild_id);
|
||||
if (UserGuildSettingsStore.isMuted(channel.guild_id)) return true;
|
||||
|
||||
if (UserGuildSettingsStore?.isMuted?.(channel.guild_id)) return true;
|
||||
if (UserGuildSettingsStore?.isChannelMuted?.(channel.guild_id, channel.id)) return true;
|
||||
if (UserGuildSettingsStore?.isCategoryMuted?.(channel.guild_id, channel.id)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isUserBlocked(userId) {
|
||||
return settings.store.ignoreMuted && RelationshipStore.isBlocked?.(userId);
|
||||
}
|
||||
|
||||
export default definePlugin({
|
||||
name: "PingNotifications",
|
||||
description: "Customizable notifications with improved mention formatting",
|
||||
authors: [EquicordDevs.smuki],
|
||||
settings,
|
||||
|
||||
flux: {
|
||||
async MESSAGE_CREATE({ message }) {
|
||||
MESSAGE_CREATE({ message }) {
|
||||
try {
|
||||
if (!message?.channel_id || message.state === "SENDING") return;
|
||||
|
||||
const channel = ChannelStore.getChannel(message.channel_id);
|
||||
const currentUser = UserStore.getCurrentUser();
|
||||
|
||||
if (!channel || !currentUser || message.author?.id === currentUser.id) return;
|
||||
if ((channel as any).isMuted?.() || (channel.guild_id && (GuildStore.getGuild(channel.guild_id) as any)?.isMuted?.())) return;
|
||||
if (!channel || !currentUser) return;
|
||||
if (message.author?.id === currentUser.id) return;
|
||||
|
||||
const isDM = [1, 3].includes(channel.type);
|
||||
|
||||
if (checkIfMuted(channel)) return;
|
||||
if (isUserBlocked(message.author.id)) return;
|
||||
if (!settings.store.showInActive && channel.id === SelectedChannelStore.getChannelId()) return;
|
||||
if (PresenceStore.getStatus(currentUser.id) === "dnd") return;
|
||||
|
||||
const author = UserStore.getUser(message.author.id) || { username: "Unknown" };
|
||||
const isDM = [1, 3].includes(channel.type);
|
||||
const channelName = channel.name || (isDM ? "DM" : "Group");
|
||||
const body = formatContent(message);
|
||||
|
||||
const shouldNotify = (
|
||||
(settings.store.mentions && message.mentions?.some(u => u.id === currentUser.id)) ||
|
||||
(settings.store.friends && RelationshipStore.isFriend(message.author.id)) ||
|
||||
(settings.store.replies && message.message_reference?.message_id &&
|
||||
MessageStore.getMessage(
|
||||
message.message_reference.channel_id || channel.id,
|
||||
message.message_reference.message_id
|
||||
)?.author.id === currentUser.id
|
||||
) ||
|
||||
(isDM && settings.store.dms)
|
||||
);
|
||||
let shouldNotify = false;
|
||||
|
||||
if (settings.store.mentions && message.mentions?.some(u => u.id === currentUser.id)) {
|
||||
shouldNotify = true;
|
||||
} else if (settings.store.friends && RelationshipStore.isFriend(message.author.id) && !isDM) {
|
||||
shouldNotify = true;
|
||||
} else if (isDM && settings.store.dms) {
|
||||
shouldNotify = true;
|
||||
}
|
||||
|
||||
if (shouldNotify) {
|
||||
showNotification({
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { isLegacyNonAsarVencord } from "@main/patcher";
|
||||
import { get } from "@main/utils/simpleGet";
|
||||
import { IpcEvents } from "@shared/IpcEvents";
|
||||
import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent";
|
||||
|
@ -120,8 +119,6 @@ async function migrateAsarToLegacy() {
|
|||
}
|
||||
}
|
||||
|
||||
if (!isLegacyNonAsarVencord) migrateAsarToLegacy();
|
||||
|
||||
ipcMain.handle(IpcEvents.GET_REPO, serializeErrors(() => `https://github.com/${gitRemote}`));
|
||||
ipcMain.handle(IpcEvents.GET_UPDATES, serializeErrors(calculateGitChanges));
|
||||
ipcMain.handle(IpcEvents.UPDATE, serializeErrors(fetchUpdates));
|
||||
|
|
|
@ -1039,7 +1039,7 @@ export const EquicordDevs = Object.freeze({
|
|||
id: 724416180097384498n
|
||||
},
|
||||
smuki: {
|
||||
name: "sumki",
|
||||
name: "smuki",
|
||||
id: 691517398523576331n
|
||||
},
|
||||
} satisfies Record<string, Dev>);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue