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

260
client.js
View File

@ -5,7 +5,6 @@ const formdata = require("form-data");
const he = require("he"); const he = require("he");
const cheerio = require("cheerio"); const cheerio = require("cheerio");
const ddg = require("duckduckgo-images-api"); const ddg = require("duckduckgo-images-api");
const yt = require("ytsr");
var mmm = require("mmmagic"); var mmm = require("mmmagic");
var Magic = mmm.Magic; var Magic = mmm.Magic;
@ -31,7 +30,7 @@ var img_headers = {
}; };
var 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" Origin: "https://deek.chat"
}; };
@ -123,22 +122,12 @@ async function send(channel, text, file = null){
channel = channel.channel; channel = channel.channel;
} }
for(var i=0; i<channels.length; i++){
if(channels[i].id === channel){
var arraypos = i;
break;
}
}
if(file === null){ if(file === null){
channels[arraypos].ws.send(JSON.stringify({ ws.send(JSON.stringify({
type: "messageEnd", type: "messageEnd",
data: { data: text,
message: text roomId: channel
}
})); }));
return; return;
@ -147,7 +136,6 @@ async function send(channel, text, file = null){
/* /*
Send file Send file
*/ */
var mimetype = await getmime(file); var mimetype = await getmime(file);
var form_data = new formdata(); var form_data = new formdata();
@ -225,82 +213,11 @@ async function handshake(name, password){
headers.cookie = "session_id=" + session_id[1] + "; api_token=" + api_token[1]; headers.cookie = "session_id=" + session_id[1] + "; api_token=" + api_token[1];
/* /*
Scrape channel list Connect to websocket serber
*/ */
console.log("getting subscribed channels"); ws = new websocket(
"wss://deek.chat/ws",
var subscribed = await fetch(
"https://deek.chat/rooms/fetch/subscribed",
{
method: "GET",
headers: headers
}
);
var res = await subscribed.buffer();
res = JSON.parse(res.toString("utf8"));
shittierloop:
for(var i=0; i<res.length; i++){
for(var k=0; k<channels.length; k++){
if(channels[k].id === res[i].room.id){
continue shittierloop;
}
}
channels.push({
name: res[i].room.name,
id: res[i].room.id,
users: []
});
}
for(var i=0; i<channels.length; i++){
/*
Scrape users
*/
console.log("getting users for " + channels[i].name + " (id:" + channels[i].id + ")");
var users = await fetch(
"https://deek.chat/users/" + channels[i].id,
{
method: "GET",
headers: headers
}
);
var res = await users.buffer();
res = JSON.parse(res.toString("utf8"));
if(res === null){
res = [];
}
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, protocolVersion: 13,
encoding: "utf8", encoding: "utf8",
@ -308,19 +225,17 @@ async function handshake(name, password){
} }
); );
var pass = i; ws.once("open", function(){
channels[i].ws.once("open", function(){ deek.emit("login");
deek.emit("login", channels[pass]);
}); });
channels[i].ws.once("close", function(){ ws.once("close", function(){
deek.emit("close", channels[pass]); deek.emit("close");
}); });
channels[i].ws.on("message", function(message, isbin){ ws.on("message", function(message, isbin){
if(isbin){ return; } if(isbin){ return; }
@ -333,71 +248,69 @@ async function handshake(name, password){
switch(m.type){ switch(m.type){
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":
var files = []
m.message.files = m.message.files === null ? [] : m.message.files; for(var k=0; k<m.data.files.length; k++){
var files = [];
for(var k=0; k<m.message.files.length; k++){ files.push("https://deek.chat/storage/files/" + m.data.files[k].name);
files.push("https://deek.chat/storage/files/" + m.message.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.userId,
picture: m.message.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.message.profilePicture picture: m.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.profilePicture
} }
); );
break; break;
@ -408,7 +321,6 @@ async function handshake(name, password){
} }
}); });
} }
}
/* /*
@ -416,7 +328,7 @@ async function handshake(name, password){
*/ */
deek.on("login", function(channel){ 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){ deek.on("message", async function(msg, user){
@ -843,95 +755,45 @@ deek.on("message", async function(msg, user){
case "youtube": case "youtube":
case "jewtube": case "jewtube":
case "yt": case "yt":
if(value.trim() == ""){ if(value.trim() == ""){
send(msg, "You need to search for something cum licker!!!"); send(msg, "You need to search for something cum licker!!!");
return; 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 + "!!"); send(msg, "No results found for " + value + "!!");
return; return;
} }
var text = ""; if(res_get.status != "ok"){
var k = 0; send(msg, "4get sucks!!!!! It returned ERRRO!!RRRO!!O!O!O!11\n>" + res_get.status);
for(var i=0; i<ytsearch.items.length; i++){ return;
}
if(k === 3){ var text = [];
for(var i=0; i<res_get.video.length; i++){
if(i === 3){
break; break;
} }
if(ytsearch.items[i].type != "video"){ text.push(
">Duration: " + (new Date(res_get.video[i].duration * 1000).toISOString().slice(11, 19)) +
continue; " • 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
);
} }
if(typeof ytsearch.items[i].badges != "undefined"){ send(msg, "Search results for \"" + value + "\"\n\n" + text.join("\n\n"));
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++;
}
send(msg, "Search results for \"" + ytsearch.correctedQuery + "\"\n\n" + text.trim());
break; break;
case "help": case "help":
@ -944,7 +806,7 @@ deek.on("message", async function(msg, user){
".boobs <yes:no> => Boobs?\n" + ".boobs <yes:no> => Boobs?\n" +
".page/.p => get page offset for image search\n" + ".page/.p => get page offset for image search\n" +
".pp => get next page\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" + ".roll/.r => Because deekchat was too slow\n" +
".mumble/.m <[optional]ip:port> => check if lolcat died\n" + ".mumble/.m <[optional]ip:port> => check if lolcat died\n" +
".prop => check if the sun has exploded or smth\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){ 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(){ setTimeout(function(){