sort of partial fix, still broken

This commit is contained in:
lolcat 2023-12-18 02:17:19 -05:00
parent dd48c9bc50
commit 0a0bc0575a
2 changed files with 140 additions and 88 deletions

194
client.js
View File

@ -88,30 +88,56 @@ function removehtml(html){
/* /*
Websocket functions Websocket functions
*/ */
async function send(channel, text){ async function send(channel, text/*, file = null, forcemime = null*/){
if(typeof channel == "object"){ if(typeof channel == "object"){
channel = channel.channel; channel = channel.channel;
} }
for(var i=0; i<channels.length; i++){ //if(file === null){
if(channels[i].id === channel){ ws.send(JSON.stringify({
var arraypos = i;
break;
}
}
channels[arraypos].ws.send(JSON.stringify({
type: "messageEnd", type: "messageEnd",
data: { data: text,
message: text roomId: channel
}
})); }));
return; return;
//}
/*
Send file
*/
/*
if(forcemime === null){
var mimetype = await getmime(file);
}else{
var mimetype = forcemime;
}
var form_data = new formdata();
form_data.append("text", text);
form_data.append(
"files[]",
file,
{
contentType: mimetype[0],
name: "file",
filename: "file." + mimetype[1]
}
);
var headers_copy = headers;
headers_copy["Content-Type"] = form_data.getHeaders()["content-type"];
fetch("https://deek.chat/message/send/" + channel, {
method: 'POST',
body: form_data,
headers: headers_copy
})*/
} }
/* /*
@ -160,7 +186,7 @@ async function handshake(){
return; return;
} }
headers.cookie = "session_id=" + session_id[1] + "; api_token=" + api_token[1]; headers.Cookie = "session_id=" + session_id[1] + "; api_token=" + api_token[1] + "; lastMessageTimestamps={}";
/* /*
@ -244,6 +270,7 @@ async function handshake(){
/* /*
Scrape users Scrape users
*/ */
/*
var users = await fetch( var users = await fetch(
"https://deek.chat/users/" + item_map[selected], "https://deek.chat/users/" + item_map[selected],
{ {
@ -253,6 +280,7 @@ async function handshake(){
); );
var res = await users.buffer(); var res = await users.buffer();
res = JSON.parse(res.toString("utf8")); res = JSON.parse(res.toString("utf8"));
if(res === null){ if(res === null){
@ -272,11 +300,12 @@ async function handshake(){
}, },
picture: res[k].profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + res[k].profilePicture picture: res[k].profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + res[k].profilePicture
}); });
} }*/
/* /*
Get previous messages Get previous messages
*/ */
/*
previous_msg = await fetch( previous_msg = await fetch(
"https://deek.chat/message/fetch/" + item_map[selected], "https://deek.chat/message/fetch/" + item_map[selected],
{ {
@ -287,14 +316,14 @@ async function handshake(){
previous_msg = await previous_msg.buffer(); previous_msg = await previous_msg.buffer();
previous_msg = JSON.parse(previous_msg.toString("utf8")); previous_msg = JSON.parse(previous_msg.toString("utf8"));
channel_index = item_map[selected]; channel_index = item_map[selected];*/
/* /*
Connect to websocket serbers Connect to websocket serbers
*/ */
channels[selected].ws = new websocket( ws = new websocket(
"wss://deek.chat/ws/" + item_map[selected], "wss://deek.chat/ws",
{ {
protocolVersion: 13, protocolVersion: 13,
encoding: "utf8", encoding: "utf8",
@ -302,17 +331,17 @@ async function handshake(){
} }
); );
channels[selected].ws.once("open", function(){ ws.once("open", function(){
deek.emit("login", channels[selected]); deek.emit("login", channels[selected]);
}); });
channels[selected].ws.once("close", function(){ ws.once("close", function(){
deek.emit("close", channels[selected]); deek.emit("close");
}); });
channels[selected].ws.on("message", function(message, isbin){ ws.on("message", function(message, isbin){
if(isbin){ return; } if(isbin){ return; }
@ -322,88 +351,98 @@ async function handshake(){
return; return;
} }
if(
typeof m.roomId != "undefined" &&
m.roomId != channels[selected].id
){
return;
}
switch(m.type){ switch(m.type){
case "message":
case "messageEnd": case "messageEnd":
for(var k=0; k<m.data.message.mentions.length; k++){ for(var k=0; k<m.data.mentions.length; k++){
m.data.message.mentions[k].id = m.data.message.mentions[k].userId; m.data.mentions[k].id = m.data.mentions[k].userId;
delete m.data.message.mentions[k].userId; delete m.data.mentions[k].userId;
} }
for(var k=0; k<m.data.message.replies.length; k++){ for(var k=0; k<m.data.replies.length; k++){
m.data.message.replies[k].id = m.data.message.replies[k].userId; m.data.replies[k].id = m.data.replies[k].userId;
m.data.message.replies[k].message = m.data.message.replies[k].replyMessageId; m.data.replies[k] = m.data.replies[k].replyMessageId;
delete m.data.message.replies[k].userId; delete m.data.replies[k].userId;
delete m.data.message.replies[k].replyMessageId; delete m.data.replies[k].replyMessageId;
} }
m.data.message.files = m.data.message.files === null ? [] : m.data.message.files; m.data.files = m.data.files === null ? [] : m.data.files;
var files = []; var files = [];
for(var k=0; k<m.data.message.files.length; k++){ for(var k=0; k<m.data.files.length; k++){
files.push("https://deek.chat/storage/files/" + m.data.message.files[k].name); files.push("https://deek.chat/storage/files/" + m.data.files[k].name);
} }
deek.emit( deek.emit(
"message", "message",
{ {
text: removehtml(m.data.message.text), text: removehtml(m.data.text),
id: m.data.message.id, id: m.data.id,
files: files, files: files,
mentions: m.data.message.mentions, mentions: m.data.mentions,
replies: m.data.message.replies, replies: m.data.replies,
channel: m.roomId channel: m.roomId
}, },
{ {
name: m.data.message.name, name: m.data.name,
id: m.userId, id: m.userId,
picture: m.data.message.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.data.message.profilePicture picture: m.data.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.data.profilePicture
} }
); );
break; break;
case "files": case "files":
m.message.files = m.message.files === null ? [] : m.message.files;
var files = []; var files = [];
for(var k=0; k<m.message.files.length; k++){ if(m.data.files !== null){
for(var k=0; k<m.data.files.length; k++){
files.push("https://deek.chat/storage/files/" + m.message.files[k].name); files.push("https://deek.chat/storage/files/" + m.data.files[k].name);
}
} }
deek.emit( deek.emit(
"message", "message",
{ {
text: removehtml(m.message.text), text: removehtml(m.data.text),
id: m.message.id, id: m.data.id,
files: files, files: files,
mentions: m.message.mentions, mentions: m.data.mentions,
replies: m.message.replies, replies: m.data.replies,
channel: m.roomId channel: m.roomId
}, },
{ {
name: m.message.name == "" ? null : m.message.name, name: m.data.name,
id: m.userId, id: m.data.userId,
picture: m.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.profilePicture picture: m.data.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.data.profilePicture
} }
); );
break; break;
case "enter": case "enter":
var payload = { var payload = {
name: m.name, name: m.data.name,
id: m.id, id: m.data.id,
phoneposter: m.isMobile, phoneposter: m.data.isMobile,
robot: m.data.isRobot,
country: { country: {
name: m.countryName, name: m.data.countryName == "" ? "idk lol" : m.data.countryName,
code: m.countryIso.toUpperCase() code: m.data.countryIso == "" ? "??" : m.data.countryIso,
}, },
picture: m.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.profilePicture picture: m.data.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.data.profilePicture
}; };
channels[selected].users.push(payload); channels[selected].users.push(payload);
@ -416,19 +455,20 @@ async function handshake(){
case "exit": case "exit":
var payload = { var payload = {
name: m.name, name: m.data.name,
id: m.id, id: m.data.id,
phoneposter: null, phoneposter: m.data.isMobile,
picture: null, robot: m.data.isRobot,
country: { country: {
name: null, name: m.data.countryName,
code: null code: m.data.countryIso.toUpperCase()
} },
picture: m.data.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.data.profilePicture
} }
for(var i=0; i<channels[selected].users.length; i++){ for(var i=0; i<channels[selected].users.length; i++){
if(channels[selected].users[i].id == m.id){ if(channels[selected].users[i].id == payload.id){
payload = channels[selected].users[i]; payload = channels[selected].users[i];
channels[selected].users.splice(i, 1); channels[selected].users.splice(i, 1);
@ -453,6 +493,9 @@ async function handshake(){
/* /*
User defined FUN-ctions!!! User defined FUN-ctions!!!
*/ */
var textbuffer = "";
var first_append = true;
function appendmessage(msg, user, render = true){ function appendmessage(msg, user, render = true){
var filetext = ""; var filetext = "";
@ -470,7 +513,15 @@ function appendmessage(msg, user, render = true){
filetext += msg.files[i]; filetext += msg.files[i];
} }
messagelist.pushLine( if(first_append === false){
textbuffer += "\n";
}else{
first_append = false;
}
textbuffer +=
"{bold}{red-fg}<" + blessed.escape(user.name) + ">{/red-fg}{/bold} " + "{bold}{red-fg}<" + blessed.escape(user.name) + ">{/red-fg}{/bold} " +
msg.text.trim() msg.text.trim()
.replace( .replace(
@ -485,8 +536,9 @@ function appendmessage(msg, user, render = true){
return "{light-red-fg}" + match + "{/light-red-fg}" return "{light-red-fg}" + match + "{/light-red-fg}"
} }
) + ) +
filetext filetext;
);
messagelist.setContent(textbuffer);
if(render){ if(render){
messagelist.setScrollPerc(100); messagelist.setScrollPerc(100);
@ -561,7 +613,7 @@ deek.on("login", function(channel){
} }
} }
messagelist.pushLine("{light-gray-fg} * Connected to channel " + channel.name + " (id:" + channel.id + "){/light-gray-fg}"); //messagelist.pushLine("{light-gray-fg} * Connected to channel " + channel.name + " (id:" + channel.id + "){/light-gray-fg}");
input.focus(); input.focus();
messagelist.setScrollPerc(100); messagelist.setScrollPerc(100);
@ -640,14 +692,14 @@ deek.on("login", function(channel){
deek.on("enter", async function(user){ deek.on("enter", async function(user){
messagelist.pushLine("{light-gray-fg} * {bold}" + blessed.escape(user.name) + "{/bold} from " + user.country.name + " has joined{/light-gray-fg}"); //messagelist.pushLine("{light-gray-fg} * {bold}" + blessed.escape(user.name) + "{/bold} from " + user.country.name + " has joined{/light-gray-fg}");
messagelist.setScrollPerc(100); messagelist.setScrollPerc(100);
screen.render(); screen.render();
}); });
deek.on("exit", async function(user){ deek.on("exit", async function(user){
messagelist.pushLine("{light-gray-fg} * {bold}" + blessed.escape(user.name) + "{/bold} has left{/light-gray-fg}"); //messagelist.pushLine("{light-gray-fg} * {bold}" + blessed.escape(user.name) + "{/bold} has left{/light-gray-fg}");
messagelist.setScrollPerc(100); messagelist.setScrollPerc(100);
screen.render(); screen.render();
}); });
@ -659,7 +711,7 @@ deek.on("message", async function(msg, user){
deek.on("close", async function(channel){ deek.on("close", async function(channel){
messagelist.pushLine("{light-red-fg}It's over. Disconnected from channel " + channel.name + " (id:" + channel.id + "){/light-red-fg}"); //messagelist.pushLine("{light-red-fg}It's over. Disconnected from channel " + channel.name + " (id:" + channel.id + "){/light-red-fg}");
messagelist.setScrollPerc(100); messagelist.setScrollPerc(100);
screen.render(); screen.render();
}); });

View File

@ -2,5 +2,5 @@
# Now with 100% less accidently commited passwords # Now with 100% less accidently commited passwords
# Create an account by visiting https://deek.chat # Create an account by visiting https://deek.chat
username=your_user_name_here username=lul4_nokia
password=your_password_here password=ehfuiwhfuiewhfiuewhfiuwehfuihewiufewiuf