Skip to content
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

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft

Feat: warn and mute command #142

wants to merge 28 commits into from

Conversation

alepiaz
Copy link
Contributor

@alepiaz alepiaz commented Nov 26, 2023

Prerequisites

  • I have read and understood the contributing guide.
  • The commit message follows the conventional commits guidelines. (mostly)
  • Tested the changes locally with a real Telegram bot.
  • Introduced tests for the changes have been added (for bug fixes / features).
  • Docs have been added/updated (for bug fixes / features).
  • I have updated the 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?

  • Yes
  • No

Python version you are using

Python 3.10.12

@alepiaz alepiaz added the enhancement New feature or request label Nov 26, 2023
@alepiaz alepiaz added this to the Moderation commands milestone Nov 26, 2023
@alepiaz alepiaz self-assigned this Nov 26, 2023
@alepiaz
Copy link
Contributor Author

alepiaz commented Nov 27, 2023

@TendTo I'd need to change the settings yaml but there's no placeholder file for default settings, is this behaviour intended?

@TendTo
Copy link
Member

TendTo commented Nov 27, 2023

@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?

@alepiaz
Copy link
Contributor Author

alepiaz commented Nov 27, 2023

@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 settings.yaml.default file

Copy link
Member

@TendTo TendTo left a 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

src/spotted/data/user.py Outdated Show resolved Hide resolved
src/spotted/data/user.py Show resolved Hide resolved
src/spotted/data/user.py Outdated Show resolved Hide resolved
src/spotted/data/user.py Outdated Show resolved Hide resolved
src/spotted/data/user.py Outdated Show resolved Hide resolved
src/spotted/handlers/job_handlers.py Outdated Show resolved Hide resolved
src/spotted/config/yaml/settings.yaml.default Outdated Show resolved Hide resolved
src/spotted/handlers/__init__.py Outdated Show resolved Hide resolved
src/spotted/handlers/job_handlers.py Outdated Show resolved Hide resolved
src/spotted/handlers/warn.py Outdated Show resolved Hide resolved
@alepiaz alepiaz marked this pull request as draft November 30, 2023 23:47
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)
Copy link
Member

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

Copy link
Contributor Author

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

Comment on lines +73 to +78
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,),
)
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure 🤔

src/spotted/handlers/job_handlers.py Show resolved Hide resolved
Comment on lines 6 to 18
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
Copy link
Member

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

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no timestamp here?

@Helias
Copy link
Member

Helias commented Jan 3, 2024

we could close this for #155

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comando /warn Implementation of /mute command to mute a user for a defined time
4 participants