Skip to content
Snippets Groups Projects
Commit 22f4f45c authored by Gabriel Engel's avatar Gabriel Engel Committed by GitHub
Browse files

Merge pull request #5200 from RocketChat/bots-avoid-sendMessage-rate-limit

Fix bot users being rate limited
parents 9f49ef06 cd6771a0
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,9 @@ Meteor.methods
check message, Object
if not Meteor.userId()
throw new Meteor.Error('error-invalid-user', "Invalid user", { method: 'sendMessage' })
if message.ts
tsDiff = Math.abs(moment(message.ts).diff())
if tsDiff > 60000
......@@ -17,9 +20,6 @@ Meteor.methods
if message.msg?.length > RocketChat.settings.get('Message_MaxAllowedSize')
throw new Meteor.Error('error-message-size-exceeded', 'Message size exceeds Message_MaxAllowedSize', { method: 'sendMessage' })
if not Meteor.userId()
throw new Meteor.Error('error-invalid-user', "Invalid user", { method: 'sendMessage' })
user = RocketChat.models.Users.findOneById Meteor.userId(), fields: username: 1, name: 1
room = Meteor.call 'canAccessRoom', message.rid, user._id
......@@ -42,10 +42,12 @@ Meteor.methods
RocketChat.sendMessage user, message, room
# Limit a user to sending 5 msgs/second
# Limit a user, who does not have the "bot" role, to sending 5 msgs/second
DDPRateLimiter.addRule
type: 'method'
name: 'sendMessage'
userId: (userId) ->
return RocketChat.models.Users.findOneById(userId)?.username isnt RocketChat.settings.get('InternalHubot_Username')
user = RocketChat.models.Users.findOneById(userId)
return true if not user?.roles
return 'bot' not in user.roles
, 5, 1000
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment