i need to stop deeking around

This commit is contained in:
lolcat 2023-10-02 22:51:09 -05:00
parent 3fda0d744d
commit c697fa31a1
1 changed files with 119 additions and 257 deletions

366
client.js
View File

@ -5,7 +5,6 @@ const formdata = require("form-data");
const he = require("he");
const cheerio = require("cheerio");
const ddg = require("duckduckgo-images-api");
const yt = require("ytsr");
var mmm = require("mmmagic");
var Magic = mmm.Magic;
@ -31,7 +30,7 @@ var img_headers = {
};
var headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0",
"User-Agent": "renabot",
Origin: "https://deek.chat"
};
@ -123,22 +122,12 @@ async function send(channel, text, file = null){
channel = channel.channel;
}
for(var i=0; i<channels.length; i++){
if(channels[i].id === channel){
var arraypos = i;
break;
}
}
if(file === null){
channels[arraypos].ws.send(JSON.stringify({
ws.send(JSON.stringify({
type: "messageEnd",
data: {
message: text
}
data: text,
roomId: channel
}));
return;
@ -147,7 +136,6 @@ async function send(channel, text, file = null){
/*
Send file
*/
var mimetype = await getmime(file);
var form_data = new formdata();
@ -225,189 +213,113 @@ async function handshake(name, password){
headers.cookie = "session_id=" + session_id[1] + "; api_token=" + api_token[1];
/*
Scrape channel list
Connect to websocket serber
*/
console.log("getting subscribed channels");
var subscribed = await fetch(
"https://deek.chat/rooms/fetch/subscribed",
ws = new websocket(
"wss://deek.chat/ws",
{
method: "GET",
protocolVersion: 13,
encoding: "utf8",
headers: headers
}
);
var res = await subscribed.buffer();
res = JSON.parse(res.toString("utf8"));
ws.once("open", function(){
shittierloop:
for(var i=0; i<res.length; i++){
deek.emit("login");
});
for(var k=0; k<channels.length; k++){
ws.once("close", function(){
if(channels[k].id === res[i].room.id){
deek.emit("close");
});
continue shittierloop;
}
ws.on("message", function(message, isbin){
if(isbin){ return; }
var m = JSON.parse(message.toString("utf8"));
if(typeof m.type == "undefined"){
return;
}
channels.push({
name: res[i].room.name,
id: res[i].room.id,
users: []
});
}
switch(m.type){
for(var i=0; i<channels.length; i++){
case "messageEnd":
for(var k=0; k<m.data.mentions.length; k++){
/*
Scrape users
*/
console.log("getting users for " + channels[i].name + " (id:" + channels[i].id + ")");
m.data.mentions[k].id = m.data.mentions[k].userId;
delete m.data.mentions[k].userId;
}
var users = await fetch(
"https://deek.chat/users/" + channels[i].id,
{
method: "GET",
headers: headers
}
);
for(var k=0; k<m.data.replies.length; k++){
var res = await users.buffer();
res = JSON.parse(res.toString("utf8"));
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;
}
if(res === null){
m.data.files = m.data.files === null ? [] : m.data.files;
var files = [];
res = [];
for(var k=0; k<m.data.files.length; k++){
files.push("https://deek.chat/storage/files/" + m.data.files[k].name);
}
deek.emit(
"message",
{
text: removehtml(m.data.text),
id: m.data.id,
files: files,
mentions: m.data.mentions,
replies: m.data.replies,
channel: m.roomId
},
{
name: m.data.name,
id: m.userId,
picture: m.data.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.data.profilePicture
}
);
break;
case "files":
var files = []
for(var k=0; k<m.data.files.length; k++){
files.push("https://deek.chat/storage/files/" + m.data.files[k].name);
}
deek.emit(
"message",
{
text: removehtml(m.data.text),
id: m.data.id,
files: files,
mentions: m.data.mentions,
replies: m.data.replies,
channel: m.roomId
},
{
name: m.data.name,
id: m.userId,
picture: m.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.profilePicture
}
);
break;
default:
//console.warn(m);
break;
}
for(var k=0; k<res.length; k++){
channels[i].users.push({
name: res[k].name,
id: res[k].id,
country: {
name: res[k].countryName,
code: res[k].countryIso.toUpperCase()
},
picture: res[k].profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + res[k].profilePicture
});
}
/*
Connect to websocket serbers
*/
channels[i].ws = new websocket(
"wss://deek.chat/ws/" + channels[i].id,
{
protocolVersion: 13,
encoding: "utf8",
headers: headers
}
);
var pass = i;
channels[i].ws.once("open", function(){
deek.emit("login", channels[pass]);
});
channels[i].ws.once("close", function(){
deek.emit("close", channels[pass]);
});
channels[i].ws.on("message", function(message, isbin){
if(isbin){ return; }
var m = JSON.parse(message.toString("utf8"));
if(typeof m.type == "undefined"){
return;
}
switch(m.type){
case "messageEnd":
for(var k=0; k<m.data.message.mentions.length; k++){
m.data.message.mentions[k].id = m.data.message.mentions[k].userId;
delete m.data.message.mentions[k].userId;
}
for(var k=0; k<m.data.message.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.message.files = m.data.message.files === null ? [] : m.data.message.files;
var files = [];
for(var k=0; k<m.data.message.files.length; k++){
files.push("https://deek.chat/storage/files/" + m.data.message.files[k].name);
}
deek.emit(
"message",
{
text: removehtml(m.data.message.text),
id: m.data.message.id,
files: files,
mentions: m.data.message.mentions,
replies: m.data.message.replies,
channel: m.roomId
},
{
name: m.data.message.name,
id: m.userId,
picture: m.data.message.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.data.message.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++){
files.push("https://deek.chat/storage/files/" + m.message.files[k].name);
}
deek.emit(
"message",
{
text: removehtml(m.message.text),
id: m.message.id,
files: files,
mentions: m.message.mentions,
replies: m.message.replies,
channel: m.roomId
},
{
name: m.message.name == "" ? null : m.message.name,
id: m.userId,
picture: m.message.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.message.profilePicture
}
);
break;
default:
//console.warn(m);
break;
}
});
}
});
}
@ -416,7 +328,7 @@ async function handshake(name, password){
*/
deek.on("login", function(channel){
console.log("connected to channel " + channel.name + " (id:" + channel.id + ")");
console.log("Connected to websocket xoxo");
});
deek.on("message", async function(msg, user){
@ -843,95 +755,45 @@ deek.on("message", async function(msg, user){
case "youtube":
case "jewtube":
case "yt":
if(value.trim() == ""){
send(msg, "You need to search for something cum licker!!!");
return;
}
var ytsearch = await yt(value);
var res = await fetch("https://4get.ca/api/v1/videos?s=" + value);
var res_get = await res.json();
if(ytsearch.items.length === 0){
if(res_get.video.length === 0){
send(msg, "No results found for " + value + "!!");
return;
}
var text = "";
if(res_get.status != "ok"){
var k = 0;
for(var i=0; i<ytsearch.items.length; i++){
send(msg, "4get sucks!!!!! It returned ERRRO!!RRRO!!O!O!O!11\n>" + res_get.status);
return;
}
if(k === 3){
var text = [];
for(var i=0; i<res_get.video.length; i++){
if(i === 3){
break;
}
if(ytsearch.items[i].type != "video"){
continue;
}
if(typeof ytsearch.items[i].badges != "undefined"){
var items = ytsearch.items[i].badges;
}else{
var items = [];
}
if(
typeof ytsearch.items[i].duration != "undefined" &&
ytsearch.items[i].duration !== null
){
items.push("Duration: " + ytsearch.items[i].duration);
}
if(
typeof ytsearch.items[i].uploadedAt != "undefined" &&
ytsearch.items[i].uploadedAt !== null
){
var tmp = "";
if(!ytsearch.items[i].uploadedAt.includes("Streamed")){
tmp = "Posted ";
}
items.push(tmp + ytsearch.items[i].uploadedAt);
}
if(
typeof ytsearch.items[i].views != "undefined" &&
ytsearch.items[i].views !== null
){
items.push("Views: " + ytsearch.items[i].views);
}
if(
typeof ytsearch.items[i].author != "undefined" &&
typeof ytsearch.items[i].author.name != "undefined" &&
ytsearch.items[i].author.name !== null
){
items.push("Author: " + ytsearch.items[i].author.name);
}
if(items.length !== 0){
text += ">" + items.join(", ") + "\n";
}
text +=
ytsearch.items[i].title + "\n" +
"â–¶ https://www.youtube.com/watch?v=" + ytsearch.items[i].id + "\n\n";
k++;
text.push(
">Duration: " + (new Date(res_get.video[i].duration * 1000).toISOString().slice(11, 19)) +
" • views: " + (new Intl.NumberFormat().format(res_get.video[i].views)) +
" • author: " + res_get.video[i].author.name +
"\n" + res_get.video[i].title +
"\n▶ " + res_get.video[i].url
);
}
send(msg, "Search results for \"" + ytsearch.correctedQuery + "\"\n\n" + text.trim());
send(msg, "Search results for \"" + value + "\"\n\n" + text.join("\n\n"));
break;
case "help":
@ -944,7 +806,7 @@ deek.on("message", async function(msg, user){
".boobs <yes:no> => Boobs?\n" +
".page/.p => get page offset for image search\n" +
".pp => get next page\n" +
".yt/.youtube => search the jewish propaganda catalog\n" +
".yt/.youtube => search the jewish propaganda catalog (now powered by 4get)\n" +
".roll/.r => Because deekchat was too slow\n" +
".mumble/.m <[optional]ip:port> => check if lolcat died\n" +
".prop => check if the sun has exploded or smth\n" +
@ -956,7 +818,7 @@ deek.on("message", async function(msg, user){
deek.on("close", function(channel){
console.log("It's over. Disconnected from channel " + channel.name + ". Attempting reconnection in 10 seconds");
console.log("It's over. Disconnected from websocket. Attempting reconnection in 10 seconds");
setTimeout(function(){