This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
spype.js
74 lines (61 loc) · 1.55 KB
/
spype.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
70
71
72
73
74
var util = require("util");
var fs = require('fs');
var config = JSON.parse(fs.readFileSync("config.json"));
var output = require("./Output");
var debug = process.argv[2] == "debug" ? true : false;
//var EditMessageHelper = require("./EditMessageHelper");
//var editHelper = new EditMessageHelper();
var pipes = require("./PipesHelper");
// SET UP PIPES AND SAY SO
pipes.setup();
// LOAD Skype
var SkypeHelper = require("./SkypeHelper");
SkypeHelper.debug = debug;
SkypeHelper.Connect();
// LOAD Discord
var DiscordHelper = require("./DiscordHelper");
DiscordHelper.debug = debug;
DiscordHelper.Connect();
// Register Callbacks
// Skype to Discord
SkypeHelper.MessageCallback(DiscordHelper.SendMessage);
// Discord to Skype
DiscordHelper.MessageCallback(SkypeHelper.SendMessage);
var sayToAll = function(message)
{
pipes.each(function(pipe)
{
if(pipe.announceConnection)
{
SkypeHelper.SendMessage(pipe, message, "SPYPE");
DiscordHelper.SendMessage(pipe, message, "SPYPE");
}
});
}
var sendDisconnectedMessages = function()
{
pipes.each(function(pipe)
{
if(pipe.announceConnection)
{
SkypeHelper.SendMessage(pipe, "Disconnected", "SPYPE");
DiscordHelper.SendMessage(pipe, "Disconnected", "SPYPE");
}
});
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (text)
{
if(text.startsWith("/say "))
{
var message = text.replace("/say ", "");
sayToAll(message);
}
});
//do something when app is closing
process.on('SIGHUP', function()
{
output.write("SIGHUP\n");
sendDisconnectedMessages();
});