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

Update python-telegram dependency #303

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
363 changes: 0 additions & 363 deletions poetry.lock

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The depencies versions are specified in pyproject.toml, we don't need a peotry.lock file.
  2. Installation with pip install . does not require peotry.lock

This file was deleted.

10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ repository = "https://github.com/paul-nameless/tg"

[tool.poetry.dependencies]
python = "^3.8"
python-telegram = "0.15.0"
python-telegram = "0.18.0"

[tool.poetry.dev-dependencies]
black = "20.8b1"
flake8 = "3.8.4"
isort = "5.6.2"
mypy = "0.812"
black = "*"
flake8 = "*"
isort = "*"
mypy = "*"

[tool.poetry.scripts]
tg = "tg.__main__:main"
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
packages=["tg"],
entry_points={"console_scripts": ["tg = tg.__main__:main"]},
python_requires=">=3.8",
install_requires=["python-telegram==0.15.0"],
install_requires=["python-telegram==0.18.0"],
)
6 changes: 3 additions & 3 deletions tg/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging.handlers
import signal
import threading
from curses import window, wrapper # type: ignore
from curses import window, wrapper
from functools import partial
from types import FrameType
from typing import Optional

from tg import config, update_handlers, utils
from tg.controllers import Controller
Expand All @@ -15,9 +16,8 @@


def run(tg: Tdlib, stdscr: window) -> None:

# handle ctrl+c, to avoid interrupting tg when subprocess is called
def interrupt_signal_handler(sig: int, frame: FrameType) -> None:
def interrupt_signal_handler(sig: int, frame: Optional[FrameType]) -> None:
# TODO: draw on status pane: to quite press <q>
log.info("Interrupt signal is handled and ignored on purpose.")

Expand Down
2 changes: 1 addition & 1 deletion tg/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
DOWNLOAD_DIR = os.path.expanduser("~/Downloads/")

if os.path.isfile(CONFIG_FILE):
config_params = runpy.run_path(CONFIG_FILE) # type: ignore
config_params = runpy.run_path(CONFIG_FILE)
for param, value in config_params.items():
if param.isupper():
globals()[param] = value
Expand Down
21 changes: 11 additions & 10 deletions tg/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from functools import partial, wraps
from queue import Queue
from tempfile import NamedTemporaryFile
from types import FrameType
from typing import Any, Callable, Dict, List, Optional

from telegram.utils import AsyncResult
Expand Down Expand Up @@ -303,8 +304,8 @@ def reply_with_long_message(self) -> None:
f.write(insert_replied_msg(msg))
f.seek(0)
s.call(config.LONG_MSG_CMD.format(file_path=shlex.quote(f.name)))
with open(f.name) as f:
if replied_msg := strip_replied_msg(f.read().strip()):
with open(f.name) as t:
if replied_msg := strip_replied_msg(t.read().strip()):
self.model.view_all_msgs()
self.tg.reply_message(chat_id, reply_to_msg, replied_msg)
self.present_info("Message sent")
Expand Down Expand Up @@ -336,8 +337,8 @@ def write_long_msg(self) -> None:
) as s:
self.tg.send_chat_action(chat_id, ChatAction.chatActionTyping)
s.call(config.LONG_MSG_CMD.format(file_path=shlex.quote(f.name)))
with open(f.name) as f:
if msg := f.read().strip():
with open(f.name) as t:
if msg := t.read().strip():
self.model.send_message(text=msg)
self.present_info("Message sent")
else:
Expand All @@ -364,8 +365,8 @@ def choose_and_send_file(self) -> None:
try:
with NamedTemporaryFile("w") as f, suspend(self.view) as s:
s.call(config.FILE_PICKER_CMD.format(file_path=f.name))
with open(f.name) as f:
file_path = f.read().strip()
with open(f.name) as t:
file_path = t.read().strip()
except FileNotFoundError:
pass
if not file_path or not os.path.isfile(file_path):
Expand Down Expand Up @@ -488,7 +489,7 @@ def can_send_msg(self) -> bool:
chat = self.model.chats.chats[self.model.current_chat]
return chat["permissions"]["can_send_messages"]

def _open_msg(self, msg: MsgProxy, cmd: str = None) -> None:
def _open_msg(self, msg: MsgProxy, cmd: Optional[str] = None) -> None:
if msg.is_text:
with NamedTemporaryFile("w", suffix=".txt") as f:
f.write(msg.text_content)
Expand Down Expand Up @@ -544,8 +545,8 @@ def edit_msg(self) -> None:
f.write(msg.text_content)
f.flush()
s.call(f"{config.EDITOR} {f.name}")
with open(f.name) as f:
if text := f.read().strip():
with open(f.name) as t:
if text := t.read().strip():
self.model.edit_message(text=text)
self.present_info("Message edited")

Expand Down Expand Up @@ -775,7 +776,7 @@ def handle(self, handlers: Dict[str, HandlerType], size: float) -> str:
except Exception:
log.exception("Error happend in key handle loop")

def resize_handler(self, signum: int, frame: Any) -> None:
def resize_handler(self, signum: int, frame: Optional[FrameType]) -> None:
self.view.resize_handler()
self.resize()

Expand Down
3 changes: 1 addition & 2 deletions tg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def _load_next_chats(self) -> None:
"""
if self.have_full_chat_list:
return None
offset_order = 2 ** 63 - 1
offset_order = 2**63 - 1
offset_chat_id = 0
if len(self.chats):
offset_chat_id = self.chats[-1]["id"]
Expand Down Expand Up @@ -655,7 +655,6 @@ def send_message(self, chat_id: int, text: str) -> None:


class UserModel:

types = {
"userTypeUnknown": "unknown",
"userTypeBot": "bot",
Expand Down
1 change: 0 additions & 1 deletion tg/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class MsgProxy:

fields_mapping = {
"messageDocument": ("document", "document"),
"messageVoiceNote": ("voice_note", "voice"),
Expand Down
4 changes: 2 additions & 2 deletions tg/tdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,12 @@ def get_secret_chat(
return self._send_data(data)

def send_chat_action(
self, chat_id: int, action: ChatAction, progress: int = None
self, chat_id: int, action: ChatAction
) -> AsyncResult:
data = {
"@type": "sendChatAction",
"chat_id": chat_id,
"action": {"@type": action.name, "progress": progress},
"action": {"@type": action.name},
}
return self._send_data(data)

Expand Down
8 changes: 5 additions & 3 deletions tg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from tg import config

log = logging.getLogger(__name__)
units = {"B": 1, "KB": 10 ** 3, "MB": 10 ** 6, "GB": 10 ** 9, "TB": 10 ** 12}
units = {"B": 1, "KB": 10**3, "MB": 10**6, "GB": 10**9, "TB": 10**12}


class LogWriter:
Expand Down Expand Up @@ -85,7 +85,9 @@ def get_file_handler(file_path: str) -> str:
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))

caps = get_mailcap()
handler, view = mailcap.findmatch(caps, mtype, filename=shlex.quote(file_path))
handler, view = mailcap.findmatch(
caps, mtype, filename=shlex.quote(file_path)
)
if not handler:
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))
return handler
Expand Down Expand Up @@ -230,7 +232,7 @@ def run_with_input(self, cmd: str, text: str) -> None:
if proc.returncode:
input(f"Command <{cmd}> failed: press <enter> to continue")

def open_file(self, file_path: str, cmd: str = None) -> None:
def open_file(self, file_path: str, cmd: Optional[str] = None) -> None:
if cmd:
cmd = cmd % shlex.quote(file_path)
else:
Expand Down
4 changes: 2 additions & 2 deletions tg/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple, Union, cast

from _curses import window # type: ignore
from _curses import window

from tg import config
from tg.colors import bold, cyan, get_color, magenta, reverse, white, yellow
Expand Down Expand Up @@ -199,7 +199,7 @@ def draw(
self, current: int, chats: List[Dict[str, Any]], title: str = "Chats"
) -> None:
self.win.erase()
line = curses.ACS_VLINE # type: ignore
line = curses.ACS_VLINE
width = self.w - 1

self.win.vline(0, width, line, self.h)
Expand Down