es6 -> commonjs

This commit is contained in:
Joonas 2023-02-01 23:11:48 +02:00
parent 12809f7656
commit 41e7e4102c
21 changed files with 33 additions and 73 deletions

View file

@ -1,10 +1,10 @@
import {
const {
AlternateMessageModifier,
ChatClient,
SlowModeRateLimiter,
} from "dank-twitch-irc";
} = require("dank-twitch-irc");
export let client = new ChatClient({
let client = new ChatClient({
username: process.env.TWITCH_USERNAME,
password: process.env.TWITCH_PASSWORD,
@ -14,3 +14,5 @@ export let client = new ChatClient({
client.use(new SlowModeRateLimiter(client));
client.use(new AlternateMessageModifier(client));
module.exports = { client };

View file

@ -1,4 +1,4 @@
import fs from "fs";
const fs = require("fs");
const command = {
name: "commands",
@ -17,4 +17,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -20,4 +20,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -1,5 +1,3 @@
import fetch from "node-fetch";
const command = {
name: "fm",
desc: "get last played track from last.fm with your username",
@ -37,4 +35,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -18,4 +18,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -20,4 +20,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -20,4 +20,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -45,4 +45,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -11,4 +11,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -32,4 +32,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -26,4 +26,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -33,4 +33,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -25,4 +25,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -29,4 +29,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -32,4 +32,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -1,5 +1,3 @@
import fetch from "node-fetch";
const command = {
name: "weather",
desc: "get the weather from wttr.in",
@ -36,4 +34,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -31,4 +31,4 @@ const command = {
},
};
export default { command };
module.exports = { command };

View file

@ -1,7 +1,8 @@
import { client } from "./clients/twitch.js";
import { getCommands } from "./utils/commands.js";
const { client } = require("./clients/twitch.js");
const fs = require("fs");
const { getCommands } = require("./utils/commands.js");
const commands = await getCommands();
const commands = getCommands();
client.on("ready", async () => console.log("Successfully connected to chat"));
client.on("close", async (error) => {
if (error != null) {
@ -19,6 +20,8 @@ client.on("PRIVMSG", async (msg) => {
splitted.splice(1, 1);
}
console.log(commands);
if (splitted[0] === "%") {
try {
await commands[splitted[1]].run(client, msg, splitted);

View file

@ -9,10 +9,8 @@
"keywords": [],
"author": "",
"license": "ISC",
"type": "module",
"dependencies": {
"dank-twitch-irc": "^4.3.0",
"node-fetch": "^3.3.0",
"nodemon": "^2.0.20"
}
}

View file

@ -2,12 +2,10 @@ lockfileVersion: 5.4
specifiers:
dank-twitch-irc: ^4.3.0
node-fetch: ^3.3.0
nodemon: ^2.0.20
dependencies:
dank-twitch-irc: 4.3.0
node-fetch: 3.3.0
nodemon: 2.0.20
packages:
@ -115,11 +113,6 @@ packages:
- utf-8-validate
dev: false
/data-uri-to-buffer/4.0.1:
resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==}
engines: {node: '>= 12'}
dev: false
/debug-logger/0.4.1:
resolution: {integrity: sha512-bLX6pxuWO6KMXBRk6vpLgHqWXiuLbKp8kLL/wNEA4rgU8wsNLaw3UNz0NfOi1bcN0JwjFwSfxhldzU5Bc6P5RQ==}
dependencies:
@ -182,14 +175,6 @@ packages:
resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==}
dev: false
/fetch-blob/3.2.0:
resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==}
engines: {node: ^12.20 || >= 14.13}
dependencies:
node-domexception: 1.0.0
web-streams-polyfill: 3.2.1
dev: false
/fill-range/7.0.1:
resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==}
engines: {node: '>=8'}
@ -197,13 +182,6 @@ packages:
to-regex-range: 5.0.1
dev: false
/formdata-polyfill/4.0.10:
resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==}
engines: {node: '>=12.20.0'}
dependencies:
fetch-blob: 3.2.0
dev: false
/fsevents/2.3.2:
resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==}
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
@ -292,20 +270,6 @@ packages:
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
dev: false
/node-domexception/1.0.0:
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
engines: {node: '>=10.5.0'}
dev: false
/node-fetch/3.3.0:
resolution: {integrity: sha512-BKwRP/O0UvoMKp7GNdwPlObhYGB5DQqwhEDQlNKuoqwVYSxkSZCSbHjnFFmUEtwSKRPU4kNK8PbDYYitwaE3QA==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dependencies:
data-uri-to-buffer: 4.0.1
fetch-blob: 3.2.0
formdata-polyfill: 4.0.10
dev: false
/nodemon/2.0.20:
resolution: {integrity: sha512-Km2mWHKKY5GzRg6i1j5OxOHQtuvVsgskLfigG25yTtbyfRGn/GNvIbRyOf1PSCKJ2aT/58TiuUsuOU5UToVViw==}
engines: {node: '>=8.10.0'}
@ -477,11 +441,6 @@ packages:
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
dev: false
/web-streams-polyfill/3.2.1:
resolution: {integrity: sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==}
engines: {node: '>= 8'}
dev: false
/wrappy/1.0.2:
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
dev: false

View file

@ -1,16 +1,18 @@
import fs from "fs";
const fs = require("fs");
export async function getCommands() {
function getCommands() {
const commands = {};
const commandFiles = fs
.readdirSync("./commands")
.map((file) => file.replace(".js", ""));
for (let file of commandFiles) {
await import(`../commands/${file}.js`).then(
import(`../commands/${file}.js`).then(
(cmd) => (commands[file] = cmd.default.command)
);
}
return commands;
}
module.exports = { getCommands };