Remove group update check for GROUP_ADMIN
GetChatAdministrators only returns admins when there IS a group, there's no need to explicitly check for groups here.
This commit is contained in:
parent
28a9cf1fdb
commit
b9da279fdf
@ -650,7 +650,7 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
|
||||
private boolean isGroupAdmin(Update update, int id) {
|
||||
GetChatAdministrators admins = new GetChatAdministrators().setChatId(getChatId(update));
|
||||
|
||||
return isGroupUpdate(update) && silent.execute(admins)
|
||||
return silent.execute(admins)
|
||||
.orElse(new ArrayList<>()).stream()
|
||||
.anyMatch(member -> member.getUser().getId() == id);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import static java.util.Objects.nonNull;
|
||||
/**
|
||||
* Flags are an conditions that are applied on an {@link Update}.
|
||||
* <p>
|
||||
* They can be used on {@link AbilityBuilder#flag(Flag...)} and on the post conditions in {@link AbilityBuilder#reply(Consumer, Predicate[])}.
|
||||
* They can be used on {@link AbilityBuilder#flag(Predicate[])} and on the post conditions in {@link AbilityBuilder#reply(Consumer, Predicate[])}.
|
||||
*
|
||||
* @author Abbas Abou Daya
|
||||
*/
|
||||
|
@ -86,6 +86,28 @@ public final class AbilityUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A "best-effort" boolean stating whether the update is a super-group message or not.
|
||||
*
|
||||
* @param update a Telegram {@link Update}
|
||||
* @return whether the update is linked to a group
|
||||
*/
|
||||
public static boolean isSuperGroupUpdate(Update update) {
|
||||
if (MESSAGE.test(update)) {
|
||||
return update.getMessage().isSuperGroupMessage();
|
||||
} else if (CALLBACK_QUERY.test(update)) {
|
||||
return update.getCallbackQuery().getMessage().isSuperGroupMessage();
|
||||
} else if (CHANNEL_POST.test(update)) {
|
||||
return update.getChannelPost().isSuperGroupMessage();
|
||||
} else if (EDITED_CHANNEL_POST.test(update)) {
|
||||
return update.getEditedChannelPost().isSuperGroupMessage();
|
||||
} else if (EDITED_MESSAGE.test(update)) {
|
||||
return update.getEditedMessage().isSuperGroupMessage();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the direct chat ID of the specified update.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user