Skip to content

Commit 2109a39

Browse files
committed
Initial Attempt at VentureChat
1 parent a90714b commit 2109a39

File tree

5 files changed

+305
-0
lines changed

5 files changed

+305
-0
lines changed

converters/chatchat/venturechat.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import Converter from '../converter';
2+
import {VentureChatConfig, VentureChatFormat, VentureChatJsonComponent} from "../types/venturechat";
3+
import {ChatChatFormat, ChatChatFormatsConfig, ChatChatSettingsConfig} from "../types/chatchat";
4+
import MiniMessage from "../minimessage";
5+
6+
const schema = require('../types/venturechat.json');
7+
8+
const ChatChatVentureChatConverter = new Converter<VentureChatConfig, {format: ChatChatFormatsConfig, settings: ChatChatSettingsConfig}>({
9+
Convert(venturechatConfig) {
10+
const chatchatFormatsConfig: ChatChatFormatsConfig = {
11+
"default-format": 'default',
12+
formats: {}
13+
}
14+
const chatchatSettingsConfig: ChatChatSettingsConfig = {
15+
"sender-format": {
16+
parts: []
17+
},
18+
"recipient-format": {
19+
parts: []
20+
},
21+
}
22+
23+
if (venturechatConfig.jsonformatting) {
24+
const formats = venturechatConfig.jsonformatting;
25+
Object.keys(formats).forEach(name => {
26+
const vcFormat = formats[name];
27+
const ccFormat: ChatChatFormat = {
28+
priority: vcFormat.priority ?? 1,
29+
parts: []
30+
};
31+
32+
let key = 0;
33+
34+
// todo get the possible key from the object?
35+
([vcFormat.json_attributes.venturechat_channel_prefix, vcFormat.json_attributes.vault_prefix, vcFormat.json_attributes.player_displayname]).forEach(section => {
36+
let part = "";
37+
switch(key) {
38+
case 0:
39+
part = "%venturechat_channel_prefix%";
40+
break;
41+
case 1:
42+
part = "%vault_prefix%";
43+
break;
44+
case 2:
45+
part = "%player_displayname%";
46+
break;
47+
}
48+
console.log(key);
49+
key++;
50+
let formattedSection = part;
51+
switch(section.click_action) {
52+
case "suggest_command": {
53+
formattedSection = "<click:suggest_command:'" + section.click_text + "'>" + formattedSection + "</click>";
54+
break;
55+
}
56+
case "run_command": {
57+
formattedSection = "<click:run_command:'" + section.click_text + "'>" + formattedSection + "</click>";
58+
break;
59+
}
60+
case "open_url": {
61+
formattedSection = "<click:open_url:'" + section.click_text + "'>" + formattedSection + "</click>";
62+
break;
63+
}
64+
}
65+
let hover: string[] = (<string[]>section.hover_text).filter(s => s && s !== "")
66+
if (hover && hover.length > 0) {
67+
formattedSection = "<hover:show_text:'" + hover.join("<newline>") + "'>" + formattedSection + "</hover>";
68+
}
69+
70+
if (formattedSection !== "") {
71+
ccFormat.parts.push(MiniMessage(formattedSection));
72+
}
73+
})
74+
ccFormat.parts.push("<message>")
75+
chatchatFormatsConfig.formats[name] = ccFormat;
76+
})
77+
}
78+
79+
80+
const toFormat = venturechatConfig.tellformatto;
81+
const fromFormat = venturechatConfig.tellformatfrom;
82+
83+
let ccPartsFormat: string[] = [];
84+
85+
// The sender format
86+
ccPartsFormat.push(MiniMessage(toFormat));
87+
ccPartsFormat.push("<message>");
88+
chatchatSettingsConfig["sender-format"].parts = ccPartsFormat;
89+
90+
// Reset
91+
ccPartsFormat = [];
92+
93+
// The recipient format
94+
ccPartsFormat.push(MiniMessage(fromFormat));
95+
ccPartsFormat.push("<message>");
96+
chatchatSettingsConfig["recipient-format"].parts = ccPartsFormat;
97+
98+
return {
99+
format: chatchatFormatsConfig,
100+
settings: chatchatSettingsConfig
101+
}
102+
},
103+
inputSchema: schema,
104+
});
105+
106+
export default ChatChatVentureChatConverter;

converters/types/venturechat.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/VentureChatConfig",
4+
"definitions": {
5+
"VentureChatConfig": {
6+
"type": "object",
7+
"properties": {
8+
"tellformatto": {
9+
"type": "string"
10+
},
11+
"tellformatfrom": {
12+
"type": "string"
13+
},
14+
"jsonformatting": {
15+
"type": "object",
16+
"additionalProperties": {
17+
"$ref": "#/definitions/VentureChatFormat"
18+
}
19+
}
20+
},
21+
"required": [
22+
"tellformatto",
23+
"tellformatfrom"
24+
],
25+
"additionalProperties": false
26+
},
27+
"VentureChatFormat": {
28+
"type": "object",
29+
"properties": {
30+
"priority": {
31+
"type": "number"
32+
},
33+
"json_attributes": {
34+
"type": "object",
35+
"properties": {
36+
"player_displayname": {
37+
"$ref": "#/definitions/VentureChatJsonComponent"
38+
},
39+
"vault_prefix": {
40+
"$ref": "#/definitions/VentureChatJsonComponent"
41+
},
42+
"venturechat_channel_prefix": {
43+
"$ref": "#/definitions/VentureChatJsonComponent"
44+
}
45+
},
46+
"required": [
47+
"player_displayname",
48+
"vault_prefix",
49+
"venturechat_channel_prefix"
50+
],
51+
"additionalProperties": false
52+
}
53+
},
54+
"required": [
55+
"priority",
56+
"json_attributes"
57+
],
58+
"additionalProperties": false
59+
},
60+
"VentureChatJsonComponent": {
61+
"type": "object",
62+
"properties": {
63+
"hover_text": {
64+
"type": "array",
65+
"items": {
66+
"type": "string"
67+
}
68+
},
69+
"click_action": {
70+
"type": "string"
71+
},
72+
"click_text": {
73+
"type": "string"
74+
}
75+
},
76+
"required": [
77+
"hover_text",
78+
"click_action",
79+
"click_text"
80+
],
81+
"additionalProperties": false
82+
}
83+
}
84+
}

converters/types/venturechat.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @ToolBox - VentureChatConfig
2+
3+
export interface VentureChatConfig {
4+
tellformatto: string
5+
tellformatfrom: string
6+
jsonformatting?: {
7+
[key: string]: VentureChatFormat;
8+
}
9+
}
10+
11+
export interface VentureChatFormat {
12+
priority: number;
13+
json_attributes: {
14+
player_displayname: VentureChatJsonComponent
15+
vault_prefix: VentureChatJsonComponent
16+
venturechat_channel_prefix: VentureChatJsonComponent
17+
}
18+
}
19+
20+
export interface VentureChatJsonComponent {
21+
hover_text: string[]
22+
click_action: string
23+
click_text: string
24+
}

pages/_app.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ function Converter({Component, pageProps}: AppProps) {
2323
<Link href={'/converters/chatchat/essentialschat'}>
2424
<p>EssentialsChat</p>
2525
</Link>
26+
<Link href={'/converters/chatchat/venturechat'}>
27+
<p>VentureChat</p>
28+
</Link>
2629
</Collapsable>
2730
</Collapsable>
2831
<Collapsable name={'Validators'}>
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 ChatChatVentureChatConverter from "../../../converters/chatchat/venturechat";
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 = ChatChatVentureChatConverter.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>VentureChat to ChatChat Converter</title>
31+
<meta name="description" content="Convert VentureChat 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`}>VentureChat 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={"VentureChat 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)