Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

add new predefined filter 'Filters.Date' to filter on message age.#1978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

ikkemaniac
Copy link
Contributor

This allows for filtering messages based on the date they were send by specifying the maximum time difference between 'now' and when the message was send.

I've added some basis tests. Pls verify these as I'm not familiar with pytest and can't seem to get them to fail (ex. change 'seconds_ago' to 15 in test_filters_date_init doesn't throw an error in testing)

harshil21 reacted with thumbs up emoji
ikkemaniac added3 commitsJune 4, 2020 12:24
…ased on the date they were send by specifying the maximum time difference between 'now' and when the message was sent.
@ikkemaniac
Copy link
ContributorAuthor

Just found this in the GH actions logs:

=================================== FAILURES ===================================
2020-06-04T13:44:39.7343980Z ______________________ TestFilters.test_filters_date_init ______________________
2020-06-04T13:44:39.7344363Z
2020-06-04T13:44:39.7346253Z self = <tests.test_filters.TestFilters object at 0x7f9d1cc08208>
2020-06-04T13:44:39.7346551Z
2020-06-04T13:44:39.7346827Z def test_filters_date_init(self):
2020-06-04T13:44:39.7347871Z with pytest.raises(ValueError, match='at minimum'):
2020-06-04T13:44:39.7348197Z > Filters.date(seconds_ago=0)
2020-06-04T13:44:39.7348389Z
2020-06-04T13:44:39.7348672Z tests/test_filters.py:52:
2020-06-04T13:44:39.7348925Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2020-06-04T13:44:39.7349125Z
2020-06-04T13:44:39.7349393Z self = date, seconds_ago = 0
2020-06-04T13:44:39.7349772Z
2020-06-04T13:44:39.7350092Z definit(self, seconds_ago=None):
2020-06-04T13:44:39.7350379Z if not (bool(seconds_ago)):
2020-06-04T13:44:39.7350926Z > raise ValueError('seconds_ago must be used')
2020-06-04T13:44:39.7351241Z E ValueError: seconds_ago must be used

2020-06-04T13:44:39.7351442Z
2020-06-04T13:44:39.7351729Z telegram/ext/filters.py:1417: ValueError
2020-06-04T13:44:39.7351915Z
2020-06-04T13:44:39.7352159Z During handling of the above exception, another exception occurred:
2020-06-04T13:44:39.7352359Z
2020-06-04T13:44:39.7352632Z self = <tests.test_filters.TestFilters object at 0x7f9d1cc08208>
2020-06-04T13:44:39.7352880Z
2020-06-04T13:44:39.7353132Z def test_filters_date_init(self):
2020-06-04T13:44:39.7353800Z with pytest.raises(ValueError, match='at minimum'):
2020-06-04T13:44:39.7354155Z > Filters.date(seconds_ago=0)
2020-06-04T13:44:39.7354698Z E AssertionError: Pattern 'at minimum' not found in 'seconds_ago must be used'
2020-06-04T13:44:39.7354953Z
2020-06-04T13:44:39.7355178Z tests/test_filters.py:52: AssertionError
2020-06-04T13:44:39.7392319Z ##[group] Coverage report

Found this. will push the change.

@Poolitzer
Copy link
Member

Hey, just a quick question: Can you tell me a real "life" usecase for a bot, where it makes sense to only handle an update when it was send X seconds ago?

@ikkemaniac
Copy link
ContributorAuthor

ikkemaniac commentedJun 4, 2020
edited
Loading

Hey, just a quick question: Can you tell me a real "life" usecase for a bot, where it makes sense to only handle an update when it was send X seconds ago?

I'm experiencing issues with users sending commands when they don't have an internet connection, the bot/server was restarted and myself during development (send commands when test bot was down -> flooding test bot once back up). So i just want to ignore everything that's older than x seconds in my bots. I currently have this implemented by creating my own filter class but thought it might be useful for others as well.

edit: re-reading your question it looks like you're under the impression is want to do the opposite: only handle old commands. well... i don't :) i have this
dp.add_handler(MessageHandler(filters=(~myFilters.date(seconds_ago=10)), callback=warn_old_msg))
and warn users their commands are ignored.

@PoolitzerTelegram GithubBot Revised
Copy link
Member

@ikkemaniac Oh, and starting clear is not what you want to aim for? Thats what I do. If someone sends an update during a downtime and it was important, they will resend it later.

@ikkemaniac
Copy link
ContributorAuthor

@ikkemaniac Oh, and starting clear is not what you want to aim for? Thats what I do. If someone sends an update during a downtime and it was important, they will resend it later.

Uhhh... facepalm... never really thought about it. Nevertheless they won't get informed would they?

@PoolitzerTelegram GithubBot Revised
Copy link
Member

@ikkemaniac "they won't get informed"

You mean that the bot was down? No. I normally have a support channel for that stuff, or I could iterate over the recently used by user ids, if I want that. But thats not really the point now ;P

I personally don't really see the usecase for this filter, but your example is okay. If it is well implemented, its just another filter, so I would personally be fine with it.

The maintainers stance currently though is that its too much of a specific case to be worth included in our library. I will ping the other ones and see if your example changed that; if not, we might have a different solution coming in the future for these kind of special cases :)

@ikkemaniac
Copy link
ContributorAuthor

ok

@Eldinnie
Copy link
Member

Eldinnie commentedJun 5, 2020
edited
Loading

Hi@ikkemaniac ,

We've discussed this PR and the proposal you're making in the developers group, and we decided to reject your PR.
As it is, the usecase is too specific to add to the library, and it serves almost the exact same purpose as theclean parameter tostart_webhook/updater. We see a usefull addition to the library to modifyclean to accept a datetime or timedelta in addition to a bool, that will only clean messages sent before that period. If you're up to proposing that that would be great.

I'm closing this PR.

@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsAug 17, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@ikkemaniac@Poolitzer@Eldinnie

[8]ページ先頭

©2009-2025 Movatter.jp