Skip to content

Commit f1e0d29

Browse files
committed
Essentials DMs
1 parent 2109a39 commit f1e0d29

File tree

13 files changed

+130
-53
lines changed

13 files changed

+130
-53
lines changed

cli/generateschema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ directory.forEach((f: string) => {
1616
const schema = tsj.createGenerator({
1717
path: `./converters/types/${f}`,
1818
tsconfig: './tsconfig.json',
19-
type: match[1]
19+
type: match[1],
20+
additionalProperties: true,
2021
}).createSchema(match[1])
2122

2223
const schemaString = JSON.stringify(schema, null, 2);

components/TextBox.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import tw, {css} from "twin.macro";
2-
import Highlight, {defaultProps, Language} from "prism-react-renderer";
2+
import Highlight, {defaultProps} from "prism-react-renderer";
3+
import Prism from 'prismjs';
34
import {Dispatch, SetStateAction} from "react";
45
import Editor from 'react-simple-code-editor'
56
import {faCopy} from '@fortawesome/free-solid-svg-icons'
67
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
8+
import "prismjs/components/prism-yaml"
9+
import "prismjs/components/prism-properties"
710

811
const textBoxStyle = tw`flex-grow flex-shrink border-none outline-none focus:outline-none max-h-full`;
912

@@ -18,7 +21,7 @@ export const TextBox = (
1821
title: string,
1922
code: string,
2023
editor?: Dispatch<SetStateAction<string>>,
21-
language: Language
24+
language: string
2225
}
2326
) => {
2427

@@ -80,8 +83,9 @@ export const TextBox = (
8083
}
8184
}
8285

83-
function highlight(code: string, language: Language) {
84-
return (<Highlight {...defaultProps} code={code} language={language}>
86+
function highlight(code: string, language: string) {
87+
// @ts-ignore (Prism is odd)
88+
return (<Highlight {...defaultProps} Prism={Prism} code={code} language={language}>
8589
{({className, style, tokens, getLineProps, getTokenProps}) => (
8690
<pre className={className} style={style} css={textBoxStyle}>
8791
{tokens.map((line, i) => (

converters/chatchat/essentialschat.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Converter from "../converter";
2-
import {EssentialsChatConfig} from "../types/essentialschat";
2+
import {EssentialsChatTypes} from "../types/essentialschat";
33
import {ChatChatFormat, ChatChatFormatsConfig, ChatChatSettingsConfig} from "../types/chatchat";
44
import MiniMessage from "../minimessage";
55
import Placeholders from "../placeholders";
66

77
const schema = require('../types/essentialschat.json')
88

9-
const ChatChatEssentialsChatConverter = new Converter<EssentialsChatConfig, { format: ChatChatFormatsConfig, settings: ChatChatSettingsConfig }>({
9+
const ChatChatEssentialsChatConverter = new Converter<EssentialsChatTypes, { format: ChatChatFormatsConfig, settings: ChatChatSettingsConfig }>({
1010
Convert(essentialschatConfig) {
1111
const chatchatFormatsConfig: ChatChatFormatsConfig = {
1212
"default-format": 'default',
@@ -21,8 +21,15 @@ const ChatChatEssentialsChatConverter = new Converter<EssentialsChatConfig, { fo
2121
},
2222
}
2323

24-
if (essentialschatConfig.format) {
25-
const format = essentialschatConfig.format;
24+
if (!essentialschatConfig.config) {
25+
return {
26+
error: true,
27+
message: 'EssentialsChat config is missing'
28+
}
29+
}
30+
31+
if (essentialschatConfig.config.format) {
32+
const format = essentialschatConfig.config.format;
2633
const ccFormat: ChatChatFormat = {
2734
priority: 1,
2835
parts: []
@@ -34,8 +41,8 @@ const ChatChatEssentialsChatConverter = new Converter<EssentialsChatConfig, { fo
3441

3542
let formatCount = 1;
3643

37-
if (essentialschatConfig["group-formats"]) {
38-
const formats = essentialschatConfig["group-formats"]
44+
if (essentialschatConfig.config["group-formats"]) {
45+
const formats = essentialschatConfig.config["group-formats"]
3946
Object.keys(formats).forEach(name => {
4047
const ecFormat = formats[name]
4148
const ccFormat: ChatChatFormat = {
@@ -49,6 +56,11 @@ const ChatChatEssentialsChatConverter = new Converter<EssentialsChatConfig, { fo
4956
});
5057
}
5158

59+
if (essentialschatConfig.language.msgFormat) {
60+
chatchatSettingsConfig["sender-format"].parts.push(
61+
essentialschatConfig.language.msgFormat
62+
);
63+
}
5264

5365
return {
5466
format: chatchatFormatsConfig,

converters/converter.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@ export default class Converter<InputConfig extends object, OutputConfigs extends
99
this.conversion = conversion
1010
}
1111

12-
convert(input: string): Record<keyof OutputConfigs, string> | ConversionError {
12+
convert(input: any): Record<keyof OutputConfigs, string> | ConversionError {
1313

14-
let untypedInputConfig;
14+
let untypedInputConfig: any;
1515

1616
try {
17-
untypedInputConfig = parse(input);
17+
if (typeof input === 'string') {
18+
untypedInputConfig = parse(input)
19+
} else {
20+
untypedInputConfig = {};
21+
for (const key of Object.keys(input)) {
22+
if (typeof input[key] === 'string') {
23+
untypedInputConfig[key] = parse(input[key])
24+
} else {
25+
untypedInputConfig[key] = input[key]
26+
}
27+
}
28+
}
1829
} catch (e: any) {
1930
return {
2031
message: e.message ?? "Error parsing input",

converters/types/deluxechat.json

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
"type": "string"
3636
}
3737
}
38-
},
39-
"additionalProperties": false
38+
}
4039
},
4140
"relation_placeholders_enabled": {
4241
"type": "boolean"
@@ -53,8 +52,7 @@
5352
"false": {
5453
"type": "string"
5554
}
56-
},
57-
"additionalProperties": false
55+
}
5856
},
5957
"ops_use_group_format": {
6058
"type": "boolean"
@@ -74,8 +72,7 @@
7472
"type": "string"
7573
}
7674
}
77-
},
78-
"additionalProperties": false
75+
}
7976
},
8077
"private_message": {
8178
"type": "object",
@@ -86,12 +83,10 @@
8683
"bungeecord": {
8784
"type": "boolean"
8885
}
89-
},
90-
"additionalProperties": false
86+
}
9187
},
9288
"private_message_formats": {
9389
"type": "object",
94-
"additionalProperties": false,
9590
"properties": {
9691
"social_spy": {
9792
"type": "string"
@@ -114,8 +109,7 @@
114109
"$ref": "#/definitions/DeluxeChatFormat"
115110
}
116111
}
117-
},
118-
"additionalProperties": false
112+
}
119113
},
120114
"DeluxeChatPrivateMessageFormat": {
121115
"type": "object",
@@ -135,8 +129,7 @@
135129
"chat_color": {
136130
"type": "string"
137131
}
138-
},
139-
"additionalProperties": false
132+
}
140133
},
141134
"DeluxeChatFormat": {
142135
"type": "object",
@@ -206,8 +199,7 @@
206199
"name",
207200
"suffix",
208201
"chat_color"
209-
],
210-
"additionalProperties": false
202+
]
211203
}
212204
}
213205
}

converters/types/essentialschat.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"type": "string"
1515
}
1616
}
17-
},
18-
"additionalProperties": false
17+
}
1918
}
2019
}
2120
}

converters/types/essentialschat.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ export interface EssentialsChatConfig {
66
[key: string]: string
77
}
88
}
9+
10+
export interface EssentialsChatTypes {
11+
config: EssentialsChatConfig
12+
language: {
13+
msgFormat: string
14+
}
15+
}

converters/types/venturechat.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"required": [
2222
"tellformatto",
2323
"tellformatfrom"
24-
],
25-
"additionalProperties": false
24+
]
2625
},
2726
"VentureChatFormat": {
2827
"type": "object",
@@ -47,15 +46,13 @@
4746
"player_displayname",
4847
"vault_prefix",
4948
"venturechat_channel_prefix"
50-
],
51-
"additionalProperties": false
49+
]
5250
}
5351
},
5452
"required": [
5553
"priority",
5654
"json_attributes"
57-
],
58-
"additionalProperties": false
55+
]
5956
},
6057
"VentureChatJsonComponent": {
6158
"type": "object",
@@ -77,8 +74,7 @@
7774
"hover_text",
7875
"click_action",
7976
"click_text"
80-
],
81-
"additionalProperties": false
77+
]
8278
}
8379
}
8480
}

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
"@fortawesome/fontawesome-svg-core": "^6.1.0",
1515
"@fortawesome/free-solid-svg-icons": "^6.1.0",
1616
"@fortawesome/react-fontawesome": "^0.1.18",
17+
"@js.properties/properties": "^0.5.4",
1718
"ajv": "^8.10.0",
1819
"next": "12.1.0",
1920
"prism-react-renderer": "^1.3.1",
21+
"prismjs": "^1.27.0",
2022
"react": "17.0.2",
2123
"react-dom": "17.0.2",
2224
"react-json-view": "^1.21.3",
@@ -26,13 +28,15 @@
2628
},
2729
"devDependencies": {
2830
"@types/node": "17.0.21",
31+
"@types/prismjs": "^1.26.0",
2932
"@types/react": "17.0.40",
3033
"@types/styled-components": "^5.1.24",
3134
"babel-plugin-macros": "^3.1.0",
3235
"eslint": "8.11.0",
3336
"eslint-config-next": "12.1.0",
3437
"tailwindcss": "^3.0.23",
3538
"ts-json-schema-generator": "^0.98.0",
39+
"ts-node": "^10.7.0",
3640
"twin.macro": "^2.8.2",
3741
"typescript": "4.6.2"
3842
},

pages/_app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ function Converter({Component, pageProps}: AppProps) {
1818
<Collapsable name={"Config Converters"}>
1919
<Collapsable name={"ChatChat"}>
2020
<Link href={'/converters/chatchat/deluxechat'}>
21-
<p>DeluxeChat</p>
21+
<p css={tw`hover:cursor-pointer`}>DeluxeChat</p>
2222
</Link>
2323
<Link href={'/converters/chatchat/essentialschat'}>
24-
<p>EssentialsChat</p>
24+
<p css={tw`hover:cursor-pointer`}>EssentialsChat</p>
2525
</Link>
2626
<Link href={'/converters/chatchat/venturechat'}>
2727
<p>VentureChat</p>
@@ -30,7 +30,7 @@ function Converter({Component, pageProps}: AppProps) {
3030
</Collapsable>
3131
<Collapsable name={'Validators'}>
3232
<Link href={'/validators/yaml'}>
33-
Yaml Validator
33+
<p css={tw`hover:cursor-pointer`}>Yaml Validator</p>
3434
</Link>
3535
</Collapsable>
3636
</div>

0 commit comments

Comments
 (0)