mirror of
https://github.com/paul-nameless/tg
synced 2025-02-16 10:38:23 +00:00
update readme (#142)
* Add contacts shortcut and link to config file * Remove logging in utils * Remove unused imports and create script for checking formatting * Remove unused import <Iterable> in models * Fix check.sh script * Reformat check.sh * Update isort * Add check flag for black
This commit is contained in:
parent
b37bba8fb7
commit
4aaf9d9d1f
8 changed files with 44 additions and 30 deletions
26
.github/workflows/main.yml
vendored
26
.github/workflows/main.yml
vendored
|
@ -1,28 +1,22 @@
|
||||||
# This is a basic workflow to help you get started with Actions
|
|
||||||
|
|
||||||
name: CI
|
name: CI
|
||||||
|
|
||||||
# Controls when the action will run. Triggers the workflow on push or pull request
|
|
||||||
# events but only for the master branch
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
|
|
||||||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
|
||||||
jobs:
|
jobs:
|
||||||
# This workflow contains a single job called "build"
|
|
||||||
build:
|
build:
|
||||||
# The type of runner that the job will run on
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [3.8]
|
python-version: [3.8]
|
||||||
|
|
||||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
|
||||||
steps:
|
steps:
|
||||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
@ -32,16 +26,8 @@ jobs:
|
||||||
|
|
||||||
- name: Install tools
|
- name: Install tools
|
||||||
run: |
|
run: |
|
||||||
pip install black==19.10b0 mypy==0.770 isort==4.3.21
|
pip install black==19.10b0 mypy==0.770 isort==5.1.0 flake8==3.8.3
|
||||||
|
|
||||||
- name: Check formatting with black
|
- name: Check formatting and run linters
|
||||||
run: |
|
run: |
|
||||||
black --check tg
|
sh check.sh
|
||||||
|
|
||||||
- name: Check sort formatting
|
|
||||||
run: |
|
|
||||||
isort -c tg/*.py
|
|
||||||
|
|
||||||
- name: Check types with mypy
|
|
||||||
run: |
|
|
||||||
mypy tg --warn-redundant-casts --warn-unused-ignores --no-warn-no-return --warn-unreachable --strict-equality --ignore-missing-imports --warn-unused-configs --disallow-untyped-calls --disallow-untyped-defs --disallow-incomplete-defs --check-untyped-defs --disallow-untyped-decorators
|
|
||||||
|
|
20
check.sh
Executable file
20
check.sh
Executable file
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
echo Checking and formatting with black...
|
||||||
|
black --check .
|
||||||
|
|
||||||
|
echo Python type checking...
|
||||||
|
mypy tg --warn-redundant-casts --warn-unused-ignores \
|
||||||
|
--no-warn-no-return --warn-unreachable --strict-equality \
|
||||||
|
--ignore-missing-imports --warn-unused-configs \
|
||||||
|
--disallow-untyped-calls --disallow-untyped-defs \
|
||||||
|
--disallow-incomplete-defs --check-untyped-defs \
|
||||||
|
--disallow-untyped-decorators
|
||||||
|
|
||||||
|
echo Checking import sorting...
|
||||||
|
isort -c tg/*.py
|
||||||
|
|
||||||
|
echo Checking unused imports...
|
||||||
|
flake8 --select=F401
|
|
@ -90,6 +90,8 @@ PHONE = "[your phone number]"
|
||||||
|
|
||||||
### Advanced configuration:
|
### Advanced configuration:
|
||||||
|
|
||||||
|
All configurable variables can be found [here](https://github.com/paul-nameless/tg/blob/master/tg/config.py)
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -210,6 +212,7 @@ For navigation arrow keys also can be used.
|
||||||
- `p`: pin/unpin current chat
|
- `p`: pin/unpin current chat
|
||||||
- `u`: mark read/unread
|
- `u`: mark read/unread
|
||||||
- `r`: read current chat
|
- `r`: read current chat
|
||||||
|
- `c`: show list of contacts
|
||||||
- `?`: show help
|
- `?`: show help
|
||||||
|
|
||||||
## Msgs:
|
## Msgs:
|
||||||
|
|
|
@ -9,6 +9,7 @@ from tempfile import NamedTemporaryFile
|
||||||
from typing import Any, Callable, Dict, List, Optional
|
from typing import Any, Callable, Dict, List, Optional
|
||||||
|
|
||||||
from telegram.utils import AsyncResult
|
from telegram.utils import AsyncResult
|
||||||
|
|
||||||
from tg import config
|
from tg import config
|
||||||
from tg.models import Model
|
from tg.models import Model
|
||||||
from tg.msg import MsgProxy
|
from tg.msg import MsgProxy
|
||||||
|
|
|
@ -2,7 +2,7 @@ import logging
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple
|
from typing import Any, Dict, List, Optional, Set, Tuple
|
||||||
|
|
||||||
from tg.msg import MsgProxy
|
from tg.msg import MsgProxy
|
||||||
from tg.tdlib import ChatAction, Tdlib, UserStatus
|
from tg.tdlib import ChatAction, Tdlib, UserStatus
|
||||||
|
|
10
tg/tdlib.py
10
tg/tdlib.py
|
@ -27,9 +27,6 @@ class ChatType(Enum):
|
||||||
channel = "channel"
|
channel = "channel"
|
||||||
chatTypeSecret = "secret"
|
chatTypeSecret = "secret"
|
||||||
|
|
||||||
def is_group(self, chat_type: "Union[str, ChatType]") -> bool:
|
|
||||||
return chat_type in (self.chatTypeSupergroup, self.chatTypeBasicGroup)
|
|
||||||
|
|
||||||
|
|
||||||
class UserStatus(Enum):
|
class UserStatus(Enum):
|
||||||
userStatusEmpty = ""
|
userStatusEmpty = ""
|
||||||
|
@ -276,3 +273,10 @@ def get_chat_type(chat: Dict[str, Any]) -> Optional[ChatType]:
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def is_group(chat_type: Union[str, ChatType]) -> bool:
|
||||||
|
return chat_type in (
|
||||||
|
ChatType.chatTypeSupergroup,
|
||||||
|
ChatType.chatTypeBasicGroup,
|
||||||
|
)
|
||||||
|
|
|
@ -19,7 +19,7 @@ from subprocess import CompletedProcess
|
||||||
from types import TracebackType
|
from types import TracebackType
|
||||||
from typing import Any, Optional, Tuple, Type
|
from typing import Any, Optional, Tuple, Type
|
||||||
|
|
||||||
from tg import colors, config
|
from tg import config
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
emoji_pattern = re.compile(
|
emoji_pattern = re.compile(
|
||||||
|
@ -240,7 +240,6 @@ def pretty_ts(ts: int) -> str:
|
||||||
diff = now - datetime.utcfromtimestamp(ts)
|
diff = now - datetime.utcfromtimestamp(ts)
|
||||||
second_diff = diff.seconds
|
second_diff = diff.seconds
|
||||||
day_diff = diff.days
|
day_diff = diff.days
|
||||||
log.info("diff:: %s, %s, %s", ts, second_diff, day_diff)
|
|
||||||
|
|
||||||
if day_diff < 0:
|
if day_diff < 0:
|
||||||
return ""
|
return ""
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
import curses
|
import curses
|
||||||
import logging
|
import logging
|
||||||
from _curses import window # type: ignore
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Dict, List, Optional, Tuple, Union, cast
|
from typing import Any, Dict, List, Optional, Tuple, Union, cast
|
||||||
|
|
||||||
|
from _curses import window # type: ignore
|
||||||
|
|
||||||
from tg import config
|
from tg import config
|
||||||
from tg.colors import bold, cyan, get_color, magenta, reverse, white, yellow
|
from tg.colors import bold, cyan, get_color, magenta, reverse, white, yellow
|
||||||
from tg.models import Model, UserModel
|
from tg.models import Model, UserModel
|
||||||
from tg.msg import MsgProxy
|
from tg.msg import MsgProxy
|
||||||
from tg.tdlib import ChatType, get_chat_type
|
from tg.tdlib import ChatType, get_chat_type, is_group
|
||||||
from tg.utils import emoji_pattern, get_color_by_str, num, truncate_to_len
|
from tg.utils import emoji_pattern, get_color_by_str, num, truncate_to_len
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -215,7 +216,7 @@ class ChatView:
|
||||||
if user:
|
if user:
|
||||||
last_msg_sender = get_user_label(self.model.users, user)
|
last_msg_sender = get_user_label(self.model.users, user)
|
||||||
chat_type = get_chat_type(chat)
|
chat_type = get_chat_type(chat)
|
||||||
if chat_type and chat_type.is_group(chat_type):
|
if chat_type and is_group(chat_type):
|
||||||
return last_msg_sender, last_msg
|
return last_msg_sender, last_msg
|
||||||
|
|
||||||
return None, last_msg
|
return None, last_msg
|
||||||
|
@ -629,7 +630,7 @@ def _get_action_label(users: UserModel, chat: Dict[str, Any]) -> Optional[str]:
|
||||||
if actioner and action:
|
if actioner and action:
|
||||||
label = f"{action}..."
|
label = f"{action}..."
|
||||||
chat_type = get_chat_type(chat)
|
chat_type = get_chat_type(chat)
|
||||||
if chat_type and chat_type.is_group(chat_type):
|
if chat_type and is_group(chat_type):
|
||||||
user_label = get_user_label(users, actioner)
|
user_label = get_user_label(users, actioner)
|
||||||
label = f"{user_label} {label}"
|
label = f"{user_label} {label}"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue