Skip to content

Commit d3ac41f

Browse files
committed
added font and normalize message body
1 parent 7b056f8 commit d3ac41f

3 files changed

Lines changed: 96 additions & 3 deletions

File tree

src/commands/pickupline.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ import axios from "axios";
33
import log from "npmlog";
44
import fs from "fs/promises";
55
import { client } from "../components/client";
6+
import Font from "../components/font";
67

78
export const command = "pickupline";
89
export const role = "user";
910

1011
export default async function (msg: Message) {
1112
await axios
12-
.get(`https://api.popcat.xyz/pickupline`)
13+
.get(`https://api.popcat.xyz/pickuplines`)
1314
.then(async (response) => {
14-
await msg.reply(response.data.pickupline);
15+
await msg.reply(Font(response.data.pickupline));
1516
})
1617
.catch(async (error) => {
1718
log.error("pickupline", `Error fetching data: ${error.message}`);
18-
await msg.reply(`Error fetching data . Please try again later.`);
19+
await msg.reply(`Error fetching data. Please try again later.`);
1920
});
2021
}

src/components/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ const messageEvent = (msg: Message) => {
3636
// ignore message if it is older than 10 seconds
3737
if (msg.timestamp < Date.now() / 1000 - 10) return;
3838

39+
// process normalization
40+
msg.body = msg.body
41+
.normalize("NFKC")
42+
.replace(/[\u0300-\u036f\u00b4\u0060\u005e\u007e]/g, "");
43+
3944
const prefix = !msg.body.startsWith(commandPrefix);
4045
const senderId = msg.from.split("@")[0];
4146

src/components/font.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const mathSansMap: Record<string, string> = {
2+
a: "𝖺",
3+
b: "𝖻",
4+
c: "𝖼",
5+
d: "𝖽",
6+
e: "𝖾",
7+
f: "𝖿",
8+
g: "𝗀",
9+
h: "𝗁",
10+
i: "𝗂",
11+
j: "𝗃",
12+
k: "𝗄",
13+
l: "𝗅",
14+
m: "𝗆",
15+
n: "𝗇",
16+
o: "𝗈",
17+
p: "𝗉",
18+
q: "𝗊",
19+
r: "𝗋",
20+
s: "𝗌",
21+
t: "𝗍",
22+
u: "𝗎",
23+
v: "𝗏",
24+
w: "𝗐",
25+
x: "𝗑",
26+
y: "𝗒",
27+
z: "𝗓",
28+
A: "𝖠",
29+
B: "𝖡",
30+
C: "𝖢",
31+
D: "𝖣",
32+
E: "𝖤",
33+
F: "𝖥",
34+
G: "𝖦",
35+
H: "𝖧",
36+
I: "𝖨",
37+
J: "𝖩",
38+
K: "𝖪",
39+
L: "𝖫",
40+
M: "𝖬",
41+
N: "𝖭",
42+
O: "𝖮",
43+
P: "𝖯",
44+
Q: "𝖰",
45+
R: "𝖱",
46+
S: "𝖲",
47+
T: "𝖳",
48+
U: "𝖴",
49+
V: "𝖵",
50+
W: "𝖶",
51+
X: "𝖷",
52+
Y: "𝖸",
53+
Z: "𝖹",
54+
1: "𝟣",
55+
2: "𝟤",
56+
3: "𝟥",
57+
4: "𝟦",
58+
5: "𝟧",
59+
6: "𝟨",
60+
7: "𝟩",
61+
8: "𝟪",
62+
9: "𝟫",
63+
0: "𝟢",
64+
};
65+
66+
export default function Font(text: string) {
67+
return text
68+
.split(" ")
69+
.map(function (char) {
70+
if (/^(http|https):\/\//.test(char)) {
71+
return char;
72+
}
73+
if (
74+
/^(https?:\/\/)?(?:www\.)?([a-zA-Z0-9-]+\.){1,}[a-zA-Z]{2,}(?:\/[^\s]*)?$/.test(
75+
char
76+
)
77+
)
78+
return char;
79+
return char
80+
.split("")
81+
.map(function (char) {
82+
return mathSansMap[char];
83+
})
84+
.join("");
85+
})
86+
.join(" ");
87+
}

0 commit comments

Comments
 (0)