Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
Rename CommandParser to MessageParser
Browse files Browse the repository at this point in the history
  • Loading branch information
sirDonovan committed Jun 27, 2017
1 parent 113eaa5 commit 075ba87
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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'
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
Expand Down
2 changes: 1 addition & 1 deletion globals.ts
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 5 additions & 5 deletions command-parser.js → message-parser.js
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -73,7 +73,7 @@ class Context {

exports.Context = Context;

class CommandParser {
class MessageParser {
constructor() {
this.globalContext = new Context('', Rooms.globalRoom, Users.self, '');
}
Expand All @@ -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;

Expand All @@ -110,4 +110,4 @@ class CommandParser {
}
}

exports.CommandParser = new CommandParser();
exports.MessageParser = new MessageParser();
2 changes: 1 addition & 1 deletion node.d.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:': {
Expand All @@ -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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/modules/games.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
}
Expand Down

0 comments on commit 075ba87

Please sign in to comment.