Skip to content

Commit

Permalink
added list_banned command
Browse files Browse the repository at this point in the history
  • Loading branch information
alepiaz committed Nov 18, 2023
1 parent ffc34fa commit ffc80fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion modules/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .stats import stats_callback, stats_cmd
from .follow_spot import follow_spot_callback
from .follow_comment import follow_spot_comment

from .list_banned import list_banned_cmd

def add_commands(updater: Updater):
"""Adds the list of commands with their description to the bot
Expand Down Expand Up @@ -86,6 +86,7 @@ def add_handlers(disp: Dispatcher):
disp.add_handler(CommandHandler("stats", stats_cmd, filters=Filters.chat_type.private))
disp.add_handler(CommandHandler("settings", settings_cmd, filters=Filters.chat_type.private))
disp.add_handler(CommandHandler("sban", sban_cmd, filters=admin_filter))
disp.add_handler(CommandHandler("list_banned", list_banned_cmd, filters=admin_filter))
disp.add_handler(CommandHandler("clean_pending", clean_pending_cmd, filters=admin_filter))
disp.add_handler(CommandHandler("db_backup", db_backup_cmd, run_async=True, filters=admin_filter))
disp.add_handler(CommandHandler("purge", purge_cmd, run_async=True, filters=admin_filter))
Expand Down
22 changes: 22 additions & 0 deletions modules/handlers/list_banned.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""/list_banned command"""
from datetime import datetime
from telegram import Update
from telegram.ext import CallbackContext
from modules.data import DbManager
from modules.utils import EventInfo

def list_banned_cmd(update: Update, context: CallbackContext):
info = EventInfo.from_message(update, context)
users = DbManager.select_from(select="*", table_name="banned_users")
info.bot.send_message(chat_id=info.chat_id, text=f"{write_banned_list(users)}",parse_mode='Markdown')

def write_banned_list(users: list)->str:
text = "*La lista dei bannati:*\n\n"
for user in users:
date = get_human_readable_datetime(user["ban_date"])
text += f"• {user['user_id']} bannato il {date}\n"
return text

def get_human_readable_datetime(date:str)->str:
datetime_object = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
return datetime_object.strftime('%d/%m/%Y %H:%M')

0 comments on commit ffc80fa

Please sign in to comment.