Skip to content

Commit e6bcf1d

Browse files
authored
Update ChatChat Config (#19)
1 parent 10ccafb commit e6bcf1d

File tree

4 files changed

+330
-337
lines changed

4 files changed

+330
-337
lines changed

converters/chatchat/deluxechat.ts

Lines changed: 124 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,150 @@
11
import Converter from "../converter";
22
import {
3-
DeluxeChat,
4-
DeluxeChatConfig,
5-
DeluxeChatFormat,
6-
DeluxeChatPrivateMessageFormat,
3+
DeluxeChat,
4+
DeluxeChatConfig,
5+
DeluxeChatFormat,
6+
DeluxeChatPrivateMessageFormat,
77
} from "../types/deluxechat";
88
import {
9-
ChatChatFormat,
10-
ChatChatFormatsConfig,
11-
ChatChatSettingsConfig,
9+
ChatChatFormat,
10+
ChatChatFormatsConfig,
11+
ChatChatSettingsConfig,
1212
} from "../types/chatchat";
1313
import MiniMessage from "../minimessage";
1414

1515
const schema = require("../types/deluxechat.json");
1616

17-
const ChatChatDeluxeChatConverter = new Converter<
18-
DeluxeChat,
19-
{ format: ChatChatFormatsConfig; settings: ChatChatSettingsConfig }
20-
>({
21-
Convert(deluxechat) {
22-
const deluxechatConfig = deluxechat.deluxechat;
23-
const chatchatFormatsConfig: ChatChatFormatsConfig = {
24-
"default-format": "default",
25-
formats: {},
26-
};
27-
const chatchatSettingsConfig: ChatChatSettingsConfig = {
28-
"sender-format": {
29-
parts: [],
30-
},
31-
"recipient-format": {
32-
parts: [],
33-
},
34-
"social-spy-format": {
35-
parts: [],
36-
},
37-
};
38-
if (deluxechatConfig.formats) {
39-
const formats = deluxechatConfig.formats;
40-
Object.keys(formats).forEach((name) => {
41-
const dcFormat = formats[name];
42-
const ccFormat: ChatChatFormat = {
43-
priority: dcFormat.priority ?? 1,
44-
parts: [],
17+
const ChatChatDeluxeChatConverter = new Converter<DeluxeChat,
18+
{ format: ChatChatFormatsConfig; settings: ChatChatSettingsConfig }>({
19+
Convert(deluxechat) {
20+
const deluxechatConfig = deluxechat.deluxechat;
21+
const chatchatFormatsConfig: ChatChatFormatsConfig = {
22+
"default-format": "default",
23+
formats: {},
4524
};
25+
const chatchatSettingsConfig: ChatChatSettingsConfig = {
26+
"sender-format": {
27+
parts: {},
28+
},
29+
"recipient-format": {
30+
parts: {},
31+
},
32+
"social-spy-format": {
33+
parts: {},
34+
},
35+
};
36+
if (deluxechatConfig.formats) {
37+
const formats = deluxechatConfig.formats;
38+
Object.keys(formats).forEach((name) => {
39+
const dcFormat = formats[name];
40+
const ccFormat: ChatChatFormat = {
41+
priority: dcFormat.priority ?? 1,
42+
parts: {},
43+
};
44+
45+
(["channel", "prefix", "name", "suffix"] as const).forEach(
46+
(segment) => {
47+
let formattedSegment = dcFormat[segment];
4648

47-
(["channel", "prefix", "name", "suffix"] as const).forEach(
48-
(segment) => {
49-
let formattedSegment = dcFormat[segment];
49+
if (formattedSegment) {
50+
// Add in the click command if it exists
51+
let segmentClick =
52+
dcFormat[(segment + "_click_command") as keyof DeluxeChatFormat];
53+
if (segmentClick && segmentClick !== "") {
54+
formattedSegment =
55+
"<click:run_command:'" +
56+
segmentClick +
57+
"'>" +
58+
formattedSegment +
59+
"</click>";
60+
}
61+
}
5062

51-
if (formattedSegment) {
63+
if (dcFormat[(segment + "_tooltip") as keyof DeluxeChatFormat]) {
64+
// Add in the hover if it exists
65+
let segmentHover: string[] = (<string[]>(
66+
dcFormat[(segment + "_tooltip") as keyof DeluxeChatFormat]
67+
)).filter((s) => s && s !== "");
68+
if (segmentHover && segmentHover.length > 0) {
69+
formattedSegment =
70+
"<hover:show_text:'" +
71+
segmentHover.join("<newline>") +
72+
"'>" +
73+
formattedSegment +
74+
"</hover>";
75+
}
76+
}
77+
if (formattedSegment !== "") {
78+
ccFormat.parts[segment] = [MiniMessage(formattedSegment)];
79+
}
80+
}
81+
);
82+
ccFormat.parts.message = ["<message>"];
83+
chatchatFormatsConfig.formats[name] = ccFormat;
84+
});
85+
}
86+
if (deluxechatConfig.private_message_formats) {
87+
const formats = deluxechatConfig.private_message_formats;
88+
["to_sender", "to_recipient"].forEach((section) => {
89+
const dcFormat: DeluxeChatPrivateMessageFormat =
90+
formats[section as keyof DeluxeChatConfig["private_message_formats"]];
91+
const ccPartsFormat: { [key: string]: string[] } = {};
92+
let formattedSegment = dcFormat.format ?? "";
5293

53-
// Add in the click command if it exists
54-
if (dcFormat[(segment + "_click_command") as keyof DeluxeChatFormat]) {
55-
let segmentClick =
56-
dcFormat[(segment + "_click_command") as keyof DeluxeChatFormat];
94+
// Add in the click command if it exists
95+
let segmentClick = dcFormat.click_command;
5796
if (segmentClick && segmentClick !== "") {
58-
formattedSegment =
59-
"<click:run_command:'" +
60-
segmentClick +
61-
"'>" +
62-
formattedSegment +
63-
"</click>";
97+
formattedSegment =
98+
"<click:run_command:'" +
99+
segmentClick +
100+
"'>" +
101+
formattedSegment +
102+
"</click>";
64103
}
65-
}
66104

67-
// Add in the hover if it exists
68-
if (dcFormat[(segment + "_tooltip") as keyof DeluxeChatFormat]) {
69-
let segmentHover: string[] = (<string[]>(
70-
dcFormat[(segment + "_tooltip") as keyof DeluxeChatFormat]
71-
)).filter((s) => s && s !== "");
105+
// Add in the hover if it exists
106+
let segmentHover: string[] = (<string[]>dcFormat.tooltip).filter(
107+
(s) => s && s !== ""
108+
);
72109
if (segmentHover && segmentHover.length > 0) {
73-
formattedSegment =
74-
"<hover:show_text:'" +
75-
segmentHover.join("<newline>") +
76-
"'>" +
77-
formattedSegment +
78-
"</hover>";
110+
formattedSegment =
111+
"<hover:show_text:'" +
112+
segmentHover.join("<newline>") +
113+
"'>" +
114+
formattedSegment +
115+
"</hover>";
79116
}
80-
}
81-
if (formattedSegment !== "") {
82-
ccFormat.parts.push(MiniMessage(formattedSegment));
83-
}
84-
}
85-
}
86-
);
87-
ccFormat.parts.push("<message>");
88-
chatchatFormatsConfig.formats[name] = ccFormat;
89-
});
90-
}
91-
if (deluxechatConfig.private_message_formats) {
92-
const formats = deluxechatConfig.private_message_formats;
93-
["to_sender", "to_recipient"].forEach((section) => {
94-
const dcFormat: DeluxeChatPrivateMessageFormat =
95-
formats[section as keyof DeluxeChatConfig["private_message_formats"]];
96-
const ccPartsFormat: string[] = [];
97-
let formattedSegment = dcFormat.format ?? "";
117+
ccPartsFormat[section] = [MiniMessage(formattedSegment)];
118+
ccPartsFormat.message = ["<message>"];
98119

99-
// Add in the click command if it exists
100-
let segmentClick = dcFormat.click_command;
101-
if (segmentClick && segmentClick !== "") {
102-
formattedSegment =
103-
"<click:run_command:'" +
104-
segmentClick +
105-
"'>" +
106-
formattedSegment +
107-
"</click>";
108-
}
109-
110-
// Add in the hover if it exists
111-
let segmentHover: string[] = (<string[]>dcFormat.tooltip).filter(
112-
(s) => s && s !== ""
113-
);
114-
if (segmentHover && segmentHover.length > 0) {
115-
formattedSegment =
116-
"<hover:show_text:'" +
117-
segmentHover.join("<newline>") +
118-
"'>" +
119-
formattedSegment +
120-
"</hover>";
121-
}
122-
ccPartsFormat.push(MiniMessage(formattedSegment));
123-
ccPartsFormat.push("<message>");
124-
125-
switch (section) {
126-
case "to_sender":
127-
chatchatSettingsConfig["sender-format"].parts = ccPartsFormat;
128-
break;
129-
case "to_recipient":
130-
chatchatSettingsConfig["recipient-format"].parts = ccPartsFormat;
131-
break;
132-
}
133-
});
120+
switch (section) {
121+
case "to_sender":
122+
chatchatSettingsConfig["sender-format"].parts = ccPartsFormat;
123+
break;
124+
case "to_recipient":
125+
chatchatSettingsConfig["recipient-format"].parts = ccPartsFormat;
126+
break;
127+
}
128+
});
134129

135-
if (formats.social_spy) {
136-
const socialSpyFormat = formats.social_spy;
137-
const ccSocialSpyPartsFormat: string[] = [];
130+
if (formats.social_spy) {
131+
const socialSpyFormat = formats.social_spy;
132+
const ccSocialSpyPartsFormat: { [key: string]: string[] } = {};
138133

139-
ccSocialSpyPartsFormat.push(MiniMessage(socialSpyFormat));
140-
ccSocialSpyPartsFormat.push("<message>");
134+
ccSocialSpyPartsFormat.format = [MiniMessage(socialSpyFormat)];
135+
ccSocialSpyPartsFormat.message = ["<message>"];
141136

142-
chatchatSettingsConfig["social-spy-format"].parts =
143-
ccSocialSpyPartsFormat;
144-
}
145-
}
137+
chatchatSettingsConfig["social-spy-format"].parts =
138+
ccSocialSpyPartsFormat;
139+
}
140+
}
146141

147-
return {
148-
format: chatchatFormatsConfig,
149-
settings: chatchatSettingsConfig,
150-
};
151-
},
152-
inputSchema: schema,
142+
return {
143+
format: chatchatFormatsConfig,
144+
settings: chatchatSettingsConfig,
145+
};
146+
},
147+
inputSchema: schema,
153148
});
154149

155150
export default ChatChatDeluxeChatConverter;

0 commit comments

Comments
 (0)