X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=engine%2Fchatcommands.js;h=9e66fec5df7252b7e079068b87bcfa9031b251dc;hb=ab08df8f4a6588ea3541a187cccce5c3c559459a;hp=acec78c3c09c27d642be049b9627e36d8991bf24;hpb=7dbc5032b29febdc34ef802151c48681c23c1deb;p=dragonblocks.git diff --git a/engine/chatcommands.js b/engine/chatcommands.js index acec78c..9e66fec 100644 --- a/engine/chatcommands.js +++ b/engine/chatcommands.js @@ -1,49 +1,59 @@ /* * chatcommands.js - * + * * Copyright 2020 Elias Fleckenstein - * + * * 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 " + e.toString() + ""); + catch (err) { + dragonblocks.chatMessage("!HTML " + err.toString() + ""); } - } - else + } else { dragonblocks.chatMessage("Invalid Command: " + command); + } + return false; });