Fix sender id
This commit is contained in:
parent
52ee9f8e53
commit
acd543ae49
@ -13,6 +13,7 @@ import java.util.stream.Collectors;
|
||||
import org.telegram.telegrambots.abilitybots.api.bot.AbilityBot;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators;
|
||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.DeleteMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.Chat;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.message.Message;
|
||||
@ -99,20 +100,26 @@ public class LanguageBlockBot extends AbilityBot {
|
||||
private CompletableFuture<Boolean> isMessageDeletable(Message msg) {
|
||||
var chatId = msg.getChatId();
|
||||
CompletableFuture<Boolean> canDeleteBecauseItsNotAdmin;
|
||||
if (msg.getSenderChat() != null) {
|
||||
canDeleteBecauseItsNotAdmin = getChatAdmins(chatId)
|
||||
.thenApply(admins -> !admins.contains(msg.getSenderChat().getId()));
|
||||
} else {
|
||||
canDeleteBecauseItsNotAdmin = CompletableFuture.completedFuture(true);
|
||||
}
|
||||
.thenApply(admins -> !admins.contains(getSenderChat(msg)));
|
||||
boolean canDeleteBecauseItsNormalMessage = !(msg.getIsAutomaticForward() != null && msg.getIsAutomaticForward())
|
||||
&& (msg.getSenderChat() != null && msg.getSenderChat().isUserChat()) && !msg.hasViaBot();
|
||||
&& (getSenderChat(msg) > 0) && !msg.hasViaBot();
|
||||
|
||||
return CompletableFuture
|
||||
.completedFuture(canDeleteBecauseItsNormalMessage)
|
||||
.thenCombine(canDeleteBecauseItsNotAdmin, (a, b) -> a && b);
|
||||
}
|
||||
|
||||
private Long getSenderChat(Message msg) {
|
||||
if (msg.getSenderChat() != null) {
|
||||
return msg.getSenderChat().getId();
|
||||
} else if (msg.getFrom() != null) {
|
||||
return msg.getFrom().getId();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
private CompletableFuture<Set<Long>> getChatAdmins(Long chatId) {
|
||||
var client = this.getTelegramClient();
|
||||
if (chatId >= 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user