diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-06-28 21:09:46 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-06-28 21:09:46 +0200 |
commit | eef139412c15d236fb797262a36f9e75fea860d9 (patch) | |
tree | 5ab8a83fa9af23fb7e090d48deba195c661a24f5 /webclient/client.html | |
parent | 0fafc1469701dfd6e4ae81dfc27fddb905ad602f (diff) |
webclient: /help command
Diffstat (limited to 'webclient/client.html')
-rw-r--r-- | webclient/client.html | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/webclient/client.html b/webclient/client.html index 57eee90..766b035 100644 --- a/webclient/client.html +++ b/webclient/client.html @@ -9,6 +9,15 @@ var roomlist=[":console"]; var currentroom=":console"; var roomlogs=new Map([[":console",[]]]); +var commandlist=[ + {cmd:"register",usage:"/register <username> <password>"}, + {cmd:"login",usage:"/login <username> <password>"}, + {cmd:"createroom",usage:"/createroom"}, + {cmd:"invite",usage:"/invite <username> (adds to current room)"}, + {cmd:"shrug",usage:"/shrug (sends '¯\\_(ツ)_/¯')"}, + {cmd:"help",usage:"/help (show list of commands)"} +]; + var uniqid=(function(){ var id=1; return function uniqid(){ @@ -296,6 +305,16 @@ function addRoomEntry(roomid,type,args){ } } +function showUsage(roomid,cmd){ + for(var i=0;i<commandlist.length;i++){ + if(commandlist[i].cmd==cmd){ + addRoomEntry(roomid,"error",[now(),"Usage: "+commandlist[i].usage]); + return; + } + } + throw new Error("No usage registered for command '"+cnd+"'!"); +} + function executeCommand(roomid,text){ var spl=fancySplit(text,true); if(spl.word.length==0)return; @@ -305,7 +324,7 @@ function executeCommand(roomid,text){ case "register": case "login": if(spl.word.length<3){ - addRoomEntry(roomid,"error",[now(),"Usage: /"+cmd+" <username> <password>"]); + showUsage(roomid,cmd); break; } creds=[spl.word[1],spl.rest[2]]; @@ -325,7 +344,7 @@ function executeCommand(roomid,text){ case "createroom": if(spl.word.length!=1){ - addRoomEntry(roomid,"error",[now(),"Usage: /createroom"]); + showUsage(roomid,cmd); break; } if(!username){ @@ -344,7 +363,7 @@ function executeCommand(roomid,text){ case "invite": if(spl.word.length<2){ - addRoomEntry(roomid,"error",[now(),"Usage: /invite <username> (adds to current room)"]); + showUsage(roomid,cmd); break; } if(!username){ @@ -369,6 +388,12 @@ function executeCommand(roomid,text){ sendMessage(roomid,"¯\\_(ツ)_/¯"); break; + case "help": + for(var i=0;i<commandlist.length;i++){ + addRoomEntry(roomid,"notice",[now(),commandlist[i].usage]); + } + break; + default: addRoomEntry(roomid,"error",[now(),"Unknown command '"+cmd+"'"]); break; |