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.abilitybots.api.bot.AbilityBot;
|
||||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators;
|
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators;
|
||||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.DeleteMessage;
|
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.Update;
|
||||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||||
import org.telegram.telegrambots.meta.api.objects.message.Message;
|
import org.telegram.telegrambots.meta.api.objects.message.Message;
|
||||||
@ -99,20 +100,26 @@ public class LanguageBlockBot extends AbilityBot {
|
|||||||
private CompletableFuture<Boolean> isMessageDeletable(Message msg) {
|
private CompletableFuture<Boolean> isMessageDeletable(Message msg) {
|
||||||
var chatId = msg.getChatId();
|
var chatId = msg.getChatId();
|
||||||
CompletableFuture<Boolean> canDeleteBecauseItsNotAdmin;
|
CompletableFuture<Boolean> canDeleteBecauseItsNotAdmin;
|
||||||
if (msg.getSenderChat() != null) {
|
canDeleteBecauseItsNotAdmin = getChatAdmins(chatId)
|
||||||
canDeleteBecauseItsNotAdmin = getChatAdmins(chatId)
|
.thenApply(admins -> !admins.contains(getSenderChat(msg)));
|
||||||
.thenApply(admins -> !admins.contains(msg.getSenderChat().getId()));
|
|
||||||
} else {
|
|
||||||
canDeleteBecauseItsNotAdmin = CompletableFuture.completedFuture(true);
|
|
||||||
}
|
|
||||||
boolean canDeleteBecauseItsNormalMessage = !(msg.getIsAutomaticForward() != null && msg.getIsAutomaticForward())
|
boolean canDeleteBecauseItsNormalMessage = !(msg.getIsAutomaticForward() != null && msg.getIsAutomaticForward())
|
||||||
&& (msg.getSenderChat() != null && msg.getSenderChat().isUserChat()) && !msg.hasViaBot();
|
&& (getSenderChat(msg) > 0) && !msg.hasViaBot();
|
||||||
|
|
||||||
return CompletableFuture
|
return CompletableFuture
|
||||||
.completedFuture(canDeleteBecauseItsNormalMessage)
|
.completedFuture(canDeleteBecauseItsNormalMessage)
|
||||||
.thenCombine(canDeleteBecauseItsNotAdmin, (a, b) -> a && b);
|
.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) {
|
private CompletableFuture<Set<Long>> getChatAdmins(Long chatId) {
|
||||||
var client = this.getTelegramClient();
|
var client = this.getTelegramClient();
|
||||||
if (chatId >= 0) {
|
if (chatId >= 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user