Skip to content

Commit

Permalink
feat: add bunch of improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
en9inerd committed Sep 26, 2023
1 parent c414cec commit d33d81b
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 215 deletions.
3 changes: 2 additions & 1 deletion Pipfile
Expand Up @@ -16,14 +16,15 @@ pytest = "*"
python-semantic-release = "*"
checksumdir = "*"
vulture = "*"
types-pyyaml = "*"

[packages]
pyyaml = "*"
docopt = "*"
telethon = "*"

[requires]
python_version = "3.10"
python_version = "3.11"

[pipenv]
allow_prereleases = true
19 changes: 13 additions & 6 deletions README.md
@@ -1,6 +1,6 @@
# TgEraser

[![PyPI version](https://badge.fury.io/py/tgeraser.svg)](https://badge.fury.io/py/tgeraser) [![Build Status](https://travis-ci.org/eng1nerd/tgeraser.svg?branch=master)](https://travis-ci.org/eng1nerd/tgeraser)
[![PyPI version](https://badge.fury.io/py/tgeraser.svg)](https://badge.fury.io/py/tgeraser)

Tool deletes all of your messages from chat/channel/dialog on Telegram without admin privilege. Official Telegram clients don't support deletion for all own messages from chat with one click (you need to manually select messages that you want to delete and you can delete only 100 selected meesages per time).

Expand All @@ -21,19 +21,18 @@ You need to specify own api_id and api_hash which you can get [here](https://my.
Tool deletes all your messages from chat/channel/dialog on Telegram.
Usage:
tgeraser [ (session <session_name>) -cdl NUM [ -i FILEPATH | -j DICT | -e ] -p PEER_ID ] | [ -k ]
tgeraser [(session <session_name>) --entity-type TYPE -l NUM [-i FILEPATH | -j DICT | -e] -p PEER_ID] | [-k]
tgeraser session <session_name> -p PEER_ID -t STRING
tgeraser session <session_name> -w
tgeraser session <session_name> -w [--entity-type TYPE]
tgeraser -h | --help
tgeraser --version
Options:
-i --input-file FILEPATH Specify YAML file that contains credentials. [default: ~/.tgeraser/credentials.yml]
-j --json DICT Specify json string that contains credentials (double quotes must be escaped).
-e --environment-variables Get credentials from environment variables (TG_API_ID, TG_API_HASH, TG_SESSION).
-d --dialogs List only Dialogs (Chats by default).
-c --channels List only Channels (Chats by default).
-w --wipe-everything Delete ALL messages from all chats/channels/dialogs that you have in list.
-w --wipe-everything Delete ALL messages from all entities of a certain type that you have in list.
--entity-type TYPE Available types: any, chat, channel, dialog. [default: chat]
-p --peers PEER_ID Specify certain peers by comma (chat/channel/dialog).
-l --limit NUM Show specified number of recent chats.
-t --time-period STRING Specify period for infinite loop to run messages deletion every X seconds/minutes/hours/days/weeks.
Expand All @@ -42,3 +41,11 @@ Options:
-h --help Show this screen.
--version Show version.
```

When you run tool without any options for the first time, it will ask you to create credentials file in `~/.tgeraser` directory. You can specify your own path to credentials file with `-i` option. Session files will be stored in the same directory.

**Note:**
- TgEraser uses YAML format for credentials file by default
- To use environment variables to specify credentials, you need to have pre-created session file
- You can specify credentials in JSON format with `-j` option, data must be escaped with double quotes and structured like YAML credentials file
- Example of credentials file in YAML format here: [credentials.yml](./examples/credentials.yml)
4 changes: 0 additions & 4 deletions build_package.py
Expand Up @@ -70,10 +70,6 @@ def formatting():
if "reformatted " in line:
file = line[len("reformatted ") :].strip()
changed.append(file)
for change in changed:
command = "git add {0}".format(change)
print(command)
execute(*(command.split(" ")))


@task(clean, formatting)
Expand Down
File renamed without changes.
75 changes: 36 additions & 39 deletions requirements-dev.txt
@@ -1,68 +1,65 @@
-i https://pypi.org/simple
astroid==2.15.6; python_full_version >= '3.7.2'
black==23.3.0
bleach==6.0.0; python_version >= '3.7'
certifi==2023.5.7; python_version >= '3.6'
annotated-types==0.5.0; python_version >= '3.7'
astroid==3.0.0b0; python_full_version >= '3.8.0'
black==23.9.1; python_version >= '3.8'
certifi==2023.7.22; python_version >= '3.6'
charset-normalizer==3.2.0; python_full_version >= '3.7.0'
checksumdir==1.2.0
click==8.1.4; python_version >= '3.7'
checksumdir==1.2.0; python_version >= '3.6' and python_version < '4.0'
click==8.1.7; python_version >= '3.7'
detect-secrets==1.4.0
dill==0.3.6; python_version < '3.11'
dill==0.3.7; python_version >= '3.11'
docutils==0.20.1; python_version >= '3.7'
dotty-dict==1.3.1; python_version >= '3.5' and python_version < '4.0'
exceptiongroup==1.1.2; python_version < '3.11'
gitdb==4.0.10; python_version >= '3.7'
gitpython==3.1.31; python_version >= '3.7'
gitpython==3.1.37; python_version >= '3.7'
idna==3.4; python_version >= '3.5'
importlib-metadata==6.8.0; python_version >= '3.8'
importlib-resources==5.7.0; python_version >= '3.7'
importlib-resources==5.13.0; python_version >= '3.8'
iniconfig==2.0.0; python_version >= '3.7'
isort==5.12.0
isort==5.12.0; python_full_version >= '3.8.0'
jaraco.classes==3.3.0; python_version >= '3.8'
jinja2==3.1.2; python_version >= '3.7'
keyring==24.2.0; python_version >= '3.8'
lazy-object-proxy==1.9.0; python_version >= '3.7'
markdown-it-py==3.0.0; python_version >= '3.8'
markupsafe==2.1.3; python_version >= '3.7'
mccabe==0.7.0; python_version >= '3.6'
mdurl==0.1.2; python_version >= '3.7'
more-itertools==9.1.0; python_version >= '3.7'
mypy==1.4.1
more-itertools==10.1.0; python_version >= '3.8'
mypy==1.5.1; python_version >= '3.8'
mypy-extensions==1.0.0; python_version >= '3.5'
nh3==0.2.14
packaging==23.1; python_version >= '3.7'
pathspec==0.11.1; python_version >= '3.7'
pathspec==0.11.2; python_version >= '3.7'
pkginfo==1.9.6; python_version >= '3.6'
platformdirs==3.8.1; python_version >= '3.7'
pluggy==1.2.0; python_version >= '3.7'
pydantic==1.10.11; python_version >= '3.7'
pygments==2.15.1; python_version >= '3.7'
pylint==3.0.0a6
platformdirs==3.10.0; python_version >= '3.7'
pluggy==1.3.0; python_version >= '3.8'
pydantic==2.4.0; python_version >= '3.7'
pydantic-core==2.10.0; python_version >= '3.7'
pygments==2.16.1; python_version >= '3.7'
pylint==3.0.0a7; python_full_version >= '3.8.0'
pynt==0.8.2
pynt-contrib==0.2.0
pytest==7.4.0
pytest==7.4.2; python_version >= '3.7'
python-gitlab==3.15.0; python_full_version >= '3.7.0'
python-semantic-release==8.0.0rc4
pyyaml==6.0
readme-renderer==40.0; python_version >= '3.8'
python-semantic-release==8.1.1; python_version >= '3.7'
pyyaml==6.0.1; python_version >= '3.6'
readme-renderer==42.0; python_version >= '3.8'
requests==2.31.0; python_version >= '3.7'
requests-toolbelt==1.0.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
rfc3986==2.0.0; python_version >= '3.7'
rich==13.4.2; python_full_version >= '3.7.0'
shellingham==1.5.0.post1; python_version >= '3.7'
six==1.16.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'
smmap==5.0.0; python_version >= '3.6'
toml==0.10.2; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2'
tomli==2.0.1; python_version < '3.11'
tomlkit==0.11.8; python_version >= '3.7'
twine==4.0.2
typing-extensions==4.7.1; python_version >= '3.7'
urllib3==2.0.3; python_version >= '3.7'
vulture==2.7
webencodings==0.5.1
wrapt==1.15.0; python_version < '3.11'
zipp==3.16.0; python_version >= '3.8'
rich==13.5.3; python_full_version >= '3.7.0'
shellingham==1.5.3; python_version >= '3.7'
smmap==5.0.1; python_version >= '3.7'
toml==0.10.2; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'
tomlkit==0.12.1; python_version >= '3.7'
twine==4.0.2; python_version >= '3.7'
types-pyyaml==6.0.12.12
typing-extensions==4.8.0; python_version >= '3.8'
urllib3==2.0.5; python_version >= '3.7'
vulture==2.9.1; python_version >= '3.7'
zipp==3.17.0; python_version >= '3.8'
docopt==0.6.2
pyaes==1.6.1
pyasn1==0.5.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
rsa==4.9; python_version >= '3.6' and python_version < '4'
telethon==1.28.5
telethon==1.30.3; python_version >= '3.5'
4 changes: 2 additions & 2 deletions requirements.txt
Expand Up @@ -2,6 +2,6 @@
docopt==0.6.2
pyaes==1.6.1
pyasn1==0.5.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
pyyaml==6.0
pyyaml==6.0.1; python_version >= '3.6'
rsa==4.9; python_version >= '3.6' and python_version < '4'
telethon==1.28.5
telethon==1.30.3; python_version >= '3.5'
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -12,6 +12,7 @@ classifiers =
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
License :: OSI Approved :: MIT License
keywords = telegram, api, delete messages
license = MIT License
Expand Down
3 changes: 2 additions & 1 deletion tgeraser/__main__.py
Expand Up @@ -2,7 +2,8 @@
Code so python -m will executed
"""

import asyncio
from . import core

if __name__ == "__main__":
core.entry()
asyncio.run(core.entry())
36 changes: 16 additions & 20 deletions tgeraser/core.py
Expand Up @@ -2,19 +2,18 @@
Tool deletes all your messages from chat/channel/dialog on Telegram.
Usage:
tgeraser [ (session <session_name>) -cdl NUM [ -i FILEPATH | -j DICT | -e ] -p PEER_ID ] | [ -k ]
tgeraser [(session <session_name>) --entity-type TYPE -l NUM [-i FILEPATH | -j DICT | -e] -p PEER_ID] | [-k]
tgeraser session <session_name> -p PEER_ID -t STRING
tgeraser session <session_name> -w
tgeraser session <session_name> -w [--entity-type TYPE]
tgeraser -h | --help
tgeraser --version
Options:
-i --input-file FILEPATH Specify YAML file that contains credentials. [default: ~/.tgeraser/credentials.yml]
-j --json DICT Specify json string that contains credentials (double quotes must be escaped).
-e --environment-variables Get credentials from environment variables (TG_API_ID, TG_API_HASH, TG_SESSION).
-d --dialogs List only Dialogs (Chats by default).
-c --channels List only Channels (Chats by default).
-w --wipe-everything Delete ALL messages from all chats/channels/dialogs that you have in list.
-w --wipe-everything Delete ALL messages from all entities of a certain type that you have in list.
--entity-type TYPE Available types: any, chat, channel, dialog. [default: chat]
-p --peers PEER_ID Specify certain peers by comma (chat/channel/dialog).
-l --limit NUM Show specified number of recent chats.
-t --time-period STRING Specify period for infinite loop to run messages deletion every X seconds/minutes/hours/days/weeks.
Expand All @@ -39,10 +38,8 @@
from .exceptions import TgEraserException
from .utils import cast_to_int, get_credentials

loop = asyncio.get_event_loop()


def entry() -> None:
async def entry() -> None:
"""
Entry function
"""
Expand Down Expand Up @@ -76,20 +73,20 @@ def entry() -> None:
sys.exit(0)

try:
credentials = get_credentials(arguments)
credentials = await get_credentials(arguments)

kwargs = {
**credentials,
"dialogs": arguments["--dialogs"],
"channels": arguments["--channels"],
"peers": arguments["--peers"],
"limit": arguments["--limit"],
"wipe_everything": arguments["--wipe-everything"]
"wipe_everything": arguments["--wipe-everything"],
"entity_type": arguments["--entity-type"],
}

client = Eraser(**kwargs)
client = Eraser(**credentials)
while True:
loop.run_until_complete(client.run())
await client.init(**kwargs)
await client.run()
if arguments["--time-period"]:
print(
"\n({0})\tNext erasing will be in {1} {2}.".format(
Expand All @@ -98,16 +95,15 @@ def entry() -> None:
period[1],
)
)
time.sleep(int(period[0]) * periods[period[1]])
await asyncio.sleep(int(period[0]) * periods[period[1]])
else:
break
client.disconnect()
loop.close()
except KeyboardInterrupt:
print("\nExiting...")
await client.disconnect()
except asyncio.CancelledError as err:
print("\n\nCancelled by user.\n", file=sys.stderr)
except Exception as err:
raise TgEraserException(err) from err


if __name__ == "__main__":
entry()
asyncio.run(entry())

0 comments on commit d33d81b

Please sign in to comment.