xeno pagination
This commit is contained in:
parent
c704e2dfa0
commit
6fa398847a
236
client.js
236
client.js
|
@ -14,12 +14,13 @@ const emitter = require("events");
|
|||
const deek = new emitter();
|
||||
|
||||
const name = "rena_chan";
|
||||
const password = "pass";
|
||||
const mc_password = "pass";
|
||||
const password = "fuckyou";
|
||||
const mc_password = "fuckyou";
|
||||
const userid = 12;
|
||||
var channels = [];
|
||||
var ws = [];
|
||||
var ddg_cache = [];
|
||||
var results_cache = [];
|
||||
var is_pp_xeno = false;
|
||||
var ddg_mod = true; // dont show porn in .img
|
||||
var global_page = 1; // .img page
|
||||
var raid = false; // raid?
|
||||
|
@ -40,16 +41,36 @@ var headers = {
|
|||
/*
|
||||
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){
|
||||
|
||||
if(mc_logged_in){
|
||||
|
||||
var txt = message.split("\n");
|
||||
// ascii filter
|
||||
message = message.replace(
|
||||
/[^-!\"#$%&'()*+,.\/0123456789:;<=>?@[\\\]^_'abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«» ]/gi,
|
||||
""
|
||||
);
|
||||
|
||||
var txt_out = "";
|
||||
txt.forEach(function(a){
|
||||
username = mc_escape(username);
|
||||
|
||||
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(
|
||||
/[^-!\"#$%&'()*+,.\/0123456789:;<=>?@[\\\]^_'abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«» ]/gi,
|
||||
""
|
||||
);
|
||||
).replace(/[\\"']/g, '\\$&')
|
||||
.replace(/\u0000/g, '\\0')
|
||||
.replace("\n", " ");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -385,31 +408,14 @@ async function handshake(name, password){
|
|||
const mineflayer = require('mineflayer');
|
||||
var mc_logged_in = false;
|
||||
|
||||
const mc = mineflayer.createBot({
|
||||
const mc_options = {
|
||||
host: 'deek.chat',
|
||||
username: name,
|
||||
auth: 'offline',
|
||||
port: 25565
|
||||
});
|
||||
};
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
/*
|
||||
User defined FUN-ctions!!!
|
||||
*/
|
||||
deek.on("login", function(channel){
|
||||
|
||||
console.log("Connected to websocket xoxo");
|
||||
function bind_mc_chat_events(){
|
||||
|
||||
mc.on("chat", function(username, message){
|
||||
if(username === mc.username){
|
||||
|
@ -435,30 +441,108 @@ deek.on("login", function(channel){
|
|||
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:
|
||||
mc.on("kicked", function(msg){
|
||||
|
||||
mc_logged_in = false;
|
||||
console.log(msg);
|
||||
console.log("kicked", msg);
|
||||
});
|
||||
|
||||
mc.on("error", function(msg){
|
||||
|
||||
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){
|
||||
|
@ -525,7 +609,7 @@ deek.on("message", async function(msg, user){
|
|||
|
||||
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];
|
||||
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_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_property_og_title.length !== 0){ title = tag_property_og_title.attr("content"); }
|
||||
if(tag_title.length !== 0){ title = tag_title.text(); }
|
||||
|
||||
|
||||
// get description
|
||||
|
@ -833,7 +917,8 @@ deek.on("message", async function(msg, user){
|
|||
}
|
||||
).then(async results => {
|
||||
|
||||
ddg_cache = results;
|
||||
is_pp_xeno = false;
|
||||
results_cache = results;
|
||||
|
||||
if(results.length === 0){
|
||||
|
||||
|
@ -883,7 +968,6 @@ deek.on("message", async function(msg, user){
|
|||
|
||||
case "page":
|
||||
case "p":
|
||||
|
||||
value = parseInt(value);
|
||||
if(
|
||||
isNaN(value) ||
|
||||
|
@ -894,35 +978,48 @@ deek.on("message", async function(msg, user){
|
|||
return;
|
||||
}
|
||||
|
||||
if(ddg_cache.length === 0){
|
||||
if(results_cache.length === 0){
|
||||
|
||||
send(msg, "Search buffer doesn't contain any links you horse fucker!!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(
|
||||
value > ddg_cache.length ||
|
||||
value > results_cache.length ||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
case "pp":
|
||||
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!!");
|
||||
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;
|
||||
|
||||
case "youtube":
|
||||
|
@ -934,25 +1031,30 @@ deek.on("message", async function(msg, user){
|
|||
break;
|
||||
}
|
||||
|
||||
var res = await fetch("https://4get.zzls.xyz/api/v1/videos?s=" + encodeURIComponent(value));
|
||||
var res_get = await res.json();
|
||||
try{
|
||||
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);
|
||||
break;
|
||||
}
|
||||
send(msg, "Shit!!!!! 4get sucks balls and returned this error: " + res_get.status);
|
||||
break;
|
||||
}
|
||||
|
||||
if(res_get.video.length === 0){
|
||||
if(res_get.video.length === 0){
|
||||
|
||||
send(msg, "No results found for " + value + "!!");
|
||||
break;
|
||||
}
|
||||
send(msg, "No results found for " + value + "!!");
|
||||
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);
|
||||
break;
|
||||
send(msg, "4get sucks!!!!! It returned ERRRO!!RRRO!!O!O!O!11\n>" + res_get.status);
|
||||
break;
|
||||
}
|
||||
}catch(error){
|
||||
|
||||
send(msg, "4get returned invalid response!!!!!! piece of fuckgin shit!!!11!111");
|
||||
}
|
||||
|
||||
var text = [];
|
||||
|
@ -977,6 +1079,7 @@ deek.on("message", async function(msg, user){
|
|||
|
||||
case "x":
|
||||
case "xeno":
|
||||
case "xeno-canto":
|
||||
if(value.trim() == ""){
|
||||
|
||||
send(
|
||||
|
@ -998,23 +1101,10 @@ deek.on("message", async function(msg, user){
|
|||
break;
|
||||
}
|
||||
|
||||
var filereq = await fetch(
|
||||
res_get.recordings[0].file,
|
||||
{headers: img_headers}
|
||||
);
|
||||
is_pp_xeno = true;
|
||||
results_cache = res_get.recordings;
|
||||
|
||||
var file = await filereq.buffer();
|
||||
|
||||
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"
|
||||
]
|
||||
);
|
||||
await fetch_xeno(res_get.recordings, 1, msg);
|
||||
break;
|
||||
|
||||
case "help":
|
||||
|
|
Loading…
Reference in New Issue