Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converted rocketchat-slashcommands-kick coffee to js #6453

Merged
merged 2 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/rocketchat-slashcommands-kick/client.coffee

This file was deleted.

10 changes: 10 additions & 0 deletions packages/rocketchat-slashcommands-kick/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RocketChat.slashCommands.add('kick', function(command, params) {
const username = params.trim();
if (username === '') {
return;
}
return username.replace('@', '');
}, {
description: 'Remove_someone_from_room',
params: '@username'
});
5 changes: 2 additions & 3 deletions packages/rocketchat-slashcommands-kick/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ Package.describe({
Package.onUse(function(api) {

api.use([
'coffeescript',
'ecmascript',
'check',
'rocketchat:lib'
]);

api.use('templating', 'client');

api.addFiles('client.coffee', 'client');
api.addFiles('server.coffee', 'server');
api.addFiles('client.js', 'client');
api.addFiles('server.js', 'server');
});
40 changes: 0 additions & 40 deletions packages/rocketchat-slashcommands-kick/server.coffee

This file was deleted.

40 changes: 40 additions & 0 deletions packages/rocketchat-slashcommands-kick/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

// 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);