cuffeo ausgelagert..
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import sql from "../sql";
|
||||
import { getLevel, loadAdmins } from "../admin";
|
||||
import { getLevel } from "../admin";
|
||||
|
||||
export default bot => {
|
||||
bot._trigger.set("join", new bot.trigger({
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { admins, getLevel } from "../admin";
|
||||
import { getLevel } from "../admin";
|
||||
import fetch from "flumm-fetch-cookies";
|
||||
import { wrapper, clients } from "../wrapper";
|
||||
|
||||
import vm from "vm";
|
||||
|
||||
@ -10,10 +9,7 @@ let context = vm.createContext({
|
||||
bot: null,
|
||||
admins: null,
|
||||
fetch: fetch,
|
||||
console: console,
|
||||
wrapper: {
|
||||
wrapper, clients
|
||||
}
|
||||
console: console
|
||||
});
|
||||
export default bot => {
|
||||
bot._trigger.set("sandbox_debug", new bot.trigger({
|
||||
@ -23,7 +19,6 @@ export default bot => {
|
||||
f: e => {
|
||||
const args = e.message.trim().substring(7);
|
||||
try {
|
||||
context.admins = admins;
|
||||
context.e = e;
|
||||
context.bot = bot;
|
||||
context.level = getLevel;
|
||||
|
@ -16,7 +16,6 @@ import rape from "./rape";
|
||||
import sandbox from "./sandbox";
|
||||
import soundcloud from "./soundcloud";
|
||||
import sysinfo from "./sysinfo";
|
||||
import timer from "./timer1";
|
||||
import urban from "./urban";
|
||||
import nxy from "./useless_nxy";
|
||||
import uwe from "./useless_uwe";
|
||||
@ -26,5 +25,5 @@ export default [
|
||||
cfg, chatbot, coins, cookie, core, debug,
|
||||
drugs, help, irpg, kernel, lastfm, mcmaniac,
|
||||
pr0gag, quotes, rape, sandbox, soundcloud,
|
||||
sysinfo, timer, urban, nxy, uwe, wttr
|
||||
sysinfo, urban, nxy, uwe, wttr
|
||||
];
|
||||
|
@ -1,66 +0,0 @@
|
||||
import lt from "long-timeout";
|
||||
import sql from "../../../inc/sql";
|
||||
import { clients } from "../../wrapper";
|
||||
|
||||
export default new class timer {
|
||||
constructor() {
|
||||
this.regex = /(\d+)(mon|[smhdwy])/;
|
||||
this.calc = {
|
||||
y: val => val * 365 * 24 * 60 * 60, // years
|
||||
mon: val => val * 30 * 24 * 60 * 60, // months
|
||||
w: val => val * 7 * 24 * 60 * 60, // weeks
|
||||
d: val => val * 24 * 60 * 60, // days
|
||||
h: val => val * 60 * 60, // hours
|
||||
m: val => val * 60, // minutes
|
||||
s: val => val // seconds
|
||||
};
|
||||
this._timers = new Set();
|
||||
setTimeout(() => { this.getTimers(); }, 1000);
|
||||
}
|
||||
add(time, fn, begin = ~~(Date.now()/1000)) {
|
||||
return new Promise((resolve, 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() {
|
||||
sql.any("select * from nxy_timers")
|
||||
.then(rows => {
|
||||
if(rows.length === 0)
|
||||
return;
|
||||
rows.forEach(r => {
|
||||
r.target = JSON.parse(r.target);
|
||||
clients.forEach(client => {
|
||||
if(client.type.toLowerCase() === r.target.type.toLowerCase()
|
||||
&& client.client.network.toLowerCase() === r.target.network.toLowerCase())
|
||||
{
|
||||
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 => {});
|
||||
}
|
||||
});
|
||||
});
|
||||
}).catch(err => console.log(err));
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
//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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
@ -1,41 +0,0 @@
|
||||
import timer from "./lib/timer";
|
||||
import sql from "../../inc/sql";
|
||||
|
||||
export default bot => {
|
||||
bot._trigger.set("timer", new bot.trigger({
|
||||
call: /^(\.|\/)timer .*/i,
|
||||
set: "nxy",
|
||||
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: false,
|
||||
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]) );
|
||||
|
||||
timer.add(t, () => {
|
||||
e.reply(`[b]${e.user.nick}[/b]: ${msg} [i](${t})[/i]`);
|
||||
}).then(seconds => {
|
||||
sql.any(
|
||||
"insert into nxy_timers (mask, target, message, delay, created) values ($1, $2, $3, $4, $5)",
|
||||
[
|
||||
e.user.prefix,
|
||||
JSON.stringify({
|
||||
nick: e.user.nick,
|
||||
type: e.type,
|
||||
network: e.network,
|
||||
channel: e.channelid
|
||||
}),
|
||||
msg,
|
||||
t,
|
||||
~~(Date.now() / 1000)
|
||||
]
|
||||
);
|
||||
}).catch(err => { e.reply("error lol"); });
|
||||
}
|
||||
}));
|
||||
};
|
@ -1,38 +0,0 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
}));
|
||||
};
|
Reference in New Issue
Block a user