diff --git a/.eslintrc.js b/.eslintrc.js index 1b81e6f..d72bba3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -28,5 +28,6 @@ module.exports = { globals: { hf: true, BigInt: true, // lol eslint + fetch: true, }, }; diff --git a/.husky/.gitignore b/.husky/.gitignore new file mode 100644 index 0000000..31354ec --- /dev/null +++ b/.husky/.gitignore @@ -0,0 +1 @@ +_ diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..bc29769 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +node_modules/.bin/eslint . && node_modules/.bin/prettier --check **/*.js diff --git a/package.json b/package.json index 9d3ccb7..8b92453 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "Discord bot", "main": "src/index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepare": "husky install" }, "repository": { "type": "git", @@ -32,6 +33,7 @@ }, "devDependencies": { "eslint": "^7.26.0", + "husky": "^8.0.2", "prettier": "^2.3.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3c68964..e4f6a4d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,7 @@ specifiers: dumpy: github:Cynosphere/dumpy.js eslint: ^7.26.0 google-images: ^2.1.0 + husky: ^8.0.2 jimp: ^0.16.1 murmurhash: ^2.0.0 node-ffprobe: ^3.0.0 @@ -32,6 +33,7 @@ dependencies: devDependencies: eslint: 7.26.0 + husky: 8.0.2 prettier: 2.3.0 packages: @@ -1384,6 +1386,12 @@ packages: - supports-color dev: false + /husky/8.0.2: + resolution: {integrity: sha512-Tkv80jtvbnkK3mYWxPZePGFpQ/tT3HNSs/sasF9P2YfkMezDl3ON37YN6jUUI4eTg5LcyVynlb6r4eyvOmspvg==} + engines: {node: '>=14'} + hasBin: true + dev: true + /iconv-lite/0.4.24: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} @@ -1743,11 +1751,6 @@ packages: resolution: {integrity: sha512-CvkDw2OEnme7ybCykJpVcKH+uAOLV2qLqiyla128dN9TkEWfrYmxG6C2boDe5KcNQqZF3orkqzGgOMvZ/JNekA==} dev: false - /node-fetch/2.6.1: - resolution: {integrity: sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==} - engines: {node: 4.x || >=6.0.0} - dev: false - /node-fetch/2.6.7: resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==} engines: {node: 4.x || >=6.0.0} @@ -2723,5 +2726,7 @@ packages: color: 3.2.1 gifwrap: 0.9.2 jimp: 0.16.1 - node-fetch: 2.6.1 + node-fetch: 2.6.7 + transitivePeerDependencies: + - encoding dev: false diff --git a/src/index.js b/src/index.js index fe198b3..7958d20 100644 --- a/src/index.js +++ b/src/index.js @@ -59,7 +59,12 @@ bot.on("messageCreate", async (msg) => { }); bot.on("messageUpdate", (msg, oldMsg) => { const oneDay = Date.now() - 86400000; - if (msg.timestamp > oneDay && !msg.hasRan && oldMsg && oldMsg.content !== msg.content) { + if ( + msg.timestamp > oneDay && + !msg.hasRan && + oldMsg && + oldMsg.content !== msg.content + ) { CommandDispatcher(msg); } }); diff --git a/src/modules/anonradio.js b/src/modules/anonradio.js index 6a03530..e163e7b 100644 --- a/src/modules/anonradio.js +++ b/src/modules/anonradio.js @@ -1,5 +1,6 @@ +const {formatTime} = require("../lib/utils.js"); + const GUILD_ID = "300436792916836352"; -const CHANNEL_ID = "353018352580689930"; const THREAD_ID = "1054106209273253888"; const MESSAGE_ID = "1054109813132509245"; @@ -14,7 +15,9 @@ async function updateNowPlaying() { playing = await fetch("http://anonradio.net/playing").then((res) => res.text() ); - } catch (err) {} + } catch (err) { + // + } } let schedule; try { @@ -26,7 +29,9 @@ async function updateNowPlaying() { schedule = await fetch("http://anonradio.net/schedule/").then((res) => res.text() ); - } catch (err) {} + } catch (err) { + // + } } if (!playing || !schedule) return; @@ -35,9 +40,9 @@ async function updateNowPlaying() { lines = lines.slice(4, lines.length - 2); const line = lines[0]; - const [_, time, id, name] = line.match(/^(.{3,4} .{4})\s+(.+?) {2}(.+?)$/); + const [_, _time, id, name] = line.match(/^(.{3,4} .{4})\s+(.+?) {2}(.+?)$/); - let liveNow = {name: "ident", id: "aNONradio"}; + const liveNow = {name: "ident", id: "aNONradio"}; if (name.includes("<- Live NOW")) { liveNow.id = id; @@ -88,7 +93,7 @@ async function updateNowPlaying() { } } - const content = (`${title}\n${subtitle}\n${openmicTime}`).trim(); + const content = `${title}\n${subtitle}\n${openmicTime}`.trim(); const thread = hf.bot.guilds.get(GUILD_ID).threads.get(THREAD_ID); const msg = await thread.getMessage(MESSAGE_ID); if (msg.content !== content) { diff --git a/src/modules/misc.js b/src/modules/misc.js index b9344fd..dd0cf16 100644 --- a/src/modules/misc.js +++ b/src/modules/misc.js @@ -285,7 +285,9 @@ anonradio.callback = async function () { playing = await fetch("http://anonradio.net/playing").then((res) => res.text() ); - } catch (err) {} + } catch (err) { + // + } } let schedule; try { @@ -297,7 +299,9 @@ anonradio.callback = async function () { schedule = await fetch("http://anonradio.net/schedule/").then((res) => res.text() ); - } catch (err) {} + } catch (err) { + // + } } if (!playing || !schedule) return "Failed to fetch schedule.";