From 6009091ac1e6f0329ecff92d72d31bbd9607171c Mon Sep 17 00:00:00 2001 From: Joonas Date: Sat, 11 Feb 2023 14:48:05 +0200 Subject: [PATCH] add a lot of logging --- commands/fill.js | 9 ++++---- commands/fm.js | 21 ++++++++++--------- commands/google.js | 4 +++- commands/hn.js | 14 ++++++------- commands/love.js | 16 ++++++-------- commands/mail.js | 49 +++++++++++++++++++++---------------------- commands/massping.js | 12 +++++------ commands/ping.js | 26 +++++++++++------------ commands/pyramid.js | 10 +++------ commands/quora.js | 2 +- commands/rd.js | 4 +++- commands/rl.js | 28 ++++++++++++------------- commands/short.js | 16 +++++++------- commands/sketch.js | 9 ++++---- commands/translate.js | 16 +++++++------- commands/twitter.js | 32 +++++++++++++--------------- commands/user.js | 36 +++++++++++++++---------------- commands/weather.js | 28 +++++++++++++------------ commands/yts.js | 29 ++++++++++++------------- 19 files changed, 175 insertions(+), 186 deletions(-) diff --git a/commands/fill.js b/commands/fill.js index 530cc1f..49023d0 100644 --- a/commands/fill.js +++ b/commands/fill.js @@ -5,9 +5,10 @@ const command = { mod: true, run: async (client, msg, splitted) => { if (!splitted[2]) { - await client - .say(msg.channelName, `${msg.displayName}, Supply an arg PoroSad`) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, Supply an arg PoroSad` + ); return; } @@ -18,7 +19,7 @@ const command = { str += `${splitted.slice(2).join(" ")} `; } - await client.me(msg.channelName, str).catch((err) => console.log(err)); + await client.me(msg.channelName, str); }, }; diff --git a/commands/fm.js b/commands/fm.js index eaebc5f..4cc2de5 100644 --- a/commands/fm.js +++ b/commands/fm.js @@ -21,21 +21,22 @@ const command = { .then((data) => { return data.recenttracks.track[0]; }) - .catch((err) => console.log(err)); + .catch((err) => + console.error("Error when fetching for last.fm: " + err.message) + ); if (data === undefined) { - await client - .say(msg.channelName, `${msg.displayName}, Invalid user PoroSad`) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, Invalid user PoroSad` + ); return; } - await client - .say( - msg.channelName, - `${msg.displayName}, (Now Playing) Album: ${data.album["#text"]} Track: ${data.name} Artist: ${data.artist["#text"]} | ${data.url}` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, (Now Playing) Album: ${data.album["#text"]} Track: ${data.name} Artist: ${data.artist["#text"]} | ${data.url}` + ); }, }; diff --git a/commands/google.js b/commands/google.js index 6cf13ef..1a6359a 100644 --- a/commands/google.js +++ b/commands/google.js @@ -11,7 +11,9 @@ const command = { ) .then((res) => res.json()) .then((data) => data[0]) - .catch((err) => console.log(err)); + .catch((err) => + console.error("Error when fetching results: " + err.message) + ); if (!data) { await client.say( diff --git a/commands/hn.js b/commands/hn.js index eeb7d09..9a5e721 100644 --- a/commands/hn.js +++ b/commands/hn.js @@ -9,14 +9,14 @@ const command = { ) .then((res) => res.json()) .then((data) => data.hits[Math.floor(Math.random() * data.hits.length)]) - .catch((err) => console.log(err)); + .catch((err) => + console.error("Error when fetching hacker news: " + err.message) + ); - await client - .say( - msg.channelName, - `${msg.displayName}, Hacker News: ${data.title} (Points: ${data.points}, Comments: ${data.num_comments}) Article: ${data.url} Comments: https://news.ycombinator.com/item?id=${data.objectID}` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, Hacker News: ${data.title} (Points: ${data.points}, Comments: ${data.num_comments}) Article: ${data.url} Comments: https://news.ycombinator.com/item?id=${data.objectID}` + ); }, }; diff --git a/commands/love.js b/commands/love.js index 81a6d82..53cc1f4 100644 --- a/commands/love.js +++ b/commands/love.js @@ -12,16 +12,12 @@ const command = { return; } - await client - .say( - msg.channelName, - `${msg.displayName}, ${splitted[2]} and ${ - splitted[3] - } are about ${Math.floor( - Math.random() * 100 - )}% in love with each other!` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, ${splitted[2]} and ${ + splitted[3] + } are about ${Math.floor(Math.random() * 100)}% in love with each other!` + ); }, }; diff --git a/commands/mail.js b/commands/mail.js index 946e447..7cefc75 100644 --- a/commands/mail.js +++ b/commands/mail.js @@ -11,14 +11,14 @@ const command = { ) .then((res) => res.json()) .then((data) => data.data.introduceSession) - .catch((err) => console.log(err)); + .catch((err) => + console.error("Error when creating a mailbox: " + err.message) + ); - await client - .say( - msg.channelName, - `${msg.displayName}, your temporary email has been created! Use the ID to fetch new mails! ID: ${data.id} Address: ${data.addresses[0].address}` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, your temporary email has been created! Use the ID to fetch new mails! ID: ${data.id} Address: ${data.addresses[0].address}` + ); break; } @@ -30,12 +30,15 @@ const command = { ) .then((res) => res.json()) .then((data) => data.data.session) - .catch((err) => console.log(err)); + .catch((err) => + console.error("Error when fetching mailbox: " + err.message) + ); if (data.mails.length === 0) { - await client - .say(msg.channelName, `${msg.displayName}, no mails found`) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, no mails found` + ); return; } @@ -47,24 +50,20 @@ const command = { ) .catch((err) => console.log(err)); - await client - .say( - msg.channelName, - `${msg.displayName}, Body: ${data.mails[0].text - .replaceAll("\n", " ") - .substring(0, 400)}` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, Body: ${data.mails[0].text + .replaceAll("\n", " ") + .substring(0, 400)}` + ); break; } default: { - await client - .say( - msg.channelName, - `${msg.displayName}, supply an action (create or fetch)` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, supply an action (create or fetch)` + ); break; } } diff --git a/commands/massping.js b/commands/massping.js index 4937b52..d5520b3 100644 --- a/commands/massping.js +++ b/commands/massping.js @@ -14,7 +14,9 @@ const command = { .then((data) => { return data.chatters; }) - .catch((err) => console.log(err)); + .catch((err) => + console.error("Error when fetching chatters: " + err.message) + ); let names = []; function printValues(obj) { @@ -31,17 +33,13 @@ const command = { let temp = []; for (let name of names) { if (temp.join(" ").length > 450) { - client - .say(msg.channelName, temp.join(" ")) - .catch((err) => console.log(err)); + client.say(msg.channelName, temp.join(" ")); temp = []; } temp.push(name); if (names.slice(-1)[0] === name) { - client - .say(msg.channelName, temp.join(" ")) - .catch((err) => console.log(err)); + client.say(msg.channelName, temp.join(" ")); } } }, diff --git a/commands/ping.js b/commands/ping.js index 82989da..31f54b8 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -7,20 +7,18 @@ const command = { restricted: false, mod: false, run: async (client, msg) => { - await client - .say( - msg.channelName, - `${msg.displayName}, Pong! Uptime: ${Math.floor( - process.uptime() - )}s Memory used: ${Math.floor( - os.totalmem() / 1024 / 1024 - os.freemem() / 1024 / 1024 - )}mb / ${Math.floor( - os.totalmem() / 1024 / 1024 - )}mb Joined channels count: ${ - client.joinedChannels.size - } Megis drinkers count: ${await prisma.user.count()}` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, Pong! Uptime: ${Math.floor( + process.uptime() + )}s Memory used: ${Math.floor( + os.totalmem() / 1024 / 1024 - os.freemem() / 1024 / 1024 + )}mb / ${Math.floor( + os.totalmem() / 1024 / 1024 + )}mb Joined channels count: ${ + client.joinedChannels.size + } Megis drinkers count: ${await prisma.user.count()}` + ); }, }; diff --git a/commands/pyramid.js b/commands/pyramid.js index eed4e04..46b53ce 100644 --- a/commands/pyramid.js +++ b/commands/pyramid.js @@ -10,7 +10,7 @@ const command = { splitted[3] === undefined || parseInt(splitted[2]) > 50 ) { - client.say( + await client.say( msg.channelName, `${msg.displayName}, Second arg needs to be a valid number and third arg needs to exist PoroSad` ); @@ -20,16 +20,12 @@ const command = { let arr = []; for (let i = 0; i < parseInt(splitted[2]); i++) { arr.push(splitted.slice(3).join(" ")); - client - .say(msg.channelName, arr.join(" ")) - .catch((err) => console.log(err)); + client.say(msg.channelName, arr.join(" ")); } for (let i = parseInt(splitted[2]); i > 1; i--) { arr.pop(); - client - .say(msg.channelName, arr.join(" ")) - .catch((err) => console.log(err)); + client.say(msg.channelName, arr.join(" ")); } }, }; diff --git a/commands/quora.js b/commands/quora.js index 2d11499..3f2295f 100644 --- a/commands/quora.js +++ b/commands/quora.js @@ -11,7 +11,7 @@ const command = { ) .then((res) => res.json()) .then((data) => data.data.results[0].text) - .catch((err) => console.log(err)); + .catch((err) => console.error("Error fetching quora: " + err.message)); if (!data) { await client.say(msg.channelName, `${msg.displayName}, nothing found`); diff --git a/commands/rd.js b/commands/rd.js index 3ab5192..20631ad 100644 --- a/commands/rd.js +++ b/commands/rd.js @@ -11,7 +11,9 @@ const command = { ) .then((res) => res.json()) .then((data) => data.links[Math.floor(Math.random() * data.links.length)]) - .catch((err) => console.log(err)); + .catch((err) => + console.error("Error fetching from teddit: " + err.message) + ); if (!data) { client.say( diff --git a/commands/rl.js b/commands/rl.js index 0ad574f..e642ede 100644 --- a/commands/rl.js +++ b/commands/rl.js @@ -17,27 +17,25 @@ const command = { ) .then((res) => res.json()) .then((data) => data.messages[0]) - .catch((err) => console.log(err)); + .catch((err) => + console.error("Error fetching leppunen api: " + err.message) + ); if (!data) { - await client - .say( - msg.channelName, - `${msg.displayName}, nothing found or ivr api is down` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, nothing found or ivr api is down` + ); return; } - await client - .say( - msg.channelName, - `${msg.displayName}, [${new Date(data.timestamp).toLocaleString()}] ${ - data.username - }: ${data.text}` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, [${new Date(data.timestamp).toLocaleString()}] ${ + data.username + }: ${data.text}` + ); }, }; diff --git a/commands/short.js b/commands/short.js index b18c15e..907eb2a 100644 --- a/commands/short.js +++ b/commands/short.js @@ -5,9 +5,10 @@ const command = { mod: false, run: async (client, msg, splitted) => { if (!splitted[2]) { - client - .say(msg.channelName, `${msg.displayName}, supply an URL PoroSad`) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, supply an URL PoroSad` + ); return; } @@ -24,11 +25,12 @@ const command = { body: formData, }) .then((res) => res.text()) - .catch((err) => console.log(err)); + .catch((err) => console.log("Error shortening url: " + err.message)); - await client - .say(msg.channelName, `${msg.displayName}, shortened URL: ${data}`) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, shortened URL: ${data}` + ); }, }; diff --git a/commands/sketch.js b/commands/sketch.js index 7776751..74cad0c 100644 --- a/commands/sketch.js +++ b/commands/sketch.js @@ -28,11 +28,12 @@ const command = { } ) .then((res) => res.text()) - .catch((err) => console.log(err)); + .catch((err) => console.error("Error sketchifying url: " + err.message)); - await client - .say(msg.channelName, `${msg.displayName}, sketchified URL: ${data}`) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, sketchified URL: ${data}` + ); }, }; diff --git a/commands/translate.js b/commands/translate.js index f6c94c5..0fcf3f6 100644 --- a/commands/translate.js +++ b/commands/translate.js @@ -18,7 +18,7 @@ const command = { )}&text=${encodeURIComponent(splitted.slice(3).join(" "))}` ) .then((res) => res.json()) - .catch((err) => console.log(err)); + .catch((err) => console.error("Error with translating: " + err.message)); if (!data) { await client.say( @@ -29,14 +29,12 @@ const command = { return; } - await client - .say( - msg.channelName, - `${msg.displayName}, Translation of ${splitted - .slice(3) - .join(" ")} to lang ${splitted[2]}: '${data["translated-text"]}'` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, Translation of ${splitted + .slice(3) + .join(" ")} to lang ${splitted[2]}: '${data["translated-text"]}'` + ); }, }; diff --git a/commands/twitter.js b/commands/twitter.js index b0e40c1..b061126 100644 --- a/commands/twitter.js +++ b/commands/twitter.js @@ -11,29 +11,25 @@ const command = { ) .then((res) => res.json()) .then((data) => data.items[0]) - .catch((err) => console.log(err)); + .catch((err) => console.error("Error with rss2json: " + err.message)); if (!data) { - await client - .say( - msg.channelName, - `${msg.displayName}, invalid name or api's are down` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, invalid name or api's are down` + ); return; } - await client - .say( - msg.channelName, - `${msg.displayName}, Latest tweet for ${ - splitted[2] ? splitted[2] : "forsen" - }: "${data.title.replaceAll("\n", "")}" Media: ${data.description - .split('"') - .filter((item) => item.startsWith("https://")) - .join(" ")} Link: ${data.link}` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, Latest tweet for ${ + splitted[2] ? splitted[2] : "forsen" + }: "${data.title.replaceAll("\n", "")}" Media: ${data.description + .split('"') + .filter((item) => item.startsWith("https://")) + .join(" ")} Link: ${data.link}` + ); }, }; diff --git a/commands/user.js b/commands/user.js index f8a8fee..eded01c 100644 --- a/commands/user.js +++ b/commands/user.js @@ -13,26 +13,24 @@ const command = { ) .then((res) => res.json()) .then((data) => data[0]) - .catch((err) => console.log(err)); + .catch((err) => console.error("Error with leppunen api: " + err.message)); - await client - .say( - msg.channelName, - `${msg.displayName}, information about user ${ - data.displayName - }: Created at: ${new Date(data.createdAt).toLocaleString()}, ${ - data.banned ? `Banned: yes; Reason: ${data.banReason}` : "" - } ${ - data.lastBroadcast.startedAt - ? `Last stream: ${data.lastBroadcast.title}; ${Math.floor( - (new Date().getTime() - - new Date(data.lastBroadcast.startedAt).getTime()) / - (1000 * 3600 * 24) - )} days ago` - : "" - }` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, information about user ${ + data.displayName + }: Created at: ${new Date(data.createdAt).toLocaleString()}, ${ + data.banned ? `Banned: yes; Reason: ${data.banReason}` : "" + } ${ + data.lastBroadcast.startedAt + ? `Last stream: ${data.lastBroadcast.title}; ${Math.floor( + (new Date().getTime() - + new Date(data.lastBroadcast.startedAt).getTime()) / + (1000 * 3600 * 24) + )} days ago` + : "" + }` + ); }, }; diff --git a/commands/weather.js b/commands/weather.js index b314539..b8e5d46 100644 --- a/commands/weather.js +++ b/commands/weather.js @@ -5,9 +5,10 @@ const command = { mod: false, run: async (client, msg, splitted) => { if (splitted[2] === undefined) { - client - .say(msg.channelName, `${msg.displayName}, supply a location PoroSad`) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, supply a location PoroSad` + ); return; } @@ -19,22 +20,23 @@ const command = { .then((data) => { return data.current_condition[0]; }) - .catch((err) => console.log(err)); + .catch((err) => + console.log("Error fetching from wttr.in: " + err.message) + ); if (data === undefined) { - await client - .say(msg.channelName, `${msg.displayName}, Invalid location PoroSad`) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, Invalid location PoroSad` + ); return; } - await client - .say( - msg.channelName, - `${msg.displayName} Weather for ${splitted[2]} Status: ${data.weatherDesc[0]?.value} Temp: ${data.temp_C}°C Feels like: ${data.FeelsLikeC}°C` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName} Weather for ${splitted[2]} Status: ${data.weatherDesc[0]?.value} Temp: ${data.temp_C}°C Feels like: ${data.FeelsLikeC}°C` + ); }, }; diff --git a/commands/yts.js b/commands/yts.js index 84bd9e2..ead092b 100644 --- a/commands/yts.js +++ b/commands/yts.js @@ -5,9 +5,10 @@ const command = { mod: false, run: async (client, msg, splitted) => { if (splitted[2] === undefined) { - await client - .say(msg.channelName, `${msg.displayName}, supply a search PoroSad`) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, supply a search PoroSad` + ); return; } @@ -18,18 +19,18 @@ const command = { ) .then((res) => res.json()) .then((data) => data[0]) - .catch((err) => console.log(err)); + .catch((err) => + console.log("Error fetching from invidious: " + err.message) + ); - await client - .say( - msg.channelName, - `${msg.displayName}, YouTube video with search term: ${splitted - .slice(2) - .join(" ")}; ${data.title} by ${ - data.author - }, Link: youtu.be/watch?v=${data.videoId}` - ) - .catch((err) => console.log(err)); + await client.say( + msg.channelName, + `${msg.displayName}, YouTube video with search term: ${splitted + .slice(2) + .join(" ")}; ${data.title} by ${data.author}, Link: youtu.be/watch?v=${ + data.videoId + }` + ); }, };