-
Notifications
You must be signed in to change notification settings - Fork 15
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: warn and mute command #142
base: main
Are you sure you want to change the base?
Conversation
@TendTo I'd need to change the settings yaml but there's no placeholder file for default settings, is this behaviour intended? |
Do you mean src/spotted/config/yaml/settings.yaml? |
My bad, I missed from the new documentation the new way of creating your own settings and the absence of a |
Co-authored-by: Stefano Borzì <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding just a couple of test cases for the new features will ensure that they won't be broken easily in future updates
…ttedDMI-Bot into feat/warn_command
user.mute(info.bot) | ||
text = f"L'utente è stato mutato per {days} giorn{'o' if days == 1 else 'i'}." | ||
await info.bot.send_message(chat_id=info.chat_id, text=text) | ||
context.job_queue.run_once(unmute_user, timedelta(days=days), context=user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This job probably gets lost and the user remains muted if, for any reason, the bot gets restarted on the VM.
Just adding a safeguard job running at 5:00 utc could ensure this won't be a problem, but you would have to keep track of the timestamp in a db table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was actually not sure about putting the timedelta in the db table or not, in that case I might as well starting the job_queue on each bot restart rather than checking every day
warn_expiration = datetime.now() + timedelta(days=Config.post_get("warn_after_days")) | ||
DbManager.delete_from( | ||
table_name="warned_users", | ||
where="warn_time > %s", | ||
where_args=(warn_expiration,), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on how you implement warn_time
, but this should probably be a -
and warn_time < %s
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure 🤔
class IsAdminFilter(MessageFilter): | ||
"""Check if the message from the update was sent by | ||
one of the administrators of the group | ||
Args: | ||
MessageFilter: the superclass for the filter | ||
""" | ||
|
||
def filter(self, message: Message): | ||
chat = message.chat | ||
sender_id = message.from_user.id | ||
if chat.type in [Chat.SUPERGROUP, Chat.GROUP]: | ||
return sender_id in [admin.id for admin in chat.get_administrators(chat.id)] | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting Filter. It opens quite a few possibilities
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice 🚀
CREATE TABLE IF NOT EXISTS muted_users | ||
( | ||
user_id BIGINT NOT NULL, | ||
PRIMARY KEY user_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no timestamp here?
we could close this for #155 |
Prerequisites
CHANGELOG.rst
file with an overview of the changes made.Description
Adding /warn and /mute command to the bot functionalities
Issue closed by this PR
Does this PR introduce a breaking change?
Python version you are using
Python 3.10.12