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