Lonami / grammers

(tele)gramme.rs - use Telegram's API from Rust
https://t.me/gramme_rs
Apache License 2.0
554 stars 113 forks source link

The is_bot flag is incorrectly interpreted for messages from a bot without a keyboard #210

Closed taimast closed 6 months ago

taimast commented 11 months ago

For messages without an attached keyboard that the bot sends, the Chat::User(user) type attached to the message has the flag user.is_bot() == False, although if the keyboard is attached, then user.is_bot() == True

Lonami commented 11 months ago

Are you sure the message wasn't sent @via inline? The library doesn't modify the bot flag returned by Telegram in any way: https://github.com/Lonami/grammers/blob/04d95775e01f52e8326e1d1e203ee1b5137ee518/lib/grammers-client/src/types/chat/user.rs#L247-L249

taimast commented 11 months ago

Are you sure the message wasn't sent @via inline? The library doesn't modify the bot flag returned by Telegram in any way:

https://github.com/Lonami/grammers/blob/04d95775e01f52e8326e1d1e203ee1b5137ee518/lib/grammers-client/src/types/chat/user.rs#L247-L249

image Of this kind

Lonami commented 11 months ago

Can you check what value the min field has?

taimast commented 11 months ago

Can you check what value the min field has?

impl ChatTypeFilter {
    pub(crate) async fn handle(&self, context: &ComponentContext<'_>) -> bool {
        if self.chat_types.len() == 0 {
            return false;
        }
        ChatTypeForFilter::is_contains(&self.chat_types, &context.message.chat())
    }
}

impl ChatTypeForFilter {
    pub fn is_contains(array: &Vec<Self>, chat: &Chat) -> bool {
        if array.len() == 0 {
            return false;
        }

        return match chat {
            Chat::User(user) => {
                println!("{}", user.is_bot());
                println!("{}", user.min());
                if user.is_bot() {
                    if array.contains(&ChatTypeForFilter::Bot) {
                        return true;
                    }
                } else {
                    if array.contains(&ChatTypeForFilter::Private) {
                        return true;
                    }
                }
                false
            }
            Chat::Group(_) => {
                if array.contains(&ChatTypeForFilter::Group) {
                    return true;
                }
                false
            }
            Chat::Channel(_) => {
                if array.contains(&ChatTypeForFilter::SuperGroup) {
                    return true;
                }
                false
            }
        };
    }
}
false
false