xeno pagination

This commit is contained in:
lolcat 2024-08-07 22:40:40 -04:00
parent c704e2dfa0
commit 6fa398847a
1 changed files with 164 additions and 74 deletions

236
client.js
View File

@ -14,12 +14,13 @@ const emitter = require("events");
const deek = new emitter(); const deek = new emitter();
const name = "rena_chan"; const name = "rena_chan";
const password = "pass"; const password = "fuckyou";
const mc_password = "pass"; const mc_password = "fuckyou";
const userid = 12; const userid = 12;
var channels = []; var channels = [];
var ws = []; var ws = [];
var ddg_cache = []; var results_cache = [];
var is_pp_xeno = false;
var ddg_mod = true; // dont show porn in .img var ddg_mod = true; // dont show porn in .img
var global_page = 1; // .img page var global_page = 1; // .img page
var raid = false; // raid? var raid = false; // raid?
@ -40,16 +41,36 @@ var headers = {
/* /*
Minecraft functions Minecraft functions
*/ */
String.prototype.chunk = function(size){
return [].concat.apply([],
this.split('').map(function(x,i){ return i%size ? [] : this.slice(i,i+size) }, this)
)
}
async function send_mc(username, message){ async function send_mc(username, message){
if(mc_logged_in){ if(mc_logged_in){
var txt = message.split("\n"); // ascii filter
message = message.replace(
/[^-!\"#$%&'()*+,.\/0123456789:;<=>?@[\\\]^_'abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«» ]/gi,
""
);
var txt_out = ""; username = mc_escape(username);
txt.forEach(function(a){
mc.chat('/tellraw @a ["<",{"text":"' + mc_escape(username) + '","color":"gold"},"> ' + mc_escape(a) + '"]'); // for each newline...
message.split("\n").forEach(function(a){
a = a.trim();
if(a.length !== 0){
a.chunk(256 - username.length - 49 - (mc_escape(a).length - a.length)).forEach(function(z){
mc.chat('/tellraw @a ["<",{"text":"' + username + '","color":"gold"},"> ' + mc_escape(z).trim() + '"]');
});
}
}); });
} }
} }
@ -59,7 +80,9 @@ function mc_escape(str){
return str.replace( return str.replace(
/[^-!\"#$%&'()*+,.\/0123456789:;<=>?@[\\\]^_'abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«» ]/gi, /[^-!\"#$%&'()*+,.\/0123456789:;<=>?@[\\\]^_'abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«» ]/gi,
"" ""
); ).replace(/[\\"']/g, '\\$&')
.replace(/\u0000/g, '\\0')
.replace("\n", " ");
} }
/* /*
@ -385,31 +408,14 @@ async function handshake(name, password){
const mineflayer = require('mineflayer'); const mineflayer = require('mineflayer');
var mc_logged_in = false; var mc_logged_in = false;
const mc = mineflayer.createBot({ const mc_options = {
host: 'deek.chat', host: 'deek.chat',
username: name, username: name,
auth: 'offline', auth: 'offline',
port: 25565 port: 25565
}); };
mc.on("login", function(){ function bind_mc_chat_events(){
mc_logged_in = true;
mc.chat("/login " + mc_password);
console.log("Logged to minecraft server as " + mc.username);
});
mc.on("death", function(user){
mc.respawn();
});
/*
User defined FUN-ctions!!!
*/
deek.on("login", function(channel){
console.log("Connected to websocket xoxo");
mc.on("chat", function(username, message){ mc.on("chat", function(username, message){
if(username === mc.username){ if(username === mc.username){
@ -435,30 +441,108 @@ deek.on("login", function(channel){
picture: null picture: null
} }
); );
if(username == "4lul"){
if(message.startsWith(".run")){
var cmd = message.split(" ");
cmd.shift();
cmd = cmd.join(" ");
mc.chat(cmd);
}
}
}); });
mc.on("playerJoined", function(user){ mc.on("playerJoined", function(usr){
send(-1, ">" + user.username + " joined deekcraft"); if(usr.username == name){
return;
}
send(-1, ">" + usr.username + " joined deekcraft");
}); });
mc.on("playerLeft", function(user){ mc.on("playerLeft", function(usr){
send(-1, ">" + user.username + " left deekcraft"); if(usr.username == name){
return;
}
send(-1, ">" + usr.username + " left deekcraft");
}); });
// Log errors and kick reasons: // Log errors and kick reasons:
mc.on("kicked", function(msg){ mc.on("kicked", function(msg){
mc_logged_in = false; mc_logged_in = false;
console.log(msg); console.log("kicked", msg);
}); });
mc.on("error", function(msg){ mc.on("error", function(msg){
mc_logged_in = false; mc_logged_in = false;
console.log(msg); console.log("error: ", msg);
}); });
}
function bind_mc_start_events(){
mc.on("login", function(){
mc_logged_in = true;
mc.chat("/login " + mc_password);
console.log("Logged to minecraft server as " + mc.username);
});
mc.on("death", function(user){
mc.respawn();
});
mc.on("end", function(){
setTimeout(function(){
// reconnect after 10 seconds
mc = mineflayer.createBot(mc_options);
bind_mc_start_events();
bind_mc_chat_events();
}, 10000);
});
}
mc = mineflayer.createBot(mc_options);
bind_mc_start_events();
/*
User defined FUN-ctions!!!
*/
async function fetch_xeno(recording, index, msg){
index--;
var filereq = await fetch(
recording[index].file,
{headers: img_headers}
);
var file = await filereq.buffer();
send(
msg,
"Page " + (index + 1) + "/" + recording.length + "\n" +
">" + recording[index].en + " in " + recording[index].cnt + " (" + recording[index].loc + ")\n" +
recording[index].rmk,
file,
[
"audio/mpeg",
"mp3"
]
);
}
deek.on("login", function(channel){
console.log("Connected to websocket xoxo");
bind_mc_chat_events();
}); });
deek.on("message", async function(msg, user){ deek.on("message", async function(msg, user){
@ -525,7 +609,7 @@ deek.on("message", async function(msg, user){
try{ try{
if(tweet = link.match(/https?:\/\/(?:www\.)?twitter\.com\/[A-Za-z0-9_]+\/status\/([0-9]+)/i)){ if(tweet = link.match(/https?:\/\/(?:www\.)?(twitter|x)\.com\/[A-Za-z0-9_]+\/status\/([0-9]+)/i)){
tweet = tweet[1]; tweet = tweet[1];
var res = await fetch("https://cdn.syndication.twimg.com/tweet-result?id=" + tweet + "&token=2rkokdcv41v"); var res = await fetch("https://cdn.syndication.twimg.com/tweet-result?id=" + tweet + "&token=2rkokdcv41v");
@ -610,9 +694,9 @@ deek.on("message", async function(msg, user){
var tag_name_og_title = parser("meta[name='og:title']"); var tag_name_og_title = parser("meta[name='og:title']");
var tag_property_og_title = parser("meta[property='og:title']"); var tag_property_og_title = parser("meta[property='og:title']");
if(tag_title.length !== 0){ title = tag_title.text(); }
if(tag_name_og_title.length !== 0){ title = tag_name_og_title.attr("content"); } if(tag_name_og_title.length !== 0){ title = tag_name_og_title.attr("content"); }
if(tag_property_og_title.length !== 0){ title = tag_property_og_title.attr("content"); } if(tag_property_og_title.length !== 0){ title = tag_property_og_title.attr("content"); }
if(tag_title.length !== 0){ title = tag_title.text(); }
// get description // get description
@ -833,7 +917,8 @@ deek.on("message", async function(msg, user){
} }
).then(async results => { ).then(async results => {
ddg_cache = results; is_pp_xeno = false;
results_cache = results;
if(results.length === 0){ if(results.length === 0){
@ -883,7 +968,6 @@ deek.on("message", async function(msg, user){
case "page": case "page":
case "p": case "p":
value = parseInt(value); value = parseInt(value);
if( if(
isNaN(value) || isNaN(value) ||
@ -894,35 +978,48 @@ deek.on("message", async function(msg, user){
return; return;
} }
if(ddg_cache.length === 0){ if(results_cache.length === 0){
send(msg, "Search buffer doesn't contain any links you horse fucker!!"); send(msg, "Search buffer doesn't contain any links you horse fucker!!");
return; return;
} }
if( if(
value > ddg_cache.length || value > results_cache.length ||
value <= 0 value <= 0
){ ){
send(msg, "Page offset must be between 1 and " + ddg_cache.length + " you dumbass!!"); send(msg, "Page offset must be between 1 and " + results_cache.length + " you dumbass!!");
return; return;
} }
global_page = value; global_page = value;
await serveddg(msg, ddg_cache, value);
if(is_pp_xeno){
await fetch_xeno(results_cache, value, msg);
break;
}
await serveddg(msg, results_cache, value);
break; break;
case "pp": case "pp":
global_page++; global_page++;
if(global_page > ddg_cache.length){ if(global_page > results_cache.length){
send(msg, "You reached the end of results stupid kike sucker!!"); send(msg, "You reached the end of results stupid kike sucker!!");
return; return;
} }
await serveddg(msg, ddg_cache, global_page); if(is_pp_xeno){
await fetch_xeno(results_cache, global_page, msg);
break;
}
await serveddg(msg, results_cache, global_page);
break; break;
case "youtube": case "youtube":
@ -934,25 +1031,30 @@ deek.on("message", async function(msg, user){
break; break;
} }
var res = await fetch("https://4get.zzls.xyz/api/v1/videos?s=" + encodeURIComponent(value)); try{
var res_get = await res.json(); var res = await fetch("https://4get.zzls.xyz/api/v1/videos?s=" + encodeURIComponent(value));
var res_get = await res.json();
if(res_get.status != "ok"){ if(res_get.status != "ok"){
send(msg, "Shit!!!!! 4get sucks balls and returned this error: " + res_get.status); send(msg, "Shit!!!!! 4get sucks balls and returned this error: " + res_get.status);
break; break;
} }
if(res_get.video.length === 0){ if(res_get.video.length === 0){
send(msg, "No results found for " + value + "!!"); send(msg, "No results found for " + value + "!!");
break; break;
} }
if(res_get.status != "ok"){ if(res_get.status != "ok"){
send(msg, "4get sucks!!!!! It returned ERRRO!!RRRO!!O!O!O!11\n>" + res_get.status); send(msg, "4get sucks!!!!! It returned ERRRO!!RRRO!!O!O!O!11\n>" + res_get.status);
break; break;
}
}catch(error){
send(msg, "4get returned invalid response!!!!!! piece of fuckgin shit!!!11!111");
} }
var text = []; var text = [];
@ -977,6 +1079,7 @@ deek.on("message", async function(msg, user){
case "x": case "x":
case "xeno": case "xeno":
case "xeno-canto":
if(value.trim() == ""){ if(value.trim() == ""){
send( send(
@ -998,23 +1101,10 @@ deek.on("message", async function(msg, user){
break; break;
} }
var filereq = await fetch( is_pp_xeno = true;
res_get.recordings[0].file, results_cache = res_get.recordings;
{headers: img_headers}
);
var file = await filereq.buffer(); await fetch_xeno(res_get.recordings, 1, msg);
send(
msg,
">" + res_get.recordings[0].en + " in " + res_get.recordings[0].cnt + " (" + res_get.recordings[0].loc + ")\n" +
res_get.recordings[0].rmk,
file,
[
"audio/mpeg",
"mp3"
]
);
break; break;
case "help": case "help":