Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const formattingTable = {
- l: '1',
- n: '4',
- k: '0',
- m: '0',
- o: '0',
- r: '0',
- };
- const colorTable = {
- 0: '30',
- 1: '34',
- 2: '32',
- 3: '36',
- 4: '31',
- 5: '35',
- 6: '33',
- 7: '0',
- 8: '30',
- 9: '34',
- a: '32',
- b: '36',
- c: '31',
- d: '35',
- e: '33',
- f: '37',
- };
- const motdToAnsi = (rawMotd) => {
- let currentColor = '37';
- let currentFormat = '0';
- const prefixedMotd = `§r${rawMotd}`; // Change "§" to "&" or whatever prefix the Minecraft color code is.
- const convertedMOTD = prefixedMotd.replaceAll(/§(.)/g, (arg) => { // Change this squiggly too.
- const [, code] = [...arg];
- // console.log(code)
- const newColor = colorTable[code];
- if (newColor) {
- currentColor = newColor;
- }
- const newFormat = formattingTable[code];
- if (newFormat) {
- currentFormat = newFormat;
- }
- return `\u001b[${currentFormat};0;${currentColor}m`;
- });
- return convertedMOTD;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement