@eliyah/

chatti Backup Server

Nodejs

No description

fork
loading
Files
  • index.js
  • cookies.json
  • msgs.json
  • package-lock.json

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.37740404995337706","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"Y29uc3QgZXhwcmVzcyA9IHJlcXVpcmUoJ2V4cHJlc3MnKTsKY29uc3QgYm9keVBhcnNlciA9IHJlcXVpcmUoJ2JvZHktcGFyc2VyJyk7Cgpjb25zdCBhcHAgPSBleHByZXNzKCk7CgphcHAudXNlKGJvZHlQYXJzZXIuanNvbigpKTsKYXBwLnVzZShib2R5UGFyc2VyLnVybGVuY29kZWQoeyBleHRlbmRlZDogdHJ1ZSB9KSk7CgphcHAudXNlKGV4cHJlc3Muc3RhdGljKCdwdWJsaWMnKSk7CgphcHAuZ2V0KCcvJywgKHJlcSwgcmVzKSA9PiB7CglyZXMuc2VuZCgnSGVsbG8gRXhwcmVzcyBhcHAnKTsKfSk7CgphcHAubGlzdGVuKDMwMDAsICgpID0+IGNvbnNvbGUubG9nKCdzZXJ2ZXIgc3RhcnRlZCcpKTsKCmNvbnN0IFdlYlNvY2tldCA9IHJlcXVpcmUoJ3dzJyk7CmNvbnN0IGZzID0gcmVxdWlyZSgiZnMiKTsKCmNvbnN0IHdzID0gbmV3IFdlYlNvY2tldCgid3M6Ly9jb25uZWN0LndlYnNvY2tldC5pbi9jaGF0aWk/cm9vbV9pZD0xIik7Cgp2YXIgc2F2ZSA9ICgpID0+IHsKICBmcy53cml0ZUZpbGUoIm1zZ3MuanNvbiIsIEpTT04uc3RyaW5naWZ5KG1zZ3MpLCAoKSA9PiB7fSk7CiAgZnMud3JpdGVGaWxlKCJjb29raWVzLmpzb24iLCBKU09OLnN0cmluZ2lmeShjb29raWVzKSwgKCkgPT4ge30pOwp9OwoKd3Mub25vcGVuID0gKCkgPT4gewogIGNvbnNvbGUubG9nKCJPUEVOIik7Cn0KdmFyIHJlbG9hZCA9ICgp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lwZSA9PSAiYmFuIikgewogICAgY29va2llc1tkYXRhLmlkXS5iYW5uZWQgPSB0cnVlOwogICAgd3Muc2VuZChKU09OLnN0cmluZ2lmeSh7dHlwZToiRGVsZXRlQ29va2llcyIsY29va2llczpjb29raWVzfSkpOwogIH0KICBpZiAoZGF0YS50eXBlID09ICJ1bmJhbiIpIHsKICAgIGNvb2tpZXNbZGF0YS5pZF0uYmFubmVkID0gZmFsc2U7CiAgICB3cy5zZW5kKEpTT04uc3RyaW5naWZ5KHt0eXBlOiJEZWxldGVDb29raWVzIixjb29raWVzOmNvb2tpZXN9KSk7CiAgfQogIGlmIChkYXRhLnR5cGUgPT0gImNvb2tpZXMiKSB7CiAgICB3cy5zZW5kKEpTT04uc3RyaW5naWZ5KHt0eXBlOiJEZWxldGVDb29raWVzIixjb29raWVzOmNvb2tpZXN9KSk7CiAgfQogIGlmIChkYXRhLnR5cGUgPT0gInJlcG9ydCIpIHsKICAgIGlmIChtc2dzLmxlbmd0aCA+IGRhdGEuaWQpIHsKICAgICAgdmFyIG1zZyA9IEpTT04ucGFyc2UobXNnc1tkYXRhLmlkXSk7CiAgICAgIGlmIChtc2cucmVwb3J0cy5pbmRleE9mKGRhdGEudXNlcikgPCAwKSB7CiAgICAgICAgbXNnLnJlcG9ydHMucHVzaChkYXRhLnVzZXIpOwogICAgICB9CiAgICAgIG1zZ3NbZGF0YS5pZF0gPSBKU09OLnN0cmluZ2lmeShtc2cpOwogICAgfQogICAgcmVsb2FkKCk7CiAgfQogIHNhdmUoKTsKfTsKdmFyIHJlcGxhY2UgPSAodGV4dCwgYSwgYikgPT4gewogIHJldHVybiB0ZXh0LnNwbGl0KGEpLmpvaW4oYik7Cn07CndzLmNsb3NlID0gKCkgPT4gewogIHByb2Nlc3MuZXhpdCgwKTsKfTs="},"asBuffer":null},"loaded":true}}
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const express = require('express');
const bodyParser = require('body-parser');

const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use(express.static('public'));

app.get('/', (req, res) => {
	res.send('Hello Express app');
});

app.listen(3000, () => console.log('server started'));

const WebSocket = require('ws');
const fs = require("fs");

const ws = new WebSocket("ws://connect.websocket.in/chatii?room_id=1");

var save = () => {
  fs.writeFile("msgs.json", JSON.stringify(msgs), () => {});
  fs.writeFile("cookies.json", JSON.stringify(cookies), () => {});
};

ws.onopen = () => {
  console.log("OPEN");
}
var reload = () => {
  ws.send(JSON.stringify({type:"Delete",msgs:msgs}));
}
var cookies = JSON.parse(fs.readFileSync("cookies.json"));
var msgs = JSON.parse(fs.readFileSync("msgs.json"));
ws.onmessage = message => {
  console.log(message.data);
  var data = JSON.parse(message.data);
  if (data.type == "SendMessage") {
    if (data.raw.startsWith("/")) {
      if (data.raw.startsWith("/msg")) {
        data.raw = data.raw.split(" ");
        data.raw.shift();
        var toa = data.raw.shift();
        data.raw = data.raw.join(" ");
        msgs.push(JSON.stringify({type:"PrivateMessage", raw:data.raw,user:data.user,to:toa,reports:[]}));
        console.log(msgs);
      }
      if (data.raw.startsWith("/nick")) {
        data.raw = data.raw.split(" ");
        data.raw.shift();
        var toa = data.raw.shift();
        data.raw = data.raw.join(" ");
        ws.send(JSON.stringify({type:"nick",user:data.user,nick:toa,reports:[]}));
      }
      if (data.raw.startsWith("/unnick")) {
        ws.send(JSON.stringify({type:"unnick",user:data.user,reports:[]}));
      }
      if (data.raw.startsWith("/colors")) {
        msgs.push(JSON.stringify({type:"PrivateMessage", raw:"&0&&00 &1&&11 &2&&22 &3&&33 &4&&44 &5&&55 &6&&66 &7&&77 &8&&88 &9&&99 &a&&aa &b&&bb &c&&cc &d&&dd &e&&ee &f&&ff&r.",user:"Console",to:data.user,reports:[]}));
      }
      if (data.raw.startsWith("/help")) {
        msgs.push(JSON.stringify({type:"PrivateMessage", raw:"/nick /unnick /msg /help /colors",user:"Console",to:data.user,reports:[]}));
      }
    } else {
      msgs.push(JSON.stringify({type:"Message", message:data.message,raw:data.raw,user:data.user,reports:[]}));
    }
    reload();
  }
  if (data.type == "GetRefresh") {
    reload();
  }
  if (data.type == "Remove") {
    msgs.splice(data.id,1);
    reload();
  }
  if (data.type == "RemoveCookie") {
    ws.send(JSON.stringify({type:"kick",name:cookies[data.id].name}));
    console.log(cookies);
    cookies.splice(data.id,1);
    console.log(cookies);
    ws.send(JSON.stringify({type:"DeleteCookies",cookies:cookies}));
  }
  if (data.type == "signup") {
    console.log(data.cookie);
    cookies.push({cookie:data.id, name:data.name});
    msgs.push(JSON.stringify({type:"Message", message:data.name+" &1Have just signup",raw:data.name+" Have just signup",user:"Console",reports:[]}));
    reload();
  }
  if (data.type == "kickCookie") {
    ws.send(JSON.stringify({type:"kick",name:cookies[data.id].name}));
  }
  if (data.type == "ban") {
    cookies[data.id].banned = true;
    ws.send(JSON.stringify({type:"DeleteCookies",cookies:cookies}));
  }
  if (data.type == "unban") {
    cookies[data.id].banned = false;
    ws.send(JSON.stringify({type:"DeleteCookies",cookies:cookies}));
  }
  if (data.type == "cookies") {
    ws.send(JSON.stringify({type:"DeleteCookies",cookies:cookies}));
  }
  if (data.type == "report") {
    if (msgs.length > data.id) {
      var msg = JSON.parse(msgs[data.id]);
      if (msg.reports.indexOf(data.user) < 0) {
        msg.reports.push(data.user);
      }
      msgs[data.id] = JSON.stringify(msg);
    }
    reload();
  }
  save();
};
var replace = (text, a, b) => {
  return text.split(a).join(b);
};
ws.close = () => {
  process.exit(0);
};
node v10.16.0