Skip to content

Instantly share code, notes, and snippets.

@Haspaker

Haspaker/Mescode.ls

Last active Aug 29, 2015
Embed
What would you like to do?
settings =
encode: no
translate: yes
ask_server = (method, message) ->
xhttp = new XMLHttpRequest()
xhttp
..open("GET", "http://mrdvpfr.appspot.com?#method=#message", false)
..setRequestHeader("Content-Type","text/javascript")
..send!
return xhttp.responseText - /^__Result:__ /
function processUserCommand command, args, connection, view
args /= ' '
unless command is \mescode => return
switch args.0
| \on =>
settings.encode = yes
view.addEventMessageToDisplay 'You are now speaking mescode!', \mescode:on, null
| \off =>
settings.encode = no
view.addEventMessageToDisplay 'You are no longer speaking mescode... :(', \mescode:off, null
| \translate =>
switch args.1
| \on =>
settings.translate = yes
view.addEventMessageToDisplay 'You can now understand mescode!', \translate:on, null
| \off =>
settings.translate = off
view.addEventMessageToDisplay 'You can no longer understand mescode... :(', \translate:off, null
| \encode =>
message = args[1 til] * ' '
encoded_message = ask_server \encode message
encoded_message -= /^pgauigh: /
view.addEventMessageToDisplay "Encoded message: #encoded_message", \encoded_message, null
| \decode =>
message = args[1 til] * ' '
decoded_message = ask_server \decode message
view.addEventMessageToDisplay "Decoded message: #decoded_message", \decoded_message, null
function processIncomingMessage message, view
if settings.translate and message is /^pgauigh:\s/
decoded_message =
ask_server \decode (message - /^pgauigh: /)
message.setBody decoded_message
function processOutgoingMessage message, view
if settings.encode
encoded_message = ask_server \encode message
message.setBody encoded_message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.