-
Notifications
You must be signed in to change notification settings - Fork 10.1k
/
slackbridge_import.server.js
69 lines (64 loc) · 1.75 KB
/
slackbridge_import.server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Meteor } from 'meteor/meteor';
import { Match } from 'meteor/check';
import { Random } from 'meteor/random';
import { TAPi18n } from 'meteor/tap:i18n';
import { RocketChat } from 'meteor/rocketchat:lib';
function SlackBridgeImport(command, params, item) {
if (command !== 'slackbridge-import' || !Match.test(params, String)) {
return;
}
const room = RocketChat.models.Rooms.findOneById(item.rid);
const channel = room.name;
const user = Meteor.users.findOne(Meteor.userId());
msgStream.emit(item.rid, {
_id: Random.id(),
rid: item.rid,
u: { username: 'rocket.cat' },
ts: new Date(),
msg: TAPi18n.__('SlackBridge_start', {
postProcess: 'sprintf',
sprintf: [user.username, channel],
}, user.language),
});
try {
RocketChat.SlackBridge.importMessages(item.rid, (error) => {
if (error) {
msgStream.emit(item.rid, {
_id: Random.id(),
rid: item.rid,
u: { username: 'rocket.cat' },
ts: new Date(),
msg: TAPi18n.__('SlackBridge_error', {
postProcess: 'sprintf',
sprintf: [channel, error.message],
}, user.language),
});
} else {
msgStream.emit(item.rid, {
_id: Random.id(),
rid: item.rid,
u: { username: 'rocket.cat' },
ts: new Date(),
msg: TAPi18n.__('SlackBridge_finish', {
postProcess: 'sprintf',
sprintf: [channel],
}, user.language),
});
}
});
} catch (error) {
msgStream.emit(item.rid, {
_id: Random.id(),
rid: item.rid,
u: { username: 'rocket.cat' },
ts: new Date(),
msg: TAPi18n.__('SlackBridge_error', {
postProcess: 'sprintf',
sprintf: [channel, error.message],
}, user.language),
});
throw error;
}
return SlackBridgeImport;
}
RocketChat.slashCommands.add('slackbridge-import', SlackBridgeImport);