fix pr0gag trigger
improve error handling
This commit is contained in:
parent
21c1f42aeb
commit
1cd1d486de
|
@ -34,7 +34,7 @@ export default async bot => {
|
||||||
}
|
}
|
||||||
catch(error) {
|
catch(error) {
|
||||||
e.reply("An error occured.");
|
e.reply("An error occured.");
|
||||||
logger.error(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${typeof error === "string" ? error : JSON.stringify(error)}`);
|
logger.error(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${error.toString ? error : JSON.stringify(error)}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -48,13 +48,13 @@ export default async bot => {
|
||||||
const response = await (await fetch(apis.reverse + path)).json();
|
const response = await (await fetch(apis.reverse + path)).json();
|
||||||
if(response.error || !response.items.length)
|
if(response.error || !response.items.length)
|
||||||
throw "reverse lookup error";
|
throw "reverse lookup error";
|
||||||
list = response.item[0];
|
list = response.items[0];
|
||||||
id = list.id;
|
id = list.id;
|
||||||
link = "https://pr0gramm.com/" + (list.promoted ? "top" : "new") + "/" + id;
|
link = "https://pr0gramm.com/" + (list.promoted ? "top" : "new") + "/" + id;
|
||||||
}
|
}
|
||||||
else if(matches = e.message.match(regex.normal)) {
|
else if(matches = e.message.match(regex.normal)) {
|
||||||
id = matches[1];
|
id = matches[1];
|
||||||
link = matches[0];
|
link = "https://" + matches[0];
|
||||||
list = (await (await fetch(apis.list + id)).json())
|
list = (await (await fetch(apis.list + id)).json())
|
||||||
.items
|
.items
|
||||||
.filter(item => item.id == id)[0];
|
.filter(item => item.id == id)[0];
|
||||||
|
@ -87,7 +87,7 @@ export default async bot => {
|
||||||
const voteRatioColor = voteRatioColors[~~Math.min(voteRatio * voteRatioColors.length, voteRatioColors.length - 1)];
|
const voteRatioColor = voteRatioColors[~~Math.min(voteRatio * voteRatioColors.length, voteRatioColors.length - 1)];
|
||||||
|
|
||||||
e.reply([
|
e.reply([
|
||||||
"https://pr0gramm.com/" + (list.promoted ? "top" : "new") + "/" + id,
|
link,
|
||||||
`${list.up - list.down} (${color.green(list.up)} / ${color.red(list.down)} = ${color[voteRatioColor]((voteRatio * 100).toFixed(1))}${color.magenta("%")})`,
|
`${list.up - list.down} (${color.green(list.up)} / ${color.red(list.down)} = ${color[voteRatioColor]((voteRatio * 100).toFixed(1))}${color.magenta("%")})`,
|
||||||
"user: " + list.user,
|
"user: " + list.user,
|
||||||
"comments: " + info.comments.length,
|
"comments: " + info.comments.length,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user