2024-04-17 14:29:47 -04:00
|
|
|
|
/*
|
|
|
|
|
|
* Vencord, a Discord client mod
|
|
|
|
|
|
* Copyright (c) 2023 Vendicated and contributors
|
|
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import { Devs } from "@utils/constants";
|
|
|
|
|
|
import definePlugin from "@utils/types";
|
2025-07-10 19:40:07 -04:00
|
|
|
|
import { Channel } from "@vencord/discord-types";
|
2026-04-28 09:04:38 -04:00
|
|
|
|
import { ChannelStore } from "@webpack/common";
|
|
|
|
|
|
|
|
|
|
|
|
const SMALL_CAPS: Record<string, string> = {
|
|
|
|
|
|
"ᴀ": "a", "ʙ": "b", "ᴄ": "c", "ᴅ": "d", "ᴇ": "e", "ꜰ": "f", "ɢ": "g", "ʜ": "h", "ɪ": "i", "ᴊ": "j",
|
|
|
|
|
|
"ᴋ": "k", "ʟ": "l", "ᴍ": "m", "ɴ": "n", "ᴏ": "o", "ᴘ": "p", "ǫ": "q", "ʀ": "r", "ꜱ": "s", "ᴛ": "t",
|
|
|
|
|
|
"ᴜ": "u", "ᴠ": "v", "ᴡ": "w", "x": "x", "ʏ": "y", "ᴢ": "z",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const ORIGINAL_NAME = Symbol("cleanChannelName.original");
|
|
|
|
|
|
|
|
|
|
|
|
let editingChannelId: string | null = null;
|
|
|
|
|
|
|
|
|
|
|
|
function computeClean(name: string, type: number): string {
|
2026-05-07 08:58:01 -04:00
|
|
|
|
const cleaned = name
|
2026-04-28 09:04:38 -04:00
|
|
|
|
.normalize("NFKC")
|
|
|
|
|
|
.replace(/[ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ]/g, m => SMALL_CAPS[m])
|
|
|
|
|
|
.replace(/[^ -~]?\p{Extended_Pictographic}[^ -~]?/ug, "")
|
|
|
|
|
|
.replace(/-?[^\p{Letter} -~]-?/ug, [2, 4].includes(type) ? " " : "-")
|
|
|
|
|
|
.replace(/(^-|-$)/g, "")
|
|
|
|
|
|
.replace(/-+/g, "-");
|
2026-05-07 08:58:01 -04:00
|
|
|
|
return cleaned || name;
|
2026-04-28 09:04:38 -04:00
|
|
|
|
}
|
2024-04-17 14:29:47 -04:00
|
|
|
|
|
|
|
|
|
|
export default definePlugin({
|
|
|
|
|
|
name: "CleanChannelName",
|
|
|
|
|
|
authors: [Devs.AutumnVN],
|
2026-04-28 09:04:38 -04:00
|
|
|
|
description: "Remove emoji and decoration from channel names. Reverts to the original while you're editing the channel.",
|
2026-04-16 13:45:58 -04:00
|
|
|
|
tags: ["Appearance", "Customisation", "Chat", "Emotes", "Servers"],
|
2024-04-17 14:29:47 -04:00
|
|
|
|
patches: [
|
|
|
|
|
|
{
|
|
|
|
|
|
find: "loadAllGuildAndPrivateChannelsFromDisk(){",
|
|
|
|
|
|
replacement: {
|
|
|
|
|
|
match: /(?<=getChannel\(\i\)\{if\(null!=\i\)return )\i\(\i\)/,
|
|
|
|
|
|
replace: "$self.cleanChannelName($&)",
|
2026-04-28 09:04:38 -04:00
|
|
|
|
},
|
|
|
|
|
|
},
|
2024-04-17 14:29:47 -04:00
|
|
|
|
],
|
|
|
|
|
|
|
2026-04-28 09:04:38 -04:00
|
|
|
|
flux: {
|
|
|
|
|
|
CHANNEL_SETTINGS_INIT({ channelId }: { channelId: string; }) {
|
|
|
|
|
|
editingChannelId = channelId;
|
|
|
|
|
|
(ChannelStore as any).emitChange?.();
|
|
|
|
|
|
},
|
|
|
|
|
|
CHANNEL_SETTINGS_CLOSE() {
|
|
|
|
|
|
editingChannelId = null;
|
|
|
|
|
|
(ChannelStore as any).emitChange?.();
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2024-04-17 14:29:47 -04:00
|
|
|
|
cleanChannelName(channel?: Channel) {
|
2026-04-28 09:04:38 -04:00
|
|
|
|
if (channel == null) return channel;
|
|
|
|
|
|
const c = channel as any;
|
|
|
|
|
|
|
|
|
|
|
|
if (c[ORIGINAL_NAME] !== undefined) return channel;
|
|
|
|
|
|
|
|
|
|
|
|
c[ORIGINAL_NAME] = channel.name;
|
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(channel, "name", {
|
|
|
|
|
|
configurable: true,
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
get() {
|
|
|
|
|
|
if (editingChannelId === channel.id) return c[ORIGINAL_NAME];
|
|
|
|
|
|
return computeClean(c[ORIGINAL_NAME], channel.type);
|
|
|
|
|
|
},
|
|
|
|
|
|
set(value: string) {
|
|
|
|
|
|
c[ORIGINAL_NAME] = value;
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2024-04-17 14:29:47 -04:00
|
|
|
|
return channel;
|
2026-04-28 09:04:38 -04:00
|
|
|
|
},
|
2024-04-17 14:29:47 -04:00
|
|
|
|
});
|