Slash command handler

Updated /me as example
pull/333/head
warcode 10 years ago
parent 3a8bdb9f46
commit 1fccfb8e67
  1. 13
      client/lib/chatMessages.coffee
  2. 20
      packages/rocketchat-lib/client/slashCommand.coffee
  3. 2
      packages/rocketchat-lib/package.js
  4. 20
      packages/rocketchat-lib/server/slashCommand.coffee
  5. 15
      packages/rocketchat-me/me.coffee

@ -73,7 +73,18 @@
msg = input.value
input.value = ''
stopTyping(rid)
Meteor.call 'sendMessage', { _id: Random.id(), rid: rid, msg: msg, day: window.day }
#Check if message starts with /command
if msg[0] is '/'
match = msg.match(/^\/([^\s]+)(?:\s+(.*))?$/m)
if(match?)
command = match[1]
param = match[2]
internalMsg = { _id: Random.id(), rid: rid, msg: msg, day: window.day }
Meteor.call 'slashCommand', {cmd: command, params: param, msg: internalMsg }
else
#Run to allow local encryption
#Meteor.call 'onClientBeforeSendMessage', {}
Meteor.call 'sendMessage', { _id: Random.id(), rid: rid, msg: msg, day: window.day }
deleteMsg = (element) ->
id = element.getAttribute("id")

@ -0,0 +1,20 @@
RocketChat.slashCommands = {}
RocketChat.slashCommands.add = (command, callback) ->
if !RocketChat.slashCommands[command]?
RocketChat.slashCommands[command] = callback
return
RocketChat.slashCommands.run = (command, params, item) ->
if RocketChat.slashCommands[command]?
callback = RocketChat.slashCommands[command]
callback command, params, item
Meteor.methods
slashCommand: (command) ->
if not Meteor.userId()
throw new Meteor.Error 203, t('User_logged_out')
RocketChat.slashCommands.run command.cmd, command.params, command.msg

@ -18,6 +18,8 @@ Package.onUse(function(api) {
api.addFiles('lib/core.coffee', ['server', 'client']);
api.addFiles('lib/callbacks.coffee', ['server', 'client']);
api.addFiles('server/sendMessage.coffee', ['server']);
api.addFiles('server/slashCommand.coffee', ['server']);
api.addFiles('client/slashCommand.coffee', ['client']);
api.addFiles([
'settings/lib/settings.coffee',

@ -0,0 +1,20 @@
RocketChat.slashCommands = {}
RocketChat.slashCommands.add = (command, callback) ->
if !RocketChat.slashCommands[command]?
RocketChat.slashCommands[command] = callback
return
RocketChat.slashCommands.run = (command, params, item) ->
if RocketChat.slashCommands[command]?
callback = RocketChat.slashCommands[command]
callback command, params, item
Meteor.methods
slashCommand: (command) ->
if not Meteor.userId()
throw new Meteor.Error 203, t('User_logged_out')
RocketChat.slashCommands.run command.cmd, command.params, command.msg

@ -4,11 +4,12 @@
###
class Me
constructor: (message) ->
if _.trim message.html
# If message starts with /me, replace it for text formatting
if message.html.indexOf('/me ') is 0
message.html = '_' + message.html.replace('/me ','') + '_'
return message
constructor: (command, params, item) ->
if(command == "me")
if _.trim params
currentUser = Meteor.user()
msg = item
msg.msg = '_' + params + '_'
Meteor.call 'sendMessage', msg
RocketChat.callbacks.add 'renderMessage', Me
RocketChat.slashCommands.add 'me', Me
Loading…
Cancel
Save