From 075ba8795154dc0492ef07dd23befa5858ec2ed7 Mon Sep 17 00:00:00 2001 From: sirDonovan Date: Tue, 27 Jun 2017 16:00:43 -0500 Subject: [PATCH] Rename CommandParser to MessageParser --- .eslintrc | 2 +- app.js | 2 +- client.js | 2 +- global.d.ts | 4 ++-- globals.ts | 2 +- command-parser.js => message-parser.js | 10 +++++----- node.d.ts | 2 +- rooms.js | 4 ++-- test/modules/games.js | 6 +++--- 9 files changed, 17 insertions(+), 17 deletions(-) rename command-parser.js => message-parser.js (93%) diff --git a/.eslintrc b/.eslintrc index 132e6e8..61a9d3b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,7 +5,7 @@ }, "root": true, "globals": { - "Client": false, "Commands": false, "CommandParser": false, "Config": false, + "Client": false, "Commands": false, "MessageParser": false, "Config": false, "Rooms": false, "Tools": false, "Users": false, "Games": false, "Storage": false, "toId": false }, diff --git a/app.js b/app.js index 05c16b8..c8390c2 100644 --- a/app.js +++ b/app.js @@ -30,7 +30,7 @@ global.Rooms = require('./rooms.js').Rooms; global.Users = require('./users.js').Users; -global.CommandParser = require('./command-parser.js').CommandParser; +global.MessageParser = require('./message-parser.js').MessageParser; global.Client = require('./client.js'); diff --git a/client.js b/client.js index 0f93e30..934fa41 100644 --- a/client.js +++ b/client.js @@ -191,7 +191,7 @@ class Client { let user = Users.add(splitMessage[0]); if (!user) return; if (user.id === Users.self.id) return; - CommandParser.parse(splitMessage.slice(2).join('|'), user, user); + MessageParser.parseCommand(splitMessage.slice(2).join('|'), user, user); break; default: room.parseMessage(messageType, splitMessage); diff --git a/global.d.ts b/global.d.ts index 146529d..184e030 100644 --- a/global.d.ts +++ b/global.d.ts @@ -1,8 +1,8 @@ import * as ClientType from './client' -import * as CommandParserType from './command-parser' import * as CommandsType from './commands' import * as ConfigType from './config-example' import * as GamesType from './games' +import * as MessageParserType from './message-parser' import * as RoomsType from './rooms' import * as StorageType from './storage' import * as ToolsType from './tools' @@ -10,10 +10,10 @@ import * as UsersType from './users' declare global { const Client: typeof ClientType - const CommandParser: typeof CommandParserType.CommandParser const Commands: typeof CommandsType const Config: typeof ConfigType const Games: typeof GamesType.Games + const MessageParser: typeof MessageParserType.MessageParser const Rooms: typeof RoomsType.Rooms const Storage: typeof StorageType const Tools: typeof ToolsType diff --git a/globals.ts b/globals.ts index d4fee97..2eaeb72 100644 --- a/globals.ts +++ b/globals.ts @@ -1,3 +1,3 @@ interface Command { - (this: typeof CommandParser.globalContext, target: string, room: typeof Rooms.globalRoom | typeof Users.self, user: typeof Users.self, cmd?: string, time?: number): void; + (this: typeof MessageParser.globalContext, target: string, room: typeof Rooms.globalRoom | typeof Users.self, user: typeof Users.self, cmd?: string, time?: number): void; } diff --git a/command-parser.js b/message-parser.js similarity index 93% rename from command-parser.js rename to message-parser.js index 282fe63..78d20a9 100644 --- a/command-parser.js +++ b/message-parser.js @@ -1,8 +1,8 @@ /** - * Command Parser + * Message Parser * Cassius - https://github.com/sirDonovan/Cassius * - * This file parses command messages. + * This file parses messages sent by the server. * * @license MIT license */ @@ -73,7 +73,7 @@ class Context { exports.Context = Context; -class CommandParser { +class MessageParser { constructor() { this.globalContext = new Context('', Rooms.globalRoom, Users.self, ''); } @@ -84,7 +84,7 @@ class CommandParser { * @param {User} user * @param {number} [time] */ - parse(message, room, user, time) { + parseCommand(message, room, user, time) { message = message.trim(); if (message.charAt(0) !== Config.commandCharacter) return; @@ -110,4 +110,4 @@ class CommandParser { } } -exports.CommandParser = new CommandParser(); +exports.MessageParser = new MessageParser(); diff --git a/node.d.ts b/node.d.ts index 45b0a93..05ba555 100644 --- a/node.d.ts +++ b/node.d.ts @@ -1,10 +1,10 @@ declare namespace NodeJS { interface Global { Client: any - CommandParser: any Commands: any Config: any Games: any + MessageParser: any Rooms: any Storage: any Tools: any diff --git a/rooms.js b/rooms.js index 16c69a2..214c957 100644 --- a/rooms.js +++ b/rooms.js @@ -126,7 +126,7 @@ class Room { if (message in this.listeners) this.listeners[message](); return; } - CommandParser.parse(message, this, user); + MessageParser.parseCommand(message, this, user); break; } case 'c:': { @@ -140,7 +140,7 @@ class Room { if (message in this.listeners) this.listeners[message](); return; } - CommandParser.parse(message, this, user, parseInt(splitMessage[0]) * 1000); + MessageParser.parseCommand(message, this, user, parseInt(splitMessage[0]) * 1000); break; } } diff --git a/test/modules/games.js b/test/modules/games.js index b1cfe61..867e195 100644 --- a/test/modules/games.js +++ b/test/modules/games.js @@ -72,7 +72,7 @@ describe('Games', function () { if (!room.game.freeJoin) { let len = users.length; for (let i = 0; i < len; i++) { - CommandParser.parse(Config.commandCharacter + 'joingame', room, users[i]); + MessageParser.parseCommand(Config.commandCharacter + 'joingame', room, users[i]); } assert.strictEqual(room.game.playerCount, len); room.game.start(); @@ -89,7 +89,7 @@ describe('Games', function () { if (!room.game.freeJoin) { room.game.signups(); for (let i = 0, len = users.length; i < len; i++) { - CommandParser.parse(Config.commandCharacter + 'joingame', room, users[i]); + MessageParser.parseCommand(Config.commandCharacter + 'joingame', room, users[i]); } room.game.start(); room.game.end(); @@ -99,7 +99,7 @@ describe('Games', function () { room.game.signups(); if (!room.game.freeJoin) { for (let i = 0, len = users.length; i < len; i++) { - CommandParser.parse(Config.commandCharacter + 'joingame', room, users[i]); + MessageParser.parseCommand(Config.commandCharacter + 'joingame', room, users[i]); } room.game.start(); }