Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser): warn on disabled command use #3311

Merged
merged 2 commits into from Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/bot/parser.ts
@@ -1,7 +1,7 @@
import _ from 'lodash';
import * as constants from './constants';
import { sendMessage } from './commons';
import { debug, error } from './helpers/log';
import { debug, error, warning } from './helpers/log';
import { incrementCountOfCommandUsage } from './helpers/commands/count';
import { getRepository } from 'typeorm';
import { PermissionCommands } from './database/entity/permissions';
Expand Down Expand Up @@ -249,6 +249,7 @@ class Parser {
return;
}; // command not found, do nothing
if (command.permission === null) {
warning(`Command ${command.command} is disabled!`);
return;
}; // command is disabled

Expand Down
7 changes: 5 additions & 2 deletions src/bot/systems/customcommands.ts
Expand Up @@ -11,7 +11,7 @@ import Expects from '../expects';
import { getOwner, isBot, isBroadcaster, isModerator, isOwner, isSubscriber, isVIP, message, prepare, sendMessage } from '../commons';
import { getAllCountOfCommandUsage, getCountOfCommandUsage, incrementCountOfCommandUsage, resetCountOfCommandUsage } from '../helpers/commands/count';

import { chatOut } from '../helpers/log';
import { chatOut, warning } from '../helpers/log';
import { adminEndpoint } from '../helpers/socket';
import { getRepository } from 'typeorm';
import { Commands, CommandsInterface, CommandsResponsesInterface } from '../database/entity/commands';
Expand Down Expand Up @@ -199,7 +199,6 @@ class CustomCommands extends System {
relations: ['responses'],
where: {
command: cmdArray.join(' '),
enabled: true,
},
});
for (const command of db_commands) {
Expand Down Expand Up @@ -228,6 +227,10 @@ class CustomCommands extends System {
// go through all commands
let atLeastOnePermissionOk = false;
for (const command of commands) {
if (!command.command.enabled) {
warning(`Custom command ${command.command.command} (${command.command.id}) is disabled!`);
continue;
}
const _responses: CommandsResponsesInterface[] = [];
// remove found command from message to get param
const param = opts.message.replace(new RegExp('^(' + command.cmdArray.join(' ') + ')', 'i'), '').trim();
Expand Down