<commit_before>###
# Invite is a named function that will replace /invite commands
# @param {Object} message - The message object
###

if Meteor.isClient
	RocketChat.slashCommands.add 'invite', undefined,
		description: 'Invite one user to join this channel'
		params: '@username'
else
	class Invite
		constructor: (command, params, item) ->
			if command isnt 'invite' or not Match.test params, String
				return

			username = params.trim()
			if username is ''
				return

			username = username.replace('@', '')

			user = Meteor.users.findOne({ username: username })

			if not user?
				return

			# cancel if the user is already in this room
			if RocketChat.models.Rooms.findOneByIdContainigUsername(item.rid, user.username)?
				return

			Meteor.runAsUser user._id, -><commit_msg>Send a message on invite commands when the user doesn't exist or is already in the channel<commit_after>###
# Invite is a named function that will replace /invite commands
# @param {Object} message - The message object
###

if Meteor.isClient
	RocketChat.slashCommands.add 'invite', undefined,
		description: 'Invite one user to join this channel'
		params: '@username'
else
	class Invite
		constructor: (command, params, item) ->
			if command isnt 'invite' or not Match.test params, String
				return

			username = params.trim()
			if username is ''
				return

			username = username.replace('@', '')

			user = Meteor.users.findOne({ username: username })

			if not user?
				RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {
					_id: Random.id()
					rid: item.rid
					ts: new Date
					msg: "No user exists by the name of `#{username}`."#TODO: Make this a language setting
				}
				return

			# cancel if the user is already in this room
			if RocketChat.models.Rooms.findOneByIdContainigUsername(item.rid, user.username)?
				RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {
					_id: Random.id()
					rid: item.rid
					ts: new Date
					msg: "`#{username}` is already in here."#TODO: Make this a language setting
				}
				return

			Meteor.runAsUser user._id, ->
{'fraction_non_alphanumeric': 0.10523809523809524, 'fraction_numerical': 0.0, 'mean_word_length': 3.4512711864406778, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5447175', 'n_tokens_mistral': 752, 'n_tokens_neox': 627, 'n_words': 221}