Skip to content
Snippets Groups Projects
Commit 80aa6204 authored by Guilherme Gazzo's avatar Guilherme Gazzo Committed by Rodrigo Nascimento
Browse files

converted rocketchat-slashcommands-kick coffee to js (#6453)

* converted rocketchat-slashcommands-kick coffee to js

* Update server.js
parent f8a86664
No related branches found
No related tags found
No related merge requests found
RocketChat.slashCommands.add 'kick', (command, params, item) ->
username = params.trim()
if username is ''
return
username = username.replace('@', '')
,
description: 'Remove_someone_from_room'
params: '@username'
RocketChat.slashCommands.add('kick', function(command, params) {
const username = params.trim();
if (username === '') {
return;
}
return username.replace('@', '');
}, {
description: 'Remove_someone_from_room',
params: '@username'
});
......@@ -8,7 +8,6 @@ Package.describe({
Package.onUse(function(api) {
api.use([
'coffeescript',
'ecmascript',
'check',
'rocketchat:lib'
......@@ -16,6 +15,6 @@ Package.onUse(function(api) {
api.use('templating', 'client');
api.addFiles('client.coffee', 'client');
api.addFiles('server.coffee', 'server');
api.addFiles('client.js', 'client');
api.addFiles('server.js', 'server');
});
###
# Kick is a named function that will replace /kick commands
###
class Kick
constructor: (command, params, item) ->
if command isnt 'kick' or not Match.test params, String
return
username = params.trim()
if username is ''
return
username = username.replace('@', '')
user = Meteor.users.findOne Meteor.userId()
kickedUser = RocketChat.models.Users.findOneByUsername username
room = RocketChat.models.Rooms.findOneById item.rid
if not kickedUser?
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {
_id: Random.id()
rid: item.rid
ts: new Date
msg: TAPi18n.__('Username_doesnt_exist', { postProcess: 'sprintf', sprintf: [ username ] }, user.language);
}
return
if username not in (room.usernames or [])
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {
_id: Random.id()
rid: item.rid
ts: new Date
msg: TAPi18n.__('Username_is_not_in_this_room', { postProcess: 'sprintf', sprintf: [ username ] }, user.language);
}
return
Meteor.call 'removeUserFromRoom', { rid: item.rid, username: username }
RocketChat.slashCommands.add 'kick', Kick
// Kick is a named function that will replace /kick commands
const Kick = function(command, params, {rid}) {
if (command !== 'kick' || !Match.test(params, String)) {
return;
}
const username = params.trim().replace('@', '');
if (username === '') {
return;
}
const user = Meteor.users.findOne(Meteor.userId());
const kickedUser = RocketChat.models.Users.findOneByUsername(username);
const room = RocketChat.models.Rooms.findOneById(rid);
if (kickedUser == null) {
return RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),
rid,
ts: new Date,
msg: TAPi18n.__('Username_doesnt_exist', {
postProcess: 'sprintf',
sprintf: [username]
}, user.language)
});
}
if ((room.usernames || []).includes(username) === false) {
return RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),
rid,
ts: new Date,
msg: TAPi18n.__('Username_is_not_in_this_room', {
postProcess: 'sprintf',
sprintf: [username]
}, user.language)
});
}
Meteor.call('removeUserFromRoom', {rid, username});
};
RocketChat.slashCommands.add('kick', Kick);
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