E.W.O. Next / All files / src/engine/Commands/CommandsTemplate motdCommand.ts

31.25% Statements 5/16
0% Branches 0/2
0% Functions 0/4
31.25% Lines 5/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54          5x 5x   5x 5x                       5x                                                                
/**
 * @module Engine.Commands.Templates
 * Update the Motd
 */
 
import { updateMotd } from '@engine/Characters/actions';
import { CharactersTools } from '@engine/Characters/CharacterTools';
import { Character } from '@models';
import validator from 'validator';
import { Command, CommandList, CommandStatus } from '../Command';
 
export interface MotdPayload {
  mat: number;
  message: string;
}
 
export interface MotdMeta {
  Character: Character;
  message: string;
}
 
export class MotdCommand implements Command {
  public readonly command = CommandList.motd;
  public readonly payload: MotdPayload;
  public status: CommandStatus;
  public callback;
 
  constructor(payload: MotdPayload) {
    this.payload = payload;
  }
 
  public eligible(payload: MotdPayload, store) {
 
    // get the current character
    const currentCharacter = CharactersTools.currentCharacter(payload.mat, store);
 
    if (currentCharacter === null) {
      return false;
    }
 
    return true;
  }
 
  public execute(meta: MotdMeta) {
    let message = validator.escape(meta.message);
    message = validator.ltrim(message, 180);
    this.callback = () => {
      console.log(message);
    };
    return [updateMotd(meta.Character, message)];
  }
 
}