added irc brigde
This commit is contained in:
parent
d21adf0dc1
commit
98b71ac466
117
client.js
117
client.js
|
@ -1,5 +1,6 @@
|
|||
const fs = require("fs");
|
||||
const websocket = require("ws");
|
||||
var irc = require("irc");
|
||||
const fetch = require("node-fetch");
|
||||
const formdata = require("form-data");
|
||||
const he = require("he");
|
||||
|
@ -10,8 +11,9 @@ var Magic = mmm.Magic;
|
|||
var ws_logged_in = false;
|
||||
|
||||
const mineflayer = require("mineflayer");
|
||||
const mc_bridge_enabled = true;
|
||||
const instance = "https://4get.tux.pizza";
|
||||
const mc_bridge_enabled = false;
|
||||
const irc_bridge_enabled = true;
|
||||
const instance = "https://4get.lumaeris.com";
|
||||
var scraper = "ddg";
|
||||
|
||||
const mc_options = {
|
||||
|
@ -21,13 +23,16 @@ const mc_options = {
|
|||
// offline mode
|
||||
};
|
||||
|
||||
const irc_ip = "192.168.0.152";
|
||||
|
||||
var http = require("http");
|
||||
|
||||
const emitter = require("events");
|
||||
const deek = new emitter();
|
||||
|
||||
const name = "rena_chan";
|
||||
const password = "yourmom";
|
||||
const password = "no";
|
||||
const irc_password = "no";
|
||||
const userid = 12;
|
||||
var channels = [];
|
||||
var ws = [];
|
||||
|
@ -193,7 +198,7 @@ async function serveddg(msg, results, page){
|
|||
|
||||
send(
|
||||
msg,
|
||||
"Page " + (page + 1) + "/" + (results.length) + "\n[" + results[page].source[0].width + "x" + results[page].source[0].height + "] " + results[page].title + "\n" + results[page].source[0].url,
|
||||
"Page " + (page + 1) + "/" + (results.length) + "\n[" + results[page].source[0].width + "x" + results[page].source[0].height + "] " + results[page].title + "\n" + results[page].url,
|
||||
res_get
|
||||
);
|
||||
}
|
||||
|
@ -528,6 +533,81 @@ function mc_escape(str){
|
|||
.replace("\n", " ");
|
||||
}
|
||||
|
||||
/*
|
||||
IRC bridge
|
||||
*/
|
||||
var irc_logged_in = false;
|
||||
var irc_debounce = false;
|
||||
var irc_client = null;
|
||||
|
||||
function init_irc(){
|
||||
if(irc_bridge_enabled === false){
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
irc_client =
|
||||
new irc.Client(
|
||||
irc_ip,
|
||||
"rena_chan",
|
||||
{
|
||||
channels: [
|
||||
"#deekchat"
|
||||
],
|
||||
userName: "rena_chan",
|
||||
realName: "Rena Chan",
|
||||
autoRejoin: false,
|
||||
retryCount: 0
|
||||
}
|
||||
);
|
||||
|
||||
irc_client.addListener("join#deekchat", function(){
|
||||
|
||||
console.log("Connected to IRC server on #deekchat");
|
||||
irc_logged_in = true;
|
||||
|
||||
irc_client.say("NickServ", "IDENTIFY rena_chan " + irc_password);
|
||||
irc_client.send("OPER", "rena_chan", irc_password);
|
||||
|
||||
// add debounce so we dont send missed messages
|
||||
setTimeout(function(){
|
||||
|
||||
irc_debounce = true;
|
||||
}, 2500);
|
||||
});
|
||||
|
||||
irc_client.addListener("message", function(from, to, message){
|
||||
|
||||
if(irc_debounce === false){ return; }
|
||||
|
||||
if(typeof from == "undefined"){ return; }
|
||||
|
||||
switch(to){
|
||||
|
||||
case "#deekchat":
|
||||
send(1, "<" + from + "> " + message);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
irc_client.addListener("error", function(message){
|
||||
|
||||
console.log("IRC error");
|
||||
console.log(message);
|
||||
|
||||
irc_logged_in = false;
|
||||
irc_debounce = false;
|
||||
irc_client.disconnect();
|
||||
|
||||
setTimeout(function(){
|
||||
|
||||
init_irc();
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
init_irc();
|
||||
|
||||
/*
|
||||
User defined FUN-ctions!!!
|
||||
*/
|
||||
|
@ -608,8 +688,6 @@ deek.on("message", async function(msg, user){
|
|||
// split message into newlines
|
||||
// make sure message gets sent in chunks
|
||||
|
||||
var chunks = [];
|
||||
|
||||
for(var i=0; i<a.length; i += 100){
|
||||
|
||||
if(i === 0){
|
||||
|
@ -623,6 +701,28 @@ deek.on("message", async function(msg, user){
|
|||
});
|
||||
}
|
||||
|
||||
if(
|
||||
irc_bridge_enabled &&
|
||||
irc_logged_in &&
|
||||
msg.channel === 1
|
||||
){
|
||||
|
||||
msg.text.split("\n").forEach(function(a){
|
||||
|
||||
var limit = 412 - ("RELAYMSG #deekchat " + user.name + "/Dek").length;
|
||||
|
||||
for(var i=0; i<a.length; i += limit){
|
||||
|
||||
irc_client.send("RELAYMSG", "#deekchat", user.name + "/Dek", a.slice(i, i + limit));
|
||||
}
|
||||
});
|
||||
|
||||
for(var i=0; i<msg.files.length; i++){
|
||||
|
||||
irc_client.send("RELAYMSG", "#deekchat", user.name + "/Dek", msg.files[i]);
|
||||
}
|
||||
}
|
||||
|
||||
switch(msg.text.toLowerCase()){
|
||||
|
||||
case "hello rena":
|
||||
|
@ -1036,7 +1136,7 @@ deek.on("message", async function(msg, user){
|
|||
global_page = 1;
|
||||
|
||||
try{
|
||||
var res = await fetch(instance + "/api/v1/images?s=" + encodeURIComponent(value) + "&nsfw" + (ddg_mod ? "no" : "yes") + "&scraper=" + scraper);
|
||||
var res = await fetch(instance + "/api/v1/images?s=" + encodeURIComponent(value) + "&nsfw=" + (ddg_mod ? "no" : "yes") + "&scraper=" + scraper);
|
||||
var res_get = await res.json();
|
||||
|
||||
if(res_get.status != "ok"){
|
||||
|
@ -1053,6 +1153,7 @@ deek.on("message", async function(msg, user){
|
|||
}catch(error){
|
||||
|
||||
send(msg, "4get returned invalid response!!!!!! piece of fuckgin shit!!!11!111");
|
||||
break;
|
||||
}
|
||||
|
||||
results_cache = res_get.image;
|
||||
|
@ -1080,7 +1181,7 @@ deek.on("message", async function(msg, user){
|
|||
break;
|
||||
|
||||
default:
|
||||
send(msg, "Choices are: ddg, yandex, brave, google, google_cse, startpage, qwant, yep, solofield, imgur, ftm");
|
||||
send(msg, ">Current scraper: " + scraper +"\nChoices are: ddg, yandex, brave, google, google_cse, startpage, qwant, yep, solofield, imgur, ftm");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue