Skip to content

Commit

Permalink
print errors
Browse files Browse the repository at this point in the history
  • Loading branch information
markusressel committed Sep 28, 2024
1 parent 8e63d6c commit bc070b2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions keel_telegram_bot/bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ApplicationBuilder, ContextTypes
from telegram_click.argument import Argument, Flag, Selection
from telegram_click.decorator import command
from telegram_click.error_handler import DefaultErrorHandler

from keel_telegram_bot import util
from keel_telegram_bot.bot.permissions import CONFIG_ADMINS, CONFIGURED_CHAT_ID
Expand All @@ -26,6 +27,12 @@
LOGGER = logging.getLogger(__name__)


class CustomErrorHandler(DefaultErrorHandler):

def __init__(self):
super().__init__(silent_denial=True, print_error=True)


class KeelTelegramBot:
"""
The main entry class of the keel telegram bot
Expand Down Expand Up @@ -152,6 +159,7 @@ async def _start_callback(self, update: Update, context: ContextTypes.DEFAULT_TY
example="10", optional=True, default=10),
Flag(name=["tracked", "t"], description="Only list tracked resources"),
],
error_handler=CustomErrorHandler(),
permissions=CONFIGURED_CHAT_ID & CONFIG_ADMINS)
async def _list_resources_callback(
self, update: Update, context: ContextTypes.DEFAULT_TYPE,
Expand Down Expand Up @@ -203,6 +211,7 @@ def filter_resources_by(resources: List[Resource], glob: str or None, tracked: b
Argument(name=["limit", "l"], description="Limit the number of entries", type=int,
example="10", optional=True, default=10),
],
error_handler=CustomErrorHandler(),
permissions=CONFIGURED_CHAT_ID & CONFIG_ADMINS)
async def _list_tracked_callback(
self, update: Update, context: ContextTypes.DEFAULT_TYPE,
Expand Down Expand Up @@ -252,6 +261,7 @@ def filter_tracked_images_by(images: List[TrackedImage], glob: str or None) -> L
Flag(name=["approved", "a"], description="Include approved items"),
Flag(name=["rejected", "r"], description="Include rejected items"),
],
error_handler=CustomErrorHandler(),
permissions=CONFIGURED_CHAT_ID & CONFIG_ADMINS)
async def _list_approvals_callback(
self, update: Update, context: ContextTypes.DEFAULT_TYPE,
Expand Down Expand Up @@ -327,6 +337,7 @@ async def _list_approvals_callback(
type=Trigger, converter=lambda x: Trigger.from_value(x),
allowed_values=[Trigger.Default, Trigger.Poll, Trigger.Approval], optional=True),
],
error_handler=CustomErrorHandler(),
permissions=CONFIGURED_CHAT_ID & CONFIG_ADMINS)
async def _set_approval_count_callback(
self, update: Update, context: ContextTypes.DEFAULT_TYPE,
Expand Down Expand Up @@ -400,6 +411,7 @@ async def execute(update: Update, context: ContextTypes.DEFAULT_TYPE, item: Reso
example="default/myimage:1.5.5"),
Argument(name=["voter", "v"], description="Name of voter", example="john", optional=True),
],
error_handler=CustomErrorHandler(),
permissions=CONFIGURED_CHAT_ID & CONFIG_ADMINS)
async def _approve_callback(self, update: Update, context: ContextTypes.DEFAULT_TYPE,
identifier: str, voter: str or None) -> None:
Expand Down Expand Up @@ -444,6 +456,7 @@ async def execute(update: Update, context: ContextTypes.DEFAULT_TYPE, item: Appr
example="default/myimage:1.5.5"),
Argument(name=["voter", "v"], description="Name of voter", example="john", optional=True),
],
error_handler=CustomErrorHandler(),
permissions=CONFIGURED_CHAT_ID & CONFIG_ADMINS)
async def _reject_callback(self, update: Update, context: ContextTypes.DEFAULT_TYPE,
identifier: str, voter: str or None) -> None:
Expand Down Expand Up @@ -489,6 +502,7 @@ async def execute(update: Update, context: ContextTypes.DEFAULT_TYPE, item: Appr
example="default/myimage:1.5.5"),
Argument(name=["voter", "v"], description="Name of voter", example="john", optional=True),
],
error_handler=CustomErrorHandler(),
permissions=CONFIGURED_CHAT_ID & CONFIG_ADMINS)
async def _delete_callback(self, update: Update, context: ContextTypes.DEFAULT_TYPE,
identifier: str, voter: str or None) -> None:
Expand Down Expand Up @@ -528,6 +542,7 @@ async def execute(update: Update, context: ContextTypes.DEFAULT_TYPE, item: Appr
@command(
name=COMMAND_STATS,
description="Print keel statistics.",
error_handler=CustomErrorHandler(),
permissions=CONFIG_ADMINS,
)
async def _stats_callback(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
Expand Down Expand Up @@ -605,6 +620,7 @@ async def on_new_pending_approval(self, item: Approval):
@command(
name=COMMAND_CONFIG,
description="Print bot config.",
error_handler=CustomErrorHandler(),
permissions=CONFIGURED_CHAT_ID & CONFIG_ADMINS,
)
async def _config_callback(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
Expand All @@ -617,6 +633,7 @@ async def _config_callback(self, update: Update, context: ContextTypes.DEFAULT_T
@command(
name=COMMAND_HELP,
description="List commands supported by this bot.",
error_handler=CustomErrorHandler(),
permissions=CONFIG_ADMINS,
)
async def _help_callback(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
Expand All @@ -633,6 +650,7 @@ async def _help_callback(self, update: Update, context: ContextTypes.DEFAULT_TYP
@command(
name=COMMAND_CHATID,
description="Print chat ID.",
error_handler=CustomErrorHandler(),
permissions=CONFIG_ADMINS,
)
async def _chatid_callback(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
Expand All @@ -646,6 +664,7 @@ async def _chatid_callback(self, update: Update, context: ContextTypes.DEFAULT_T
@command(
name=COMMAND_VERSION,
description="Print bot version.",
error_handler=CustomErrorHandler(),
permissions=CONFIG_ADMINS,
)
async def _version_callback(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
Expand Down

0 comments on commit bc070b2

Please sign in to comment.