Skip to content

Commit

Permalink
Fix user using admin commands
Browse files Browse the repository at this point in the history
added admin check to command execution
  • Loading branch information
Kozoobmennik committed Dec 16, 2021
1 parent 4b8b124 commit 851970a
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,30 @@ public void onUpdateReceived(Update update) {
if (command.contains("@")) return; // skip other's bot commands

Optional.ofNullable(commandKeeper.getExecutor(command)).ifPresent(executor -> {
if (userHasPermission(executor, message)) {
if (executor.pmOnly() && !message.isUserMessage()) {
telegram.sendMessage(chatId, "Команду можно использовать только в лс");
return;
}
executor.execute(message);
if (!userHasPermission(executor, message)) {
telegram.sendMessage(chatId, "Простите, но вы не можете использовать эту команду.");
return;
}
if (message.getText().length() > 300) {
telegram.sendMessage(chatId, "Менее 300 символов, будьте добры.");
return;
}
if (executor.pmOnly() && !message.isUserMessage()) {
telegram.sendMessage(chatId, "Команду можно использовать только в лс");
return;
}
executor.execute(message);
});

}

private boolean userHasPermission(CommandExecutor executor, Message message) {
long userId = message.getFrom().getId();
long chatId = message.getChatId();
return config.isAdmin(userId) ||
if (executor.adminsOnly()) {
return config.isAdmin(userId);
}
return config.isAdmin(userId) ||
config.isAllowForeignChats() ||
chatId == config.getChatId();
}
Expand Down

0 comments on commit 851970a

Please sign in to comment.