check if command in command object and add more logging

This commit is contained in:
Joonas 2023-02-11 14:10:13 +02:00
parent 3756ebc128
commit 8f5939983b
1 changed files with 8 additions and 9 deletions

View File

@ -16,13 +16,12 @@ let client = new ChatClient({
client.use(new SlowModeRateLimiter(client));
client.use(new AlternateMessageModifier(client));
client.commands = getCommands();
console.log("Commands loaded");
client.on("ready", async () => {
console.log("connected to chat");
client.joinAll([process.env.TWITCH_USERNAME, "rollinjuusto", "catsh"]);
await client
.say(process.env.TWITCH_USERNAME, "MrDestructoid")
.catch((err) => console.log(err));
console.log("Joined channels");
});
client.on("close", async (error) => {
@ -43,6 +42,11 @@ client.on("PRIVMSG", async (msg) => {
if (splitted[0] === process.env.BOT_PREFIX) {
try {
if (!client.commands.hasOwnProperty(splitted[1])) {
await client.say(msg.channelName, `${msg.displayName}, not a command`);
return;
}
if (client.commands[splitted[1]].restricted) {
if (!msg.badges.hasBroadcaster) {
if (!msg.isMod) {
@ -74,12 +78,7 @@ client.on("PRIVMSG", async (msg) => {
await client.commands[splitted[1]].run(client, msg, splitted);
} catch (err) {
await client
.say(
msg.channelName,
`${msg.displayName}, not a command or something went wrong`
)
.catch((err) => console.log(err));
console.error("Something very unexpected happened: " + err.message);
}
}
});