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

Delete report karma award message #134

Merged
merged 5 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ Dockerfile
*.db*
docs/
log/
.venv/
venv/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ __pycache__/
db_data/
/config/
.ruff_cache/
.venv/
venv/
24 changes: 16 additions & 8 deletions app/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@
from dotenv import load_dotenv

from app.models.config import Config, TgClientConfig

from .db import load_db_config
from .karmic_restriction import load_karmic_restriction_config
from .log import load_log_config
from .logging_config import logging_setup
from .storage import load_storage
from .webhook import load_webhook_config
from .logging_config import logging_setup


@lru_cache
def load_config(config_dir: Path = None) -> Config:
app_dir: Path = Path(__file__).parent.parent.parent
config_dir = config_dir or app_dir / 'config'
config_dir = config_dir or app_dir / "config"

with (config_dir / "bot-config.yaml").open('r', encoding="utf-8") as f:
with (config_dir / "bot-config.yaml").open("r", encoding="utf-8") as f:
config_file_data = yaml.load(f, Loader=yaml.FullLoader)

log_config = load_log_config(app_dir=app_dir, log_chat_id=config_file_data['log_chat_id'])
log_config = load_log_config(
app_dir=app_dir, log_chat_id=config_file_data["log_chat_id"]
)
logging_setup(config_dir, log_config)

load_dotenv(str(config_dir / '.env'))
load_dotenv(str(config_dir / ".env"))
_bot_token = os.getenv("KARMA_BOT_TOKEN")

return Config(
Expand All @@ -34,11 +37,16 @@ def load_config(config_dir: Path = None) -> Config:
webhook=load_webhook_config(),
app_dir=app_dir,
bot_token=_bot_token,
superusers=frozenset(config_file_data['superusers']),
superusers=frozenset(config_file_data["superusers"]),
log=log_config,
dump_chat_id=config_file_data['dump_chat_id'],
dump_chat_id=config_file_data["dump_chat_id"],
tg_client=TgClientConfig(bot_token=_bot_token),
storage=load_storage(config_file_data["storage"]),
report_karma_award=config_file_data.get("report_karma_award", 0),
callback_query_answer_cache_time=config_file_data.get("callback_query_answer_cache_time", 3600)
report_award_cleanup_delay=config_file_data.get(
"report_award_cleanup_delay", 3600
),
callback_query_answer_cache_time=config_file_data.get(
"callback_query_answer_cache_time", 3600
),
)
9 changes: 8 additions & 1 deletion app/handlers/moderator.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ async def approve_report_handler(
reward_amount=config.report_karma_award,
bot=bot,
)
await bot.edit_message_text(
message = await bot.edit_message_text(
"<b>{reporter}</b> получил <b>+{reward_amount}</b> кармы "
"в награду за репорт{admin_url}".format(
reporter=hd.quote(karma_change_result.karma_event.user_to.fullname),
Expand All @@ -349,6 +349,13 @@ async def approve_report_handler(
chat_id=first_report.chat.chat_id,
message_id=first_report.bot_reply_message_id,
)
if config.report_award_cleanup_delay > 0:
asyncio.create_task(
delete_message(
message,
sleep_time=config.report_award_cleanup_delay,
)
)

await callback_query.answer("Вы подтвердили репорт", show_alert=not award_enabled)
await cleanup_reports_dialog(
Expand Down
7 changes: 5 additions & 2 deletions app/models/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from .auto_restriction import AutoRestrictionConfig
from .db import DBConfig
from .log import LogConfig
from .storage import StorageConfig
from .tg_client import TgClientConfig
from .webhook import WebhookConfig
from .storage import StorageConfig


@dataclass
Expand All @@ -22,10 +22,13 @@ class Config:
dump_chat_id: int
tg_client: TgClientConfig
storage: StorageConfig
date_format: str = '%d.%m.%Y'
date_format: str = "%d.%m.%Y"
time_to_cancel_actions: int = 60
time_to_remove_temp_messages: int = 30
report_karma_award: int = 0
report_award_cleanup_delay: int = (
3600 # If time in seconds less than 1, then messages will not be deleted
)
callback_query_answer_cache_time: int = 3600


Expand Down