mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 11:53:08 +00:00
Quote filename path for mailcap (#208)
* Quote filename path for mailcap * Fix formatting
This commit is contained in:
parent
4190da13f8
commit
1cd023afc1
4 changed files with 12 additions and 42 deletions
|
@ -427,8 +427,7 @@ class Controller:
|
||||||
self.tg.send_video(file_path, chat_id, width, height, duration)
|
self.tg.send_video(file_path, chat_id, width, height, duration)
|
||||||
|
|
||||||
def send_file(
|
def send_file(
|
||||||
self,
|
self, send_file_fun: Callable[[str, int], AsyncResult],
|
||||||
send_file_fun: Callable[[str, int], AsyncResult],
|
|
||||||
) -> None:
|
) -> None:
|
||||||
_input = self.view.status.get_input()
|
_input = self.view.status.get_input()
|
||||||
if _input is None:
|
if _input is None:
|
||||||
|
@ -552,10 +551,7 @@ class Controller:
|
||||||
def _get_user_ids(self, is_multiple: bool = False) -> List[int]:
|
def _get_user_ids(self, is_multiple: bool = False) -> List[int]:
|
||||||
users = self.model.users.get_users()
|
users = self.model.users.get_users()
|
||||||
_, cols = self.view.stdscr.getmaxyx()
|
_, cols = self.view.stdscr.getmaxyx()
|
||||||
limit = min(
|
limit = min(int(cols / 2), max(len(user.name) for user in users),)
|
||||||
int(cols / 2),
|
|
||||||
max(len(user.name) for user in users),
|
|
||||||
)
|
|
||||||
users_out = "\n".join(
|
users_out = "\n".join(
|
||||||
f"{user.id}\t{user.name:<{limit}} | {user.status}"
|
f"{user.id}\t{user.name:<{limit}} | {user.status}"
|
||||||
for user in sorted(users, key=lambda user: user.order)
|
for user in sorted(users, key=lambda user: user.order)
|
||||||
|
|
25
tg/tdlib.py
25
tg/tdlib.py
|
@ -294,50 +294,35 @@ class Tdlib(Telegram):
|
||||||
}
|
}
|
||||||
return self._send_data(data)
|
return self._send_data(data)
|
||||||
|
|
||||||
def get_basic_group(
|
def get_basic_group(self, basic_group_id: int,) -> AsyncResult:
|
||||||
self,
|
|
||||||
basic_group_id: int,
|
|
||||||
) -> AsyncResult:
|
|
||||||
data = {
|
data = {
|
||||||
"@type": "getBasicGroup",
|
"@type": "getBasicGroup",
|
||||||
"basic_group_id": basic_group_id,
|
"basic_group_id": basic_group_id,
|
||||||
}
|
}
|
||||||
return self._send_data(data)
|
return self._send_data(data)
|
||||||
|
|
||||||
def get_basic_group_full_info(
|
def get_basic_group_full_info(self, basic_group_id: int,) -> AsyncResult:
|
||||||
self,
|
|
||||||
basic_group_id: int,
|
|
||||||
) -> AsyncResult:
|
|
||||||
data = {
|
data = {
|
||||||
"@type": "getBasicGroupFullInfo",
|
"@type": "getBasicGroupFullInfo",
|
||||||
"basic_group_id": basic_group_id,
|
"basic_group_id": basic_group_id,
|
||||||
}
|
}
|
||||||
return self._send_data(data)
|
return self._send_data(data)
|
||||||
|
|
||||||
def get_supergroup(
|
def get_supergroup(self, supergroup_id: int,) -> AsyncResult:
|
||||||
self,
|
|
||||||
supergroup_id: int,
|
|
||||||
) -> AsyncResult:
|
|
||||||
data = {
|
data = {
|
||||||
"@type": "getSupergroup",
|
"@type": "getSupergroup",
|
||||||
"supergroup_id": supergroup_id,
|
"supergroup_id": supergroup_id,
|
||||||
}
|
}
|
||||||
return self._send_data(data)
|
return self._send_data(data)
|
||||||
|
|
||||||
def get_supergroup_full_info(
|
def get_supergroup_full_info(self, supergroup_id: int,) -> AsyncResult:
|
||||||
self,
|
|
||||||
supergroup_id: int,
|
|
||||||
) -> AsyncResult:
|
|
||||||
data = {
|
data = {
|
||||||
"@type": "getSupergroupFullInfo",
|
"@type": "getSupergroupFullInfo",
|
||||||
"supergroup_id": supergroup_id,
|
"supergroup_id": supergroup_id,
|
||||||
}
|
}
|
||||||
return self._send_data(data)
|
return self._send_data(data)
|
||||||
|
|
||||||
def get_secret_chat(
|
def get_secret_chat(self, secret_chat_id: int,) -> AsyncResult:
|
||||||
self,
|
|
||||||
secret_chat_id: int,
|
|
||||||
) -> AsyncResult:
|
|
||||||
data = {
|
data = {
|
||||||
"@type": "getSecretChat",
|
"@type": "getSecretChat",
|
||||||
"secret_chat_id": secret_chat_id,
|
"secret_chat_id": secret_chat_id,
|
||||||
|
|
15
tg/utils.py
15
tg/utils.py
|
@ -85,7 +85,9 @@ def get_file_handler(file_path: str) -> str:
|
||||||
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))
|
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))
|
||||||
|
|
||||||
caps = get_mailcap()
|
caps = get_mailcap()
|
||||||
handler, view = mailcap.findmatch(caps, mtype, filename=file_path)
|
handler, view = mailcap.findmatch(
|
||||||
|
caps, mtype, filename=shlex.quote(file_path)
|
||||||
|
)
|
||||||
if not handler:
|
if not handler:
|
||||||
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))
|
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))
|
||||||
return handler
|
return handler
|
||||||
|
@ -102,16 +104,7 @@ def parse_size(size: str) -> int:
|
||||||
def humanize_size(
|
def humanize_size(
|
||||||
num: int,
|
num: int,
|
||||||
suffix: str = "B",
|
suffix: str = "B",
|
||||||
suffixes: Tuple[str, ...] = (
|
suffixes: Tuple[str, ...] = ("", "K", "M", "G", "T", "P", "E", "Z",),
|
||||||
"",
|
|
||||||
"K",
|
|
||||||
"M",
|
|
||||||
"G",
|
|
||||||
"T",
|
|
||||||
"P",
|
|
||||||
"E",
|
|
||||||
"Z",
|
|
||||||
),
|
|
||||||
) -> str:
|
) -> str:
|
||||||
magnitude = int(math.floor(math.log(num, 1024)))
|
magnitude = int(math.floor(math.log(num, 1024)))
|
||||||
val = num / math.pow(1024, magnitude)
|
val = num / math.pow(1024, magnitude)
|
||||||
|
|
|
@ -280,11 +280,7 @@ class ChatView:
|
||||||
|
|
||||||
|
|
||||||
class MsgView:
|
class MsgView:
|
||||||
def __init__(
|
def __init__(self, stdscr: window, model: Model,) -> None:
|
||||||
self,
|
|
||||||
stdscr: window,
|
|
||||||
model: Model,
|
|
||||||
) -> None:
|
|
||||||
self.model = model
|
self.model = model
|
||||||
self.stdscr = stdscr
|
self.stdscr = stdscr
|
||||||
self.h = 0
|
self.h = 0
|
||||||
|
|
Loading…
Reference in a new issue