-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (59 loc) · 1.95 KB
/
index.js
File metadata and controls
71 lines (59 loc) · 1.95 KB
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
70
var config = require('./config');
var mumble = require('mumble');
var fs = require('fs');
var options = {};
if( config.get("key") )
options.key = fs.readFileSync( config.get("key") );
if( config.get("cert") )
options.cert = fs.readFileSync( config.get("cert") );
if( !config.get("serverAddress") )
throw new Error("Must have config option serverAddress");
mumble.connect( config.get("serverAddress"), options, function(error, mumbleClient) {
if(error) {
throw new Error(error);
}
// stream that goes to the server
var inputStream;
// stream from the server
var outputStream;
var MessageHandler;
mumbleClient.updateChannelName = function(new_name) {
this.connection.sendMessage('ChannelState', {channel_id: this.user.channel.id, name: new_name.replace(/([^\w\W])+/g, "")});
};
mumbleClient.baseChannelName = config.get("channelName");
mumbleClient.volume = 50;
mumbleClient.authenticate('CyrcleBot');
mumbleClient.on('initialized', function() {
console.log("Init success");
inputStream = mumbleClient.inputStream();
outputStream = mumbleClient.outputStream();
MessageHandler = require('./messageHandler')(mumbleClient, inputStream);
});
mumbleClient.on('protocol-in', function(data) {
if(data.type != "Ping" && data.type != "PermissionDenied") {
}
if(data.type == "TextMessage") {
MessageHandler(data);
}
if(data.type == "ChannelState") {
}
if(data.type == "ServerConfig") {
joinChannel(mumbleClient, findChannelByPrefix(mumbleClient,config.get("channelName")));
}
});
mumbleClient.on('error', function(data) {
});
});
function findChannelByPrefix(mumbleClient, prefix) {
for(var i in mumbleClient._channels) {
var chan = mumbleClient._channels[i];
if(chan.name && chan.name.indexOf(prefix) === 0) {
return chan;
}
}
return null;
}
function joinChannel(mumbleClient, channel) {
channel.join();
mumbleClient.currentChannelId = channel.id;
}