Skip to content

Commit a90714b

Browse files
committed
Initial EssXChat Converter
1 parent 37775e5 commit a90714b

File tree

6 files changed

+202
-1
lines changed

6 files changed

+202
-1
lines changed

converters/chatchat/essentialschat.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import Converter from "../converter";
2+
import {EssentialsChatConfig} from "../types/essentialschat";
3+
import {ChatChatFormat, ChatChatFormatsConfig, ChatChatSettingsConfig} from "../types/chatchat";
4+
import MiniMessage from "../minimessage";
5+
import Placeholders from "../placeholders";
6+
7+
const schema = require('../types/essentialschat.json')
8+
9+
const ChatChatEssentialsChatConverter = new Converter<EssentialsChatConfig, { format: ChatChatFormatsConfig, settings: ChatChatSettingsConfig }>({
10+
Convert(essentialschatConfig) {
11+
const chatchatFormatsConfig: ChatChatFormatsConfig = {
12+
"default-format": 'default',
13+
formats: {}
14+
}
15+
const chatchatSettingsConfig: ChatChatSettingsConfig = {
16+
"sender-format": {
17+
parts: []
18+
},
19+
"recipient-format": {
20+
parts: []
21+
},
22+
}
23+
24+
if (essentialschatConfig.format) {
25+
const format = essentialschatConfig.format;
26+
const ccFormat: ChatChatFormat = {
27+
priority: 1,
28+
parts: []
29+
}
30+
let parsed = MiniMessage(format);
31+
ccFormat.parts.push(Placeholders(parsed));
32+
chatchatFormatsConfig.formats['default'] = ccFormat;
33+
}
34+
35+
let formatCount = 1;
36+
37+
if (essentialschatConfig["group-formats"]) {
38+
const formats = essentialschatConfig["group-formats"]
39+
Object.keys(formats).forEach(name => {
40+
const ecFormat = formats[name]
41+
const ccFormat: ChatChatFormat = {
42+
priority: formatCount,
43+
parts: []
44+
}
45+
let parsed = MiniMessage(ecFormat);
46+
ccFormat.parts.push(Placeholders(parsed));
47+
chatchatFormatsConfig.formats[name] = ccFormat;
48+
formatCount++;
49+
});
50+
}
51+
52+
53+
return {
54+
format: chatchatFormatsConfig,
55+
settings: chatchatSettingsConfig
56+
}
57+
},
58+
inputSchema: schema,
59+
});
60+
61+
export default ChatChatEssentialsChatConverter;

converters/placeholders.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default function Placeholders(input: string): string {
2+
const replacements: Record<string, string> = {
3+
'{MESSAGE}': "<message>",
4+
'{USERNAME}': "%player_name%",
5+
'{DISPLAYNAME}': "%player_display_name%",
6+
'{NICKNAME}': "%essentials_nickname%",
7+
'{PREFIX}': "%vault_prefix%",
8+
'{SUFFIX}': "%vault_suffix%",
9+
'{GROUP}': "%vault_groupprefix%",
10+
'{WORLDNAME}': "%player_world_name%"
11+
}
12+
13+
let out = input;
14+
15+
Object.keys(replacements).forEach(key => {
16+
out = out.replace(new RegExp(key, "ig"), replacements[key]);
17+
});
18+
19+
return out;
20+
}

converters/types/essentialschat.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/EssentialsChatConfig",
4+
"definitions": {
5+
"EssentialsChatConfig": {
6+
"type": "object",
7+
"properties": {
8+
"format": {
9+
"type": "string"
10+
},
11+
"group-formats": {
12+
"type": "object",
13+
"additionalProperties": {
14+
"type": "string"
15+
}
16+
}
17+
},
18+
"additionalProperties": false
19+
}
20+
}
21+
}

converters/types/essentialschat.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @ToolBox - EssentialsChatConfig
2+
3+
export interface EssentialsChatConfig {
4+
format?: string
5+
"group-formats"?: {
6+
[key: string]: string
7+
}
8+
}

pages/_app.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ function Converter({Component, pageProps}: AppProps) {
1818
<Collapsable name={"Config Converters"}>
1919
<Collapsable name={"ChatChat"}>
2020
<Link href={'/converters/chatchat/deluxechat'}>
21-
DeluxeChat
21+
<p>DeluxeChat</p>
22+
</Link>
23+
<Link href={'/converters/chatchat/essentialschat'}>
24+
<p>EssentialsChat</p>
2225
</Link>
2326
</Collapsable>
2427
</Collapsable>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import type {NextPage} from 'next'
2+
import Head from 'next/head'
3+
import tw, {css} from 'twin.macro'
4+
import {TextBox} from "../../../components/TextBox";
5+
import {useEffect, useState} from "react";
6+
import ChatChatEssentialsChatConverter from "../../../converters/chatchat/essentialschat";
7+
import {ConversionError} from "../../../converters/converter";
8+
9+
10+
const Home: NextPage = () => {
11+
12+
const [config, setConfig] = useState("");
13+
const [parsedConfig, setParsedConfig] = useState<false | { format: string, settings: string }>(false);
14+
const [error, setError] = useState<false | string>(false);
15+
16+
useEffect(() => {
17+
const newConfig = ChatChatEssentialsChatConverter.convert(config);
18+
if (Object.keys(newConfig).includes("error")) {
19+
setError((newConfig as ConversionError).message);
20+
setParsedConfig(false);
21+
} else {
22+
setError(false);
23+
setParsedConfig(newConfig as { format: string, settings: string });
24+
}
25+
}, [config])
26+
27+
return (
28+
<div>
29+
<Head>
30+
<title>EssentialsChat to ChatChat Converter</title>
31+
<meta name="description" content="Convert EssentialsChat Configs to ChatChat"/>
32+
</Head>
33+
34+
<main css={css`${tw`flex flex-col`} height: calc(100vh - 2.75rem)`}>
35+
<div css={tw`text-white bg-blue-500 w-full md:px-8 p-16 h-48 text-center`}>
36+
<p css={tw`text-3xl font-bold`}>HelpChat</p>
37+
<p css={tw`text-lg`}>EssentialsChat Config Converter</p>
38+
</div>
39+
<div css={tw`flex flex-col md:flex-row flex-grow flex-shrink h-full max-w-full`}>
40+
<div css={css`
41+
${tw`w-full md:w-1/2 p-4 pt-1 pr-2`}
42+
height: calc(100vh - 14.75em);
43+
max-width: calc(50vw - 6rem);
44+
`}>
45+
<TextBox title={"EssentialsChat Config"} code={config} editor={setConfig} language={"yaml"}/>
46+
</div>
47+
<div css={css`
48+
${tw`w-full md:w-1/2 p-4 pl-2 pt-1 flex flex-col`}
49+
height: calc(100vh - 14.75em);
50+
max-width: calc(50vw - 6rem);
51+
`}>
52+
{
53+
error ? (<div css={tw`flex flex-col h-full w-full pt-1`}>
54+
<div css={tw`flex flex-row pl-2`}>
55+
<p css={tw`text-xl font-semibold mx-auto mb-2`}>YAML Validation Errors</p>
56+
</div>
57+
<div css={css`${tw`rounded-md overflow-auto h-full`} background-color: #2a2734`}>
58+
<div css={tw` py-2 px-4`}>
59+
<span css={
60+
css`
61+
${tw`text-base text-white whitespace-pre`}
62+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
63+
`}>{error}</span>
64+
</div>
65+
</div>
66+
</div>) : (
67+
<>
68+
<div css={tw`flex flex-col md:flex-row flex-grow flex-shrink h-full max-w-full`}>
69+
<TextBox title={"ChatChat formats.yml"}
70+
code={!parsedConfig ? "" : parsedConfig.format}
71+
language={"yaml"}/>
72+
</div>
73+
{/*<div css={tw`h-1/2`}>*/}
74+
{/* <TextBox title={"ChatChat settings.yml"}*/}
75+
{/* code={!parsedConfig ? "" : parsedConfig.settings}*/}
76+
{/* language={"yaml"}/>*/}
77+
{/*</div>*/}
78+
</>
79+
)
80+
}
81+
</div>
82+
</div>
83+
</main>
84+
</div>
85+
)
86+
}
87+
88+
export default Home

0 commit comments

Comments
 (0)