Skip to content

Commit

Permalink
[removeChannelEmojis] Add option for removing Unicode emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
lexisother committed Jun 13, 2023
1 parent cd2ce63 commit 8efd14e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
26 changes: 26 additions & 0 deletions plugins/removeChannelEmojis/Settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { components, settings, util } from "replugged";
const { SwitchItem, FormNotice } = components;

interface Settings {
unicode?: boolean;
}

export const pSettings = await settings.init<Settings>("dev.alyxia.removeChannelEmojis");

export function Settings(): React.ReactElement {
return (
<>
<FormNotice
title="Reload after configuring!"
body="The below settings require a reload to take effect."
type={FormNotice.Types.DANGER}
style={{ marginBottom: 20 }}
/>
<SwitchItem
note="Also get rid of all Unicode emojis that people put in channel names."
{...util.useSetting(pSettings, "unicode", false)}>
Remove Unicode emojis
</SwitchItem>
</>
);
}
18 changes: 18 additions & 0 deletions plugins/removeChannelEmojis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export { Settings } from "./Settings";

interface IChannel {
name: string;
}
export function transformName(channel: IChannel): IChannel {
if (channel != null)
if (channel.name) {
channel.name = channel.name
.replace(
/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g,
"",
)
.replace(/\s+/g, " ")
.trim();
}
return channel;
}
3 changes: 2 additions & 1 deletion plugins/removeChannelEmojis/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"discordID": "952185386350829688",
"github": "lexisother"
},
"version": "1.1.1",
"version": "1.2.0",
"updater": {
"type": "store",
"id": "dev.alyxia.removeChannelEmojis"
},
"license": "Apache-2.0",
"type": "replugged-plugin",
"renderer": "index.ts",
"plaintextPatches": "plaintextPatches.ts"
}
19 changes: 19 additions & 0 deletions plugins/removeChannelEmojis/plaintextPatches.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { PlaintextPatch } from "replugged/dist/types";
import { pSettings } from "./Settings";

const __a_require = (e: string): string =>
`window.replugged.plugins.getExports("dev.alyxia.removeChannelEmojis").${e}`;

export default [
{
Expand All @@ -10,4 +14,19 @@ export default [
},
],
},
...(pSettings.get("unicode")
? ([
{
find: /.{1,2}.displayName="ChannelStore";/,
replacements: [
{
match:
/([^;]{1,2}\.getChannel=function\([^)]*\)\{)if\(null!=(.{1,2})\)return ([^(]{1,2})\(.{1,2}\)/,
replace: (_, def, channelId, func) =>
`${def}if(null!=e)return ${__a_require("transformName")}(${func}(${channelId}))`,
},
],
},
] as PlaintextPatch[]) // required typehint due to conditional
: []),
] as PlaintextPatch[];
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8efd14e

Please sign in to comment.