Skip to content

Commit

Permalink
EXTRA COLOR CODES
Browse files Browse the repository at this point in the history
now we have color codes not present in mc:
&i:
	a&ib&i when you shift-click a, the content of your chat box is replaced by "b"
&g: click actions
	&gs:
		a&gub&i: like &i, but without shift
	&gu:
		go to xkcd&guxkcd.com&g: goes to http://xkcd.com
	&gr:
		creative&gr/gm 1&g: changes mode to creative. can also be used to send chat
	&gp:
		go to page 42&gp42&g: in a book, it changes the page to 42
&h:
	hi&hhow are you&h: when hi is hovered, "How are you" is shown
  • Loading branch information
FranchuFranchu committed Jan 22, 2019
1 parent 3979da3 commit b1a31d6
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 49 deletions.
193 changes: 144 additions & 49 deletions lib/colorCodes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,162 @@
"""
This library implements basic mc color codes, plus a few more:
&i:
a&ib&i when you shift-click a, the content of your chat box is replaced by "b"
&g: click actions
&gs:
a&gub&i: like &i, but without shift
&gu:
go to xkcd&guxkcd.com&g: goes to http://xkcd.com
&gr:
creative&gr/gm 1&g: changes mode to creative. can also be used to send chat
&gp:
go to page 42&gp42&g: in a book, it changes the page to 42
&h:
hi&hhow are you&h: when hi is hovered, "How are you" is shown
"""

import json
def to_json(string):
l = [""]
dl = {'text':'','bold':False,'italic':False,'underline':False,'obfuscated':False,'strike':False,'color':'white'}
dl = {'text':'','clickEvent':{"action":"","value":"" },'hoverEvent':{"action":"","value":"" },'bold':False,'italic':False,'underline':False,'obfuscated':False,'strike':False,'color':'white'}
curr = ''
nextIsColorCode = False
nextIsClick = False
nextIsHover = False
compData = ''
isCurrentlyInsertingText = False
for i in string:
if i == '&':
nextIsColorCode = True
elif nextIsClick:
if i == 'u':
dl['clickEvent']['action'] = 'open_url'
elif i == 'r':
dl['clickEvent']['action'] = 'run_command'
elif i == 's':
dl['clickEvent']['action'] = 'suggest_command'
elif i == 'p':
dl['clickEvent']['action'] = 'change_page'
print('Augh!')
nextIsClick = False
isCurrentlyInsertingText = True

elif nextIsHover:
dl['hoverEvent']['action'] = 'show_text'
isCurrentlyInsertingText = True
nextIsHover = False
elif nextIsColorCode:
dl['text'] = curr
curr = ''
l.append(dl.copy())
dl['text'] = ''
i = i.lower()
if i == "i":
if isCurrentlyInsertingText:
print('compData')
dl['insertion'] = compData
compData = ''
isCurrentlyInsertingText = False

else:
print('das')
isCurrentlyInsertingText = True
elif i == 'g': #click events
if isCurrentlyInsertingText:
if dl['clickEvent']['action'] == 'change_page':
try:
compData = int(compData)
except ValueError:
compData = 1
elif dl['clickEvent']['action'] == 'open_url':
if not(compData.startswith('http://') or compData.startswith('https://')):
compData = 'http://'+compData
print('cddasdsa',compData)
dl['clickEvent']['value'] = compData
compData = ''
print('cddasdsa',compData)
nextIsClick = not nextIsClick
isCurrentlyInsertingText = False
elif i == 'h':
nextIsHover = not nextIsHover
isCurrentlyInsertingText = False
else:
dl['text'] = curr
curr = ''
l.append(dl.copy())
dl['text'] = ''
if i == 'l':
dl['bold'] = not dl['bold']
elif i == 'o':
dl['italic'] = not dl['italic']
elif i == 'k':
dl['obfuscated'] = not dl['obfuscated']
elif i == 'm':
dl['strike'] = not dl['strike']
elif i == 'n':
dl['underline'] = not dl['underline']
elif i == "4":
dl['color'] = "dark_red"
elif i == "c":
dl['color'] = "red"
elif i == "6":
dl['color'] = "gold"
elif i == "e":
dl['color'] = "yellow"
elif i == "2":
dl['color'] = "dark_green"
elif i == "a":
dl['color'] = "green"
elif i == "b":
dl['color'] = "aqua"
elif i == "3":
dl['color'] = "dark_aqua"
elif i == "1":
dl['color'] = "dark_blue"
elif i == "9":
dl['color'] = "blue"
elif i == "d":
dl['color'] = "light_purple"
elif i == "5":
dl['color'] = "dark_purple"
elif i == "f":
dl['color'] = "white"
elif i == "7":
dl['color'] = "gray"
elif i == "8":
dl['color'] = "dark_gray"
elif i == "0":
dl['color'] = "black"
elif i == "r":
dl = {**dl,**{'bold':False,'italic':False,'underline':False,'obfuscated':False,'strike':False,'color':'white'}}
nextIsColorCode = False
if i == 'l':
dl['bold'] = not dl['bold']
elif i == 'o':
dl['italic'] = not dl['italic']
elif i == 'k':
dl['obfuscated'] = not dl['obfuscated']
elif i == 'm':
dl['strike'] = not dl['strike']
elif i == 'n':
dl['underline'] = not dl['underline']
elif i == "4":
dl['color'] = "dark_red"
elif i == "c":
dl['color'] = "red"
elif i == "6":
dl['color'] = "gold"
elif i == "e":
dl['color'] = "yellow"
elif i == "2":
dl['color'] = "dark_green"
elif i == "a":
dl['color'] = "green"
elif i == "b":
dl['color'] = "aqua"
elif i == "3":
dl['color'] = "dark_aqua"
elif i == "1":
dl['color'] = "dark_blue"
elif i == "9":
dl['color'] = "blue"
elif i == "d":
dl['color'] = "light_purple"
elif i == "5":
dl['color'] = "dark_purple"
elif i == "f":
dl['color'] = "white"
elif i == "7":
dl['color'] = "gray"
elif i == "8":
dl['color'] = "dark_gray"
elif i == "0":
dl['color'] = "black"
elif i == "r":
dl = {**dl,**{'bold':False,'italic':False,'underline':False,'obfuscated':False,'strike':False,'color':'white'}}

elif isCurrentlyInsertingText:
print(compData)
compData+=i
else:
curr += i
dl['text'] = curr
curr = ''
l.append(dl)
for i in l:
if type(i) == dict:
if i['clickEvent'] == {"action":"","value":"" }:
del l[l.index(i)]['clickEvent']
if i['hoverEvent'] == {"action":"","value":"" }:
del l[l.index(i)]['hoverEvent']

if i['bold'] == False:
del l[l.index(i)]['bold']
if i['italic'] == False:
del l[l.index(i)]['italic']
if i['obfuscated'] == False:
del l[l.index(i)]['obfuscated']
if i['strike'] == False:
del l[l.index(i)]['strike']
if i['underline'] == False:
del l[l.index(i)]['underline']
if i['color'] == 'white':
del l[l.index(i)]['color']
if i['text'] == '':
del l[l.index(i)]
print('l',l)
print('JSON',l)
return l
Binary file modified lib/colorCodes/__pycache__/__init__.cpython-36.pyc
Binary file not shown.

0 comments on commit b1a31d6

Please sign in to comment.