.nextrocket/.fml
This commit is contained in:
parent
b5197f92f4
commit
94ad3a38d6
|
@ -17,7 +17,7 @@ const timeout = 1000;
|
|||
this.help = args.help || false;
|
||||
this.level = args.level || 0;
|
||||
this.active = args.hasOwnProperty("active") ? args.active : true;
|
||||
this.set = args.set || "all"; // uwe, nxy, f0ck, all
|
||||
this.set = args.set || "all"; // uwe, nxy, f0ck, huan, all
|
||||
this.clients = args.clients || [ "irc", "tg", "slack" ];
|
||||
this.f = args.f;
|
||||
},
|
||||
|
|
52
src/inc/trigger/useless_huan.mjs
Normal file
52
src/inc/trigger/useless_huan.mjs
Normal file
|
@ -0,0 +1,52 @@
|
|||
import fetch from "flumm-fetch-cookies";
|
||||
|
||||
const apis = {
|
||||
launch: 'https://fdo.rocketlaunch.live/json/launches/next/1',
|
||||
fml: 'https://www.fmylife.com/random'
|
||||
|
||||
};
|
||||
|
||||
const timeLeft = (s, t = []) => {
|
||||
for(let i = 0; i < 4; i++) {
|
||||
const d = [24, 60, 60, 1].slice(i).reduce((a, c) => a * c);
|
||||
const v = ~~(s / d);
|
||||
s -= v * d;
|
||||
t.push(v.toString().padStart(v ? 2 : 1, '0'));
|
||||
}
|
||||
return t.join(':');
|
||||
};
|
||||
|
||||
export default async bot => {
|
||||
return [{
|
||||
name: "launch",
|
||||
call: /^\.nextrocket/i,
|
||||
set: "huan",
|
||||
f: async e => {
|
||||
let res;
|
||||
try {
|
||||
res = (await (await fetch(apis.launch)).json()).result[0];
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
return e.reply('Error contacting LaunchLibrary API');
|
||||
}
|
||||
const now = new Date();
|
||||
const launch_time = new Date(res.t0);
|
||||
const timedelta = Math.abs(launch_time - now);
|
||||
const t_string = timedelta > now ? "+" : "-";
|
||||
return e.reply(`Next rocket: ${res.vehicle.name} | ${res.name} | T${t_string}${timeLeft(timedelta / 1000)}`);
|
||||
}
|
||||
}, {
|
||||
name: "fml",
|
||||
call: /^\.fml/i,
|
||||
set: "huan",
|
||||
f: async e => {
|
||||
let res;
|
||||
try {
|
||||
res = await (await fetch(apis.fml)).text();
|
||||
} catch(err) {
|
||||
return e.reply('Error getting FML');
|
||||
}
|
||||
return e.reply(res.match(/<a href=\".*\" class=\"block.*\">\n(.*?)\n<\/a>/im)[1]);
|
||||
}
|
||||
}];
|
||||
};
|
Loading…
Reference in New Issue
Block a user