2018-11-05 08:02:20 +01:00
|
|
|
var WebSocket = require('ws');
|
|
|
|
var Discord = require('discord.js');
|
2018-12-08 08:11:06 +01:00
|
|
|
var createWsMessageCollector = require('./datacollector');
|
|
|
|
|
2022-01-04 05:40:43 +01:00
|
|
|
var webhook = new Discord.WebhookClient({url: config.webhooks.ddp});
|
2018-11-05 08:02:20 +01:00
|
|
|
|
|
|
|
var ws;
|
|
|
|
var wasConnected = false;
|
2018-11-06 09:28:41 +01:00
|
|
|
//var myId;
|
2018-11-05 08:02:20 +01:00
|
|
|
|
2018-12-08 08:11:06 +01:00
|
|
|
var collectWsMessage = createWsMessageCollector(async function(data, startDate, endDate){
|
2018-12-08 08:39:30 +01:00
|
|
|
await webhook.send({files:[{
|
2018-12-08 08:11:06 +01:00
|
|
|
attachment: data,
|
|
|
|
name: `daydun piano main raw data recording from ${startDate.toISOString()} to ${endDate.toISOString()} .txt.gz`
|
|
|
|
}]});
|
|
|
|
});
|
|
|
|
|
2018-11-05 08:02:20 +01:00
|
|
|
(function connect() {
|
|
|
|
ws = new WebSocket("wss://daydun.com:5012/?nick=%5Bdiscord.gg%2Fk44Eqha%5D");
|
|
|
|
ws.on("open", () => {
|
|
|
|
if (!wasConnected) send2discord("**Connected**");
|
|
|
|
wasConnected = true;
|
|
|
|
});
|
|
|
|
ws.on("message", message => {
|
2018-12-08 08:11:06 +01:00
|
|
|
collectWsMessage(message);
|
2018-11-05 08:18:46 +01:00
|
|
|
if (typeof message != 'string') return;
|
|
|
|
var transmission = JSON.parse(message);
|
2018-11-05 08:02:20 +01:00
|
|
|
if (transmission.type == 'chat') {
|
|
|
|
let chatmsg = transmission.message;
|
|
|
|
if (chatmsg.type == "message") {
|
2018-11-06 09:28:41 +01:00
|
|
|
//if (chatmsg.id != myId)
|
|
|
|
if (!chatmsg.content.startsWith('\u034f'))
|
2018-11-09 22:10:20 +01:00
|
|
|
send2discord(`**${sanitizeName(chatmsg.user.nick)}:** ${escapeDiscordMentions(chatmsg.content)}`);
|
2018-11-05 08:02:20 +01:00
|
|
|
} else if (chatmsg.type == "join") {
|
2018-11-09 22:10:20 +01:00
|
|
|
send2discord(`__***${sanitizeName(chatmsg.nick || chatmsg.id)} joined.***__`);
|
2018-11-05 08:02:20 +01:00
|
|
|
} else if (chatmsg.type == "leave") {
|
2018-11-09 22:10:20 +01:00
|
|
|
send2discord(`__***${sanitizeName(chatmsg.nick || chatmsg.id)} left.***__`);
|
2018-11-05 08:02:20 +01:00
|
|
|
}
|
2018-11-06 09:28:41 +01:00
|
|
|
} /*else if (transmission.type == 'load') {
|
2018-11-06 09:24:10 +01:00
|
|
|
myId = transmission.id;
|
2018-11-06 09:28:41 +01:00
|
|
|
}*/
|
2018-11-05 08:02:20 +01:00
|
|
|
});
|
2022-01-04 05:40:43 +01:00
|
|
|
ws.on("error", error => handleError(error));
|
2018-11-05 08:02:20 +01:00
|
|
|
ws.on("close", () => {
|
|
|
|
if (wasConnected) send2discord("**Disconnected**");
|
|
|
|
wasConnected = false;
|
|
|
|
setTimeout(connect, 5000);
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
|
|
|
function send2discord(message) {
|
2022-01-04 05:40:43 +01:00
|
|
|
webhook.send(message.substring(0,2000));
|
2018-11-05 08:02:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function send2ddp(message) {
|
2018-11-06 08:53:00 +01:00
|
|
|
if (ws.readyState == WebSocket.OPEN) ws.send(JSON.stringify({type:"chat",message}));
|
2018-11-05 08:02:20 +01:00
|
|
|
}
|
|
|
|
|
2022-01-04 05:40:43 +01:00
|
|
|
dClient.on("messageCreate", message => {
|
2018-11-05 08:32:05 +01:00
|
|
|
if (message.channel.id != "508890674138054667" || message.author.bot) return;
|
2018-11-07 22:18:53 +01:00
|
|
|
var x = message.cleanContent;
|
2022-01-04 05:40:43 +01:00
|
|
|
if (message.attachments.size > 0) x += ' ' + message.attachments.map(a => a.url).join(' ');
|
2018-11-07 22:18:53 +01:00
|
|
|
send2ddp(`\u034f${message.member.displayName}#${message.author.discriminator}: ${x}`);
|
2018-11-05 08:02:20 +01:00
|
|
|
});
|