-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auto delete): Added auto delete for Bot messages in group
- Loading branch information
Nickelza
committed
May 5, 2024
1 parent
a866614
commit a0d3493
Showing
16 changed files
with
339 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,3 +359,5 @@ PLUNDER_COOLDOWN_DURATION= | |
PLUNDER_REPAY_MULTIPLIER= | ||
|
||
IMPEL_DOWN_BAIL_PER_MINUTE= | ||
|
||
AUTO_DELETE_DURATION_VALUES= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from telegram import Update | ||
from telegram.ext import ContextTypes | ||
|
||
import resources.Environment as Env | ||
import resources.phrases as phrases | ||
from src.model.GroupChat import GroupChat | ||
from src.model.enums.Emoji import Emoji | ||
from src.model.enums.ReservedKeyboardKeys import ReservedKeyboardKeys | ||
from src.model.pojo.Keyboard import Keyboard | ||
from src.service.list_service import get_options_keyboard | ||
from src.service.message_service import full_message_send | ||
|
||
|
||
async def manage( | ||
update: Update, | ||
context: ContextTypes.DEFAULT_TYPE, | ||
inbound_keyboard: Keyboard, | ||
group_chat: GroupChat, | ||
) -> None: | ||
""" | ||
Manage the auto delete screen | ||
:param update: The update object | ||
:param context: The context object | ||
:param inbound_keyboard: The inbound keyboard | ||
:param group_chat: The group chat | ||
:return: None | ||
""" | ||
|
||
if ReservedKeyboardKeys.DEFAULT_PRIMARY_KEY in inbound_keyboard.info: | ||
duration = inbound_keyboard.get(ReservedKeyboardKeys.DEFAULT_PRIMARY_KEY) | ||
group_chat.auto_delete_duration = duration | ||
group_chat.save() | ||
|
||
current_value = group_chat.auto_delete_duration | ||
# Create numeric keyboard with all possible values | ||
numeric_keyboard: list[list[Keyboard]] = get_options_keyboard( | ||
inbound_info=inbound_keyboard.info, | ||
values=Env.AUTO_DELETE_DURATION_VALUES.get_list(), | ||
current_selected=current_value, | ||
) | ||
|
||
# Add "Never" option as first option | ||
numeric_keyboard.insert( | ||
0, | ||
[ | ||
Keyboard( | ||
(Emoji.RADIO_BUTTON if current_value is None else "") + phrases.TEXT_NEVER, | ||
info={ReservedKeyboardKeys.DEFAULT_PRIMARY_KEY: None}, | ||
inbound_info=inbound_keyboard.info, | ||
) | ||
], | ||
) | ||
|
||
ot_text = phrases.AUTO_DELETE_SET.format( | ||
phrases.TEXT_NEVER if current_value is None else current_value | ||
) | ||
await full_message_send( | ||
context, | ||
ot_text, | ||
update=update, | ||
keyboard=numeric_keyboard, | ||
add_delete_button=True, | ||
use_close_delete=True, | ||
inbound_keyboard=inbound_keyboard, | ||
should_auto_delete=False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import datetime | ||
|
||
from peewee import * | ||
|
||
from src.model.BaseModel import BaseModel | ||
from src.model.GroupChat import GroupChat | ||
|
||
|
||
class GroupChatAutoDelete(BaseModel): | ||
""" | ||
Group Chat Auto Delete class | ||
""" | ||
|
||
id: int | PrimaryKeyField = PrimaryKeyField() | ||
group_chat: GroupChat | ForeignKeyField = ForeignKeyField( | ||
GroupChat, backref="auto_delete", on_delete="CASCADE" | ||
) | ||
message_id: int | IntegerField = IntegerField() | ||
date: datetime.datetime | DateTimeField = DateTimeField(default=datetime.datetime.now) | ||
delete_date: datetime.datetime | DateTimeField = DateTimeField() | ||
|
||
class Meta: | ||
db_table = "group_chat_auto_delete" | ||
|
||
|
||
GroupChatAutoDelete.create_table() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.