database connectivity for timers

This commit is contained in:
Flummi
2018-03-03 07:12:40 +01:00
parent 703152f170
commit 47faa9dff4
5 changed files with 76 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
import timer from "./lib/timer";
import sql from "../../inc/sql";
export default bot => {
bot._trigger.set("timer", new bot.trigger({
@@ -9,11 +10,26 @@ export default bot => {
usage: "[b].timer[/b] [i]<delay>[/i] [i]<message>[/i]..."
},
f: e => {
//e.reply(
timer.add(e.args.shift(), () => {
e.reply(e.args.join(" "));
});
//);
const t = e.args.shift();
const msg = e.args.join(" ");
timer.add(t, () => {
e.reply(msg);
}).then(seconds => {
sql.any(
"insert into nxy_timers (mask, target, message, delay, created) values ($1, $2, $3, $4, $5)",
[
e.user.prefix,
JSON.stringify({
type: e.type,
network: e.network,
channel: e.channelid
}),
msg,
t,
~~(Date.now() / 1000)
]
);
}).catch(err => { e.reply("error lol"); });
}
}));
};