-
-
Save jashkenas/581954 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Client() { | |
| this.state = "loggedoff" | |
| } | |
| //attempt to say something, will attempt login every time and keep you at as far as you have gotten | |
| Client.prototype.say = function(msg) { | |
| switch(this.state) { | |
| case "loggedoff": | |
| this.queueLogin() | |
| case "authenticated": | |
| this.queueVoiceRequest() | |
| case "voiced": | |
| this.queueMessage(msg) | |
| break | |
| //banned etc. | |
| default: | |
| throw "not allowed" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Client | |
| constructor: -> | |
| @state = 'loggedoff' | |
| say: (msg) -> | |
| switch @state | |
| when 'loggedoff' then @queueLogin() | |
| when 'authenticated' then @queueVoiceRequest() | |
| when 'voiced' then @queueMessage() | |
| else | |
| throw 'not allowed' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment