-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
105 lines (93 loc) · 3.01 KB
/
test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var sheepnet = require('./lib.js')();
var readline = require('readline');
var moment = require('moment-timezone');
var mdToAnsi = function(line) {
line = line.replace(/`(.*?)`/g, '$1');
line = line.replace(/\*\*(.*?)\*\*/g, '[1m$1[0m');
line = line.replace(/\*(.*?)\*/g, '[3m$1[0m');
return line;
}
var consSend = function(message) {
if ( "embed" in message ) {
message.embed.fields.forEach(function(msg) {
console.log("[34;1m" + msg.name + "[0m");
var printOut = msg.value.trim().split(/\n/).map(function(line) {
line = mdToAnsi(line);
return ' ' + line;
}).join("\n");
console.log(printOut);
});
console.log();
} else {
console.log(message.trim());
rl.prompt();
}
};
var message = {
sender: {
send: consSend,
},
channel: {
send: consSend,
},
delete: function() { return { catch: function() {} } }
};
var processLine = function(line) {
message.content = line;
if (message.content.indexOf(config.prefix) !== 0) {
rl.prompt();
return;
}
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === "events") {
authorize(JSON.parse(authTokens), handleEvents(function(channel) { return function(events) { printEventsToChannel(channel)(events); rl.prompt(); }}(message.channel)));
}
else if (command === "dailies" || command === "daily") {
message.delete().catch(O_o=>{});
if ( args.length == 0 ) {
displayCurrentCycle(getDailies(moment()), "Current dailies", message);
rl.prompt();
} else {
var wantedDate = chrono.parseDate(args.join(' ') + ' at ' + moment().format('HH:mm:ss'));
if ( moment.utc(wantedDate).isValid() ) {
wantedDate = moment.utc(wantedDate);
displayCurrentCycle(getDailies(wantedDate), "Dailies for " + moment.tz(wantedDate, 'Europe/Berlin').format('dddd, MMMM D, YYYY @ HH:mm:ss z'), message);
rl.prompt();
}
}
}
else if (command === "weeklies" || command === "weekly" || command === "nick") {
message.delete().catch(O_o=>{});
if ( args.length == 0 ) {
displayCurrentCycle(getWeeklies(moment()), "Current weeklies", message);
rl.prompt();
} else {
var wantedDate = chrono.parseDate(args.join(' ') + ' at ' + moment().format('HH:mm:ss'));
if ( moment.utc(wantedDate).isValid() ) {
wantedDate = moment.utc(wantedDate);
displayCurrentCycle(getWeeklies(wantedDate), "Weeklies for " + moment.tz(wantedDate, 'Europe/Berlin').format('dddd, MMMM D, YYYY @ HH:mm:ss z'), message);
rl.prompt();
}
}
}
else if (command === "quit" || command === "q" ) {
rl.close();
}
else {
console.log('Command not recognized');
rl.prompt();
}
};
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: '> ',
});
console.log("Sheepnet initialized.\n");
rl.prompt();
rl.on('line', processLine);
rl.on('close', function() {
console.log("Bye!");
process.exit(0);
});