Guest User

Untitled

a guest
Oct 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. 'use strict'
  2.  
  3. const BaseCommand = require('./BaseCommand')
  4.  
  5. class ParamCommand extends BaseCommand {
  6.  
  7. /**
  8. *
  9. * @param {string} textPattern
  10. * @param {string} [handler]
  11. * @param {Array} ...arguments the arguments passed to parameter
  12. */
  13. constructor(command, handler, ...params) {
  14. super()
  15.  
  16. this._command = command
  17. this._handler = handler
  18. this._params = params
  19. }
  20.  
  21. /**
  22. * @param {Scope} scope
  23. * @returns {boolean}
  24. */
  25. test(scope) {
  26.  
  27. if(scope.message.text){
  28.  
  29. var split = scope.message.text.split(" ")
  30.  
  31. if(split[0] == this._command){ //command matching
  32. console.log("command matching")
  33.  
  34. if(this._params.length == split.length - 1){ //param matching
  35. console.log("param matching")
  36.  
  37. scope.param = {}
  38.  
  39. for(var i=0; i<this._params.length; i++){
  40. scope.param[this._params[i]] = split[i]
  41. }
  42.  
  43. return true
  44. }
  45. }
  46. }
  47.  
  48. return false
  49. }
  50.  
  51. /**
  52. * @returns {string}
  53. */
  54. get handlerName() {
  55. return this._handler
  56. }
  57.  
  58. }
  59.  
  60. module.exports = ParamCommand
Advertisement
Add Comment
Please, Sign In to add comment