Skip to content

Commit 17b161c

Browse files
committed
chore: improve types in telegram
1 parent 5d3c764 commit 17b161c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

freqtrade/rpc/telegram.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ def authorized_only(command_handler: Callable[..., Coroutine[Any, Any, None]]):
9797
"""
9898

9999
@wraps(command_handler)
100-
async def wrapper(self, *args, **kwargs):
100+
async def wrapper(self, *args, **kwargs) -> None:
101101
"""Decorator logic"""
102-
update: Update = kwargs.get("update") or args[0]
102+
update = kwargs.get("update") or args[0]
103103

104104
# Reject unauthorized messages
105105
message: Message = (
106106
update.message if update.callback_query is None else update.callback_query.message
107107
)
108108
cchat_id: int = int(message.chat_id)
109109
ctopic_id: int | None = message.message_thread_id
110-
from_user_id: str = str(update.effective_user.id)
110+
from_user_id: str = str(update.effective_user.id if update.effective_user else "")
111111

112112
chat_id = int(self._config["telegram"]["chat_id"])
113113
if cchat_id != chat_id:
@@ -2158,7 +2158,9 @@ async def _tg_info(self, update: Update, context: CallbackContext) -> None:
21582158
return
21592159
chat_id = update.message.chat_id
21602160
topic_id = update.message.message_thread_id
2161-
user_id = update.message.from_user.id if topic_id is not None else None
2161+
user_id = (
2162+
update.effective_user.id if topic_id is not None and update.effective_user else None
2163+
)
21622164

21632165
msg = f"""Freqtrade Bot Info:
21642166
```json
@@ -2167,7 +2169,7 @@ async def _tg_info(self, update: Update, context: CallbackContext) -> None:
21672169
"token": "********",
21682170
"chat_id": "{chat_id}",
21692171
{f'"topic_id": "{topic_id}",' if topic_id else ""}
2170-
{f'//"authorized_users": ["{user_id}"]' if topic_id else ""}
2172+
{f'//"authorized_users": ["{user_id}"]' if topic_id and user_id else ""}
21712173
}}
21722174
```
21732175
"""

0 commit comments

Comments
 (0)