]> git.lizzy.rs Git - dragonblocks.git/blobdiff - engine/chatcommands.js
Code style overhaul
[dragonblocks.git] / engine / chatcommands.js
index acec78c3c09c27d642be049b9627e36d8991bf24..9e66fec5df7252b7e079068b87bcfa9031b251dc 100644 (file)
@@ -1,49 +1,59 @@
 /*
  * chatcommands.js
- * 
+ *
  * Copyright 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
- * 
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA 02110-1301, USA.
- * 
- * 
- */ 
+ *
+ *
+ */
+
 dragonblocks.chatcommands = {};
-dragonblocks.registerChatcommand = function(obj){
-       if(! obj || ! obj.name)
+
+dragonblocks.registerChatcommand = def => {
+       if (! def || ! def.name)
                return;
-       obj.desc = obj.desc || obj.description || "No description";
-       obj.param = obj.param || obj.parameters || "";
-       dragonblocks.chatcommands[obj.name] = obj;
+
+       def.desc = def.desc || def.description || "No description";
+       def.param = def.param || def.params || def.parameter || def.parameters || "";
+
+       dragonblocks.chatcommands[def.name] = def;
 }
+
 dragonblocks.registerOnChatMessage(msg => {
        if( ! msg.startsWith("/"))
                return true;
+
        msg += " ";
+
        let command = msg.slice(msg.search("/") + 1, msg.search(" "));
+
        let arg = msg.slice(msg.search(" ") + 1);
        arg = arg.slice(0, arg.length - 1);
-       if(dragonblocks.chatcommands[command]){
+
+       if (dragonblocks.chatcommands[command]) {
                try {
                        dragonblocks.chatcommands[command].func(arg);
                }
-               catch(e){
-                       dragonblocks.chatMessage("!HTML <span style=\"color: red; font-width: bold\"> " + e.toString() + "</span>");
+               catch (err) {
+                       dragonblocks.chatMessage("!HTML <span style=\"color: red; font-width: bold\"> " + err.toString() + "</span>");
                }
-       }
-       else
+       } else {
                dragonblocks.chatMessage("Invalid Command: " + command);
+       }
+
        return false;
 });