50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
const { client } = require("./clients/twitch.js");
|
|
const { getCommands } = require("./utils/commands.js");
|
|
const commands = getCommands();
|
|
|
|
client.on("ready", async () => console.log("Successfully connected to chat"));
|
|
client.on("close", async (error) => {
|
|
if (error != null) {
|
|
console.error("Client closed due to error", error);
|
|
}
|
|
});
|
|
|
|
client.on("PRIVMSG", async (msg) => {
|
|
if (msg.senderUsername === process.env.TWITCH_USERNAME) return;
|
|
if (msg.messageText.length < 3) return;
|
|
const splitted = msg.messageText.split(" ");
|
|
|
|
// chatterinos duplicate message bypass fix lol
|
|
if (splitted[1] === "") {
|
|
splitted.splice(1, 1);
|
|
}
|
|
|
|
if (splitted[0] === process.env.BOT_PREFIX) {
|
|
try {
|
|
if (commands[splitted[1]].restricted) {
|
|
if (!msg.badges.hasBroadcaster) {
|
|
if (!msg.isMod) {
|
|
client.say(
|
|
msg.channelName,
|
|
`${msg.displayName}, need to be a mod or brodcaster to use`
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
await commands[splitted[1]].run(client, msg, splitted);
|
|
} catch (err) {
|
|
client
|
|
.say(
|
|
msg.channelName,
|
|
`${msg.displayName}, not a command or something went wrong`
|
|
)
|
|
.catch((err) => console.log(err));
|
|
}
|
|
}
|
|
});
|
|
|
|
client.connect();
|
|
client.joinAll([process.env.TWITCH_USERNAME, "rollinjuusto"]);
|