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

218
client.js
View File

@ -88,30 +88,56 @@ function removehtml(html){
/*
Websocket functions
*/
async function send(channel, text){
async function send(channel, text/*, file = null, forcemime = null*/){
if(typeof channel == "object"){
channel = channel.channel;
}
for(var i=0; i<channels.length; i++){
//if(file === null){
if(channels[i].id === channel){
ws.send(JSON.stringify({
type: "messageEnd",
data: text,
roomId: channel
}));
var arraypos = i;
break;
}
return;
//}
/*
Send file
*/
/*
if(forcemime === null){
var mimetype = await getmime(file);
}else{
var mimetype = forcemime;
}
channels[arraypos].ws.send(JSON.stringify({
type: "messageEnd",
data: {
message: text
var form_data = new formdata();
form_data.append("text", text);
form_data.append(
"files[]",
file,
{
contentType: mimetype[0],
name: "file",
filename: "file." + mimetype[1]
}
}));
);
return;
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;
}
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
*/
/*
var users = await fetch(
"https://deek.chat/users/" + item_map[selected],
{
@ -253,6 +280,7 @@ async function handshake(){
);
var res = await users.buffer();
res = JSON.parse(res.toString("utf8"));
if(res === null){
@ -272,11 +300,12 @@ async function handshake(){
},
picture: res[k].profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + res[k].profilePicture
});
}
}*/
/*
Get previous messages
*/
/*
previous_msg = await fetch(
"https://deek.chat/message/fetch/" + item_map[selected],
{
@ -287,14 +316,14 @@ async function handshake(){
previous_msg = await previous_msg.buffer();
previous_msg = JSON.parse(previous_msg.toString("utf8"));
channel_index = item_map[selected];
channel_index = item_map[selected];*/
/*
Connect to websocket serbers
*/
channels[selected].ws = new websocket(
"wss://deek.chat/ws/" + item_map[selected],
ws = new websocket(
"wss://deek.chat/ws",
{
protocolVersion: 13,
encoding: "utf8",
@ -302,17 +331,17 @@ async function handshake(){
}
);
channels[selected].ws.once("open", function(){
ws.once("open", function(){
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; }
@ -322,88 +351,98 @@ async function handshake(){
return;
}
if(
typeof m.roomId != "undefined" &&
m.roomId != channels[selected].id
){
return;
}
switch(m.type){
case "message":
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;
delete m.data.message.mentions[k].userId;
m.data.mentions[k].id = m.data.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.message.replies[k].message = m.data.message.replies[k].replyMessageId;
delete m.data.message.replies[k].userId;
delete m.data.message.replies[k].replyMessageId;
m.data.replies[k].id = m.data.replies[k].userId;
m.data.replies[k] = m.data.replies[k].replyMessageId;
delete m.data.replies[k].userId;
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 = [];
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(
"message",
{
text: removehtml(m.data.message.text),
id: m.data.message.id,
text: removehtml(m.data.text),
id: m.data.id,
files: files,
mentions: m.data.message.mentions,
replies: m.data.message.replies,
mentions: m.data.mentions,
replies: m.data.replies,
channel: m.roomId
},
{
name: m.data.message.name,
name: m.data.name,
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;
case "files":
m.message.files = m.message.files === null ? [] : m.message.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(
"message",
{
text: removehtml(m.message.text),
id: m.message.id,
text: removehtml(m.data.text),
id: m.data.id,
files: files,
mentions: m.message.mentions,
replies: m.message.replies,
mentions: m.data.mentions,
replies: m.data.replies,
channel: m.roomId
},
{
name: m.message.name == "" ? null : m.message.name,
id: m.userId,
picture: m.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.profilePicture
name: m.data.name,
id: m.data.userId,
picture: m.data.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.data.profilePicture
}
);
break;
case "enter":
var payload = {
name: m.name,
id: m.id,
phoneposter: m.isMobile,
name: m.data.name,
id: m.data.id,
phoneposter: m.data.isMobile,
robot: m.data.isRobot,
country: {
name: m.countryName,
code: m.countryIso.toUpperCase()
name: m.data.countryName == "" ? "idk lol" : m.data.countryName,
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);
@ -416,19 +455,20 @@ async function handshake(){
case "exit":
var payload = {
name: m.name,
id: m.id,
phoneposter: null,
picture: null,
name: m.data.name,
id: m.data.id,
phoneposter: m.data.isMobile,
robot: m.data.isRobot,
country: {
name: null,
code: null
}
name: m.data.countryName,
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++){
if(channels[selected].users[i].id == m.id){
if(channels[selected].users[i].id == payload.id){
payload = channels[selected].users[i];
channels[selected].users.splice(i, 1);
@ -453,6 +493,9 @@ async function handshake(){
/*
User defined FUN-ctions!!!
*/
var textbuffer = "";
var first_append = true;
function appendmessage(msg, user, render = true){
var filetext = "";
@ -470,7 +513,15 @@ function appendmessage(msg, user, render = true){
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} " +
msg.text.trim()
.replace(
@ -485,8 +536,9 @@ function appendmessage(msg, user, render = true){
return "{light-red-fg}" + match + "{/light-red-fg}"
}
) +
filetext
);
filetext;
messagelist.setContent(textbuffer);
if(render){
messagelist.setScrollPerc(100);
@ -498,21 +550,21 @@ deek.on("login", function(channel){
messagelist =
blessed.box({
parent:screen,
label:'{bold}{cyan-fg}#' + channel.name + '{/cyan-fg}{/bold}',
tags:true,
border:'line',
width:"100%",
top:0,
left:0,
bottom:1,
scrollable:true,
scrollbar:{
parent: screen,
label: '{bold}{cyan-fg}#' + channel.name + '{/cyan-fg}{/bold}',
tags: true,
border: 'line',
width: "100%",
top: 0,
left: 0,
bottom: 1,
scrollable: true,
scrollbar: {
ch:'',
track:{
bg:'cyan'
track: {
bg: 'cyan'
},
style:{
style: {
inverse:true
}
}
@ -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();
messagelist.setScrollPerc(100);
@ -640,14 +692,14 @@ deek.on("login", function(channel){
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);
screen.render();
});
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);
screen.render();
});
@ -659,7 +711,7 @@ deek.on("message", async function(msg, user){
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);
screen.render();
});

View File

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