local sync

This commit is contained in:
Flummi 2019-04-24 15:26:39 +02:00
parent 67b0fc291a
commit 175b994be3
12 changed files with 160 additions and 35 deletions

View File

@ -92,7 +92,7 @@ export class tg extends EventEmitter {
method: "POST",
body: {
chat_id: chatid,
text: msg,
text: msg.split("\n").length > 1 ? `<code>${msg}</code>` : msg,
parse_mode: "HTML"
}
};

View File

@ -9,9 +9,9 @@ const readdata = (res, mode, data = "") => new Promise((resolve, reject) => res
.on("end", () => {
switch(mode) {
case "text": resolve(data); break;
case "json": try { resolve(JSON.parse(data)); } catch(err) { reject("no json D:"); } break;
case "json": try { resolve(JSON.parse(data)); } catch(err) { reject(data); } break;
case "buffer": resolve(new Buffer.from(data)); break;
default: reject("lol no"); break;
default: reject("lol no D:"); break;
}
}));

View File

@ -16,7 +16,7 @@ import rape from "./rape";
import sandbox from "./sandbox";
import soundcloud from "./soundcloud";
import sysinfo from "./sysinfo";
import timer from "./timer";
import timer from "./timer1";
import urban from "./urban";
import nxy from "./useless_nxy";
import uwe from "./useless_uwe";

View File

@ -5,8 +5,8 @@ export default bot => {
call: /^\.irpg/i,
set: "uwe",
f: e => {
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
fetch("https://irpg.zneb.org/db.php")
//process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
fetch("https://f0ck.me/irpg/db.php")
.then(res => res.text())
.then(res => {
e.args[0] = e.args[0] || e.user.nick;

View File

@ -61,7 +61,7 @@ const sandbox = (lang, code) => {
method: "POST",
body: langs[lang]
};
fetch("http://rextester.com/rundotnet/api", options)
fetch("https://rextester.com/rundotnet/api", options)
.then(res => res.json())
.then(body => {
if (body.Errors) {
@ -76,7 +76,10 @@ const sandbox = (lang, code) => {
if (body.Result.length === 0)
return reject("lol keine Ausgabe");
resolve(body.Result);
}).catch(err => reject("Error!"));
}).catch(err => {
console.log(err);
reject("Error!");
});
});
};
@ -92,4 +95,4 @@ const bfgen = text => {
return out;
};
export { maxoutput, sandbox, bfgen, hsimports };
export { maxoutput, sandbox, bfgen, hsimports };

View File

@ -19,25 +19,23 @@ export default new class timer {
}
add(time, fn, begin = ~~(Date.now()/1000)) {
return new Promise((resolve, reject) => {
if(this.regex.test(time)) {
let seconds = 0;
time.match(/\d+(mon|[smhdwy])/g).forEach(t => {
const [,val,mod] = t.match(/(\d+)(mon|[smhdwy])/);
seconds += parseInt(this.calc[mod](val));
});
if(seconds > 0) {
const rest = seconds - (~~(Date.now() / 1000) - begin);
lt.setTimeout(() => {
fn();
}, rest * 1000);
this._timers.add(rest);
resolve(rest);
}
else
reject();
}
else
reject();
if(!this.regex.test(time))
return reject();
let seconds = 0;
time.match(/\d+(mon|[smhdwy])/g).forEach(t => {
const [,val,mod] = t.match(/(\d+)(mon|[smhdwy])/);
seconds += parseInt(this.calc[mod](val));
});
if(seconds < 1)
return reject();
const rest = seconds - (~~(Date.now() / 1000) - begin);
if(begin < ~~(Date.now() / 1000))
return reject();
lt.setTimeout(() => {
fn();
}, rest * 1000);
this._timers.add(rest);
resolve(rest);
});
}
getTimers() {
@ -53,6 +51,12 @@ export default new class timer {
{
this.add(r.delay, () => {
client.client.sendmsg("normal", r.target.channel, client.client.format(`[b]${r.target.nick}[/b]: ${r.message} [i](${r.delay})[/i]`));
sql.any("delete from nxy_timers where id = $1", [ r.id ])
.then(() => {
client.client.sendmsg("normal", r.target.channel, client.client.format(`timer ${r.id} gelöscht.`));
console.log(`deleted timer ${r.id}`);
})
.catch(err => console.log(err));
}, r.created).catch(err => {});
}
});

View File

@ -0,0 +1,64 @@
//import sql from "../../../inc/sql";
import { clients } from "../../wrapper";
export default new class timer {
constructor() {
this.regex = /(\d+)(mon|[smhdwy])/;
this.calc = {
y: 365 * 24 * 60 * 60, // years
mon: 30 * 24 * 60 * 60, // months
w: 7 * 24 * 60 * 60, // weeks
d: 24 * 60 * 60, // days
h: 60 * 60, // hours
m: 60, // minutes
s: 1 // seconds
};
this._timers = new Map();
setInterval(() => { this.loop(); }, 1000);
//setTimeout(() => { this.getTimers(); }, 1000);
}
add(time, fn, now = ~~(Date.now() / 1000)) {
return new Promise((resolve, reject) => {
try {
if(!this.regex.test(time))
return reject("ungültig lol");
let seconds = 0;
time.match(/\d+(mon|[smhdwy])/g).forEach(t => {
const [,val,mod] = t.match(/(\d+)(mon|[smhdwy])/);
seconds += val * this.calc[mod];
});
if(seconds < 1)
return reject("lel ne");
const until = now + seconds;
const rest = until - now;
if(!this._timers.has(until))
this._timers.set(until, []);
this._timers.get(until).push(fn);
resolve({
now: new Date(now * 1000),
rest: rest,
until: new Date((now + rest) * 1000)
});
} catch(err) {
reject(err);
};
});
}
loop() {
this._timers.forEach((val, key) => {
if(key === ~~(Date.now() / 1000)) {
val.forEach(k => {
k.target = JSON.parse(k.target);
clients.forEach(client => {
if(client.type.toLowerCase() === k.target.type.toLowerCase() && client.client.network.toLowerCase() === k.target.network.toLowerCase()) {
client.client.sendmsg("normal", k.target.channel, client.client.format(`[b]${k.target.nick}[/b]: ${k.message} [i](${k.delay})[/i]`));
}
});
this._timers.delete(key);
});
}
});
}
};

View File

@ -4,8 +4,8 @@ import url from "url";
const apis = {
reverse: "https://pr0.totally.rip/api/v2/item?file=",
pr0gag: {
list: "https://pr0gramm.com/api/items/get/?flags=15&id=",
item: "https://pr0gramm.com/api/items/info?flags=15&itemId="
list: "https://pr0gramm.com/api/items/get/?flags=1&id=", // 15
item: "https://pr0gramm.com/api/items/info?flags=1&itemId="
}
};
const flags = {

View File

@ -1,4 +1,5 @@
import sql from "../sql";
import fetch from "../fetch";
let _query_get = `
with ranked_quotes as (
@ -23,6 +24,18 @@ insert into nxy_quotes
`;
export default bot => {
bot._trigger.set("qrnd", new bot.trigger({
call: /^(\.|\/)qrnd$/i,
set: "all",
f: e => {
fetch("https://nxy.totally.rip/api/quotes.php?c=nick,item")
.then(res => res.json())
.then(res => {
const quote = res.data.quotes[~~(Math.random() * res.data.quotes.length)];
e.reply(`<[b]${quote.nick}[/b]> [i]${quote.item}[/i]`);
}).catch(console.error);
}
}));
bot._trigger.set("quotes", new bot.trigger({
call: /^(\.|\/)q .*/i,
set: "nxy",

View File

@ -6,9 +6,11 @@ import fetch from "../fetch";
import stringify from "stringify-object";
let _contexts = new Map();
sql.any("select prefix, sandbox from nxy_users where sandbox != 'NULL'")
.then(rows => rows.forEach(row => eval(`_contexts.set(row.prefix, ${JSON.parse(row.sandbox)});`)))
.catch(err => console.log("nichts vorhanden lol", err));
setTimeout(() => {
sql.any("select prefix, sandbox from nxy_users where sandbox != 'NULL'")
.then(rows => rows.forEach(row => eval(`_contexts.set(row.prefix, ${JSON.parse(row.sandbox)});`)))
.catch(err => console.log("nichts vorhanden lol", err));
}, 5000);
export default bot => {
bot._trigger.set("sandbox_js", new bot.trigger({

View File

@ -11,8 +11,9 @@ export default bot => {
},
active: false,
f: e => {
const t = e.args.shift();
const msg = e.args.join(" ");
const t = e.args.shift()
, msg = e.args.join(" ");
if(t === "debug" && e.user.level.level >= 100)
return e.reply( JSON.stringify([...timer._timers]) );

View File

@ -0,0 +1,38 @@
import timer from "./lib/timer1";
//import sql from "../../inc/sql";
export default bot => {
bot._trigger.set("timer", new bot.trigger({
call: /^(\.|\/)timer .*/i,
set: "nxy",
level: 100,
help: {
text: "(WIP) Sets a timer, delay can be: s, m, h, d, w, mon, y",
usage: "[b].timer[/b] [i]<delay>[/i] [i]<message>[/i]..."
},
active: true,
f: e => {
const t = e.args.shift()
, msg = e.args.join(" ");
if(t === "debug" && e.user.level.level >= 100)
return e.reply( JSON.stringify([...timer._timers.entries()]) );
timer.add(t, {
prefix: e.user.prefix,
target: JSON.stringify({
nick: e.user.nick,
type: e.type,
network: e.network,
channel: e.channelid
}),
message: msg,
delay: t
}).then(tmp => {
//e.reply(JSON.stringify([...timer._timers.entries()]));
}).catch(err => {
e.reply(err);
});
}
}));
};