From 369ab56defda8bc2a8ed40f13400fa2d42eddabb Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Wed, 11 Mar 2020 16:22:32 +0800 Subject: [PATCH] Add docs and scripts --- .github/ISSUE_TEMPLATE/bug_report.md | 39 ++ .github/ISSUE_TEMPLATE/bug_report.zh-Hans.md | 39 ++ .github/ISSUE_TEMPLATE/feature_request.md | 22 ++ .../ISSUE_TEMPLATE/feature_request.zh-Hans.md | 22 ++ CHANGELOG.md | 31 ++ README.md | 340 ++++++++++++++++++ delethon/__init__.py | 2 +- delethon/__main__.py | 2 +- delethon/constants.py | 2 +- .../zh_CN/LC_MESSAGES/delethon.options.po | 46 ++- delethon/metadata.py | 2 +- delethon/options.py | 21 +- docs/CHANGELOG.zh-Hans.md | 31 ++ docs/README.zh-Hans.md | 290 +++++++++++++++ docs/issue_labels.json | 74 ++++ scripts/create_release.py | 4 +- setup.py | 6 +- 17 files changed, 942 insertions(+), 31 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.zh-Hans.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.zh-Hans.md create mode 100644 CHANGELOG.md create mode 100644 README.md create mode 100644 docs/CHANGELOG.zh-Hans.md create mode 100644 docs/README.zh-Hans.md create mode 100644 docs/issue_labels.json diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..14990c9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,39 @@ +--- +name: 'Bug report' +about: 'Create a report to help us improve' +title: '' +labels: 'Status: Review Needed' +assignees: '' + +--- + +**Make sure you have read the readme, searched and read the issues related to yours. Otherwise it will be considered as a duplicate which will be closed immediately.** + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: + +1. Command line arguments you are using. +2. A complete copy of command line output of the delethon. You can use `Ctrl-A` and `Ctrl-C` to copy all of them. Use the following markdown code block syntax is recommended. Copy them into the place between \`\`\`. + +``` +``` + +3. etc. + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. But it is not recommended using screenshots to demonstrate the commandline output unless you think it really matters. + +**Environment (please complete the following information):** + +- OS: [e.g. windows] +- Python Version: [e.g. Python 3.7] +- Delethon Version: [e.g. 0.4.1-alpha/0.5.4-alpha Nuitka windows release] + +**Additional context** (Optional) +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/bug_report.zh-Hans.md b/.github/ISSUE_TEMPLATE/bug_report.zh-Hans.md new file mode 100644 index 0000000..492d618 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.zh-Hans.md @@ -0,0 +1,39 @@ +--- +name: '问题反馈' +about: '报告问题' +title: '' +labels: 'Status: Review Needed' +assignees: '' + +--- + +**确保你已经看过 readme,也搜索并阅读过和你遇到的情况相关的问题。否则会被认为是重复的并被立刻关闭。** + +**描述问题** +清晰并准确地描述问题。 + +**复现问题** +复现问题的步骤: + +1. 你使用的命令行参数。 +2. 一份完整的delethon命令行输出。你可以使用`Ctrl-A`和`Ctrl-C`去复制所有输出。推荐使用以下的代码块markdown语法,将代码块复制到\`\`\`和\`\`\`之间即可。 + +``` +``` + +3. 等等 + +**期待的行为** +清晰并准确地描述你本想做的事情。 + +**截图** +合适的话可以提供用以描述问题的截图。但是不推荐用截图来展示命令行输出,除非你真的认为这很有必要。 + +**操作环境(请提供以下完整数据):** + +- 操作系统: [譬如 windows] +- Python版本: [譬如 Python 3.7] +- Delethon版本: [譬如 0.4.1-alpha或0.5.4-alpha Nuitka windows发布版] + +**额外信息**(可选) +任何其他的能描述问题的信息。 diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..704f530 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,22 @@ +--- +name: 'Feature request' +about: 'Suggest an idea for this project' +title: '' +labels: 'Status: Review Needed' +assignees: '' + +--- + +**Make sure you have read the readme, searched and read the issues related to yours. Otherwise it will be considered as a duplicate which will be closed immediately.** + +**Is your feature request related to a problem? Please describe.** (Optional) +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** (Optional) +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** (Optional) +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.zh-Hans.md b/.github/ISSUE_TEMPLATE/feature_request.zh-Hans.md new file mode 100644 index 0000000..dbe23c5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.zh-Hans.md @@ -0,0 +1,22 @@ +--- +name: '功能请求' +about: '新功能建议' +title: '' +labels: 'Status: Review Needed' +assignees: '' + +--- + +**确保你已经看过 readme,也搜索并阅读过和你遇到的情况相关的问题。否则会被认为是重复的并被立刻关闭。** + +**描述与这个功能请求有关的某一问题**(可选) +清晰并准确地描述这个问题。 + +**描述你期待的解决方案** +清晰并准确地描述你的解决方案。 + +**描述你考虑过的替代方案**(可选) +清晰并准确地描述类似功能的替代方案。 + +**额外的信息**(可选) +任何其他的能描述功能请求的信息。 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7a50b91 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,31 @@ +## Changelog + +[简体中文](docs/CHANGELOG.zh-Hans.md) + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## TOC + +- [Unreleased](#unreleased) + - [Added](#addedunreleased) + - [Changed](#changedunreleased) +- [0.1.0-alpha - 2020-03-11](#010-alpha---2020-03-11) + - [Added](#added040-alpha) + +Click up arrow to go back to TOC. + +### [Unreleased] + +### [0.1.0-alpha] - 2020-03-11 + +#### Added(0.1.0-alpha) + +- Add basic messages deleting functions. + + ↑  + +[Unreleased]: https://github.com/BingLingGroup/autosub/compare/0.1.0-alpha...HEAD +[0.1.0-alpha]: https://github.com/BingLingGroup/autosub/releases/tag/0.1.0-alpha diff --git a/README.md b/README.md new file mode 100644 index 0000000..858c098 --- /dev/null +++ b/README.md @@ -0,0 +1,340 @@ +# Delethon + + + +[简体中文](docs/README.zh-Hans.md) + +[更新日志](CHANGELOG.md). + + + +图标字体: [source-han-serif](https://source.typekit.com/source-han-serif/) ([OFL 1.1](https://github.com/adobe-fonts/source-han-serif/blob/master/LICENSE.txt)) + +### TOC + +1. [Description](#description) +2. [License](#license) +3. [Dependencies](#dependencies) +4. [Download and Installation](#download-and-installation) + - 4.1 [Branches](#branches) + - 4.2 [Install on Ubuntu](#install-on-ubuntu) + - 4.3 [Install on Windows](#install-on-windows) +5. [Usage](#usage) + - 6.1 [Typical usage](#typical-usage) + - 6.2 [Options](#Options) + - 6.3 [Internationalization](#internationalization) +6. [Bugs report](#bugs-report) +7. [Build](#build) + +Click up arrow to go back to TOC. + +### Description + +Delete Telegram messages based on Telethon. + +It can do: + +- [x] Delete the messages of the logged in user for all members in group chats. +- [x] Delete certain types of the messages. +- [x] Print instead of deleting the messages. + +It can not do: + +- [ ] Delete the messages that's been cached or exported to the local storage. +- [ ] Delete the messages in group's recent actions. +- [ ] Delete other people's messages for all in group chats unless you have the admin rights of the group. + +### License + +[GPLv3](LICENSE) + +### Dependencies + +[requirements.txt](requirements.txt) + +Python >= 3.5 + +### Download and Installation + +About the git installation. If you don't want to install git to use pip [VCS](https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support) support to install python package or just confused with git environment variables, you can manually click that clone and download button to download the source code and use pip to install the source code [locally](https://pip.pypa.io/en/stable/reference/pip_install/#description) by input these commands. + +```batch +cd the_directory_contains_the_source_code +pip install . +``` + +#### Branches + +[master branch](https://github.com/BingLingGroup/delethon/tree/master) + +- Codes will be updated when a new version releases. + +[dev branch](https://github.com/BingLingGroup/delethon/tree/dev) + +- The latest codes will be pushed to this branch. It will be merged to master branch when new version released. + + ↑  + +#### Install on Ubuntu + +Include dependencies installation commands. + +Install from `master` branch. + +```bash +apt install python3 python-pip3 git -y +pip3 install git+https://github.com/BingLingGroup/delethon.git@master +``` + + ↑  + +#### Install on Windows + +You can just go to the [release page](https://github.com/BingLingGroup/delethon/releases) and download the latest release for Windows. The click-and-run batches are also in the package. You can manually edit by using Notepad++. Or add the executable files' directory to system environment variables so you can use it as a universal command everywhere in the system if permission is Ok. + +Tips: `Shift - Right Click` is the keyboard shortcut for opening a Powershell on current directory. To open an exe at current directory, the format is like `.\delethon`. + +Or install Python environment(if you still don't have one) from [choco](https://chocolatey.org) and then install the package. + +Choco installation command is for cmd.(not Powershell) + +```batch +@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" +``` + +Install from `master` branch. + +```batch +choco install git python curl -y +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py +python get-pip.py +pip install git+https://github.com/BingLingGroup/delethon.git@master +``` + + ↑  + +### Usage + +You need to get the `api_id` and `api_hash` from [Telegram app](https://my.telegram.org/apps) to log in. Remember not to post these codes anywhere or give them to anyone. + +If the user is logged in for the first time or the session file is not ready, it will ask for a login authentication just like other Telegram clients. + +Typical usages for delethon instead of other Telegram clients: + +- Delete all messages of the logged in user in group chats instead of asking their admin's for help. +- Delete all messages of the group chats on schedule if the logged in user is the admin of some group chats. + +Log in behind local `SOCKS5` proxy `127.0.0.1:1080` + +``` +delethon -pt ...(other options) +``` + +Delete all messages of logged in user in some chats. + +``` +delethon -ai api_id -ah api_hash -c "chat_1" "chat_2" -m ...(other options) +``` + +Delete quietly. + +``` +delethon -ll 0 ...(other options) +``` + +Delete text messages only. (But won't delete those photo messages with caption) + +``` +delethon -fs empty ...(other options) +``` + + ↑  + +#### Options + +Full list of the help message. + +``` +$ delethon -h +usage: + delethon [options] + +Delete Telegram messages based on Telethon. + +Client Options: + Options to start a Telethon client. + + -ai API_ID, --api-id API_ID + Telegram app api_id. Input it or set the environment + variable "TELEGRAM_API_ID". You can get one from + https://my.telegram.org/apps (arg_num = 1) (default: + None) + -ah API_HASH, --api-hash API_HASH + Telegram app api_hash. Input it or set the environment + variable "TELEGRAM_API_HASH". You can get one from + https://my.telegram.org/apps (arg_num = 1) (default: + None) + -sf path, --session-file path + Telegram session file path. Ref: https://docs.telethon + .dev/en/latest/concepts/sessions.html (arg_num = 1) + (default: Telethon) + +Proxy Options: + Options to use Telethon behind a proxy. + + -pt [proxy_type], --proxy-type [proxy_type] + PySocks or MTProto Proxy. Available types: "SOCKS5", + "SOCKS4", "HTTP", "MTPROTO". When using "MTPROTO", its + type is "ConnectionTcpMTProxyRandomizedIntermediate". + If environment variable "HTTP_PROXY" exists and this + option is not used, it will use it. Ref: + https://docs.telethon.dev/en/latest/basic/signing- + in.html#signing-in-behind-a-proxy If arg_num is 0, use + const type. (arg_num = 0 or 1) (const: SOCKS5) + -pa address, --proxy-address address + The IP address or DNS name of the proxy server. + (arg_num = 1) (default: 127.0.0.1) + -pp port, --proxy-port port + The port of the proxy server. (arg_num = 1) (default: + 1080) + -pu username, --proxy-username username + Set proxy username. (arg_num = 1) + -ps password, --proxy-password password + Set proxy password. When using "MTPROTO", this option + is "secret" instead. (arg_num = 1) + +Iterate Messages Options: + Options to control Telethon iter_messages method. Ref: https://docs.telethon.dev/en/latest/modules/client.html#telethon.client.messages.MessageMethods.iter_messages + + -c [entity_like [entity_like ...]], --chats [entity_like [entity_like ...]] + Get the messages in the chat entity/entities. + entity_like can be Telegram username, Group name and + so on. If failed to get one, it will use it to match + the entity name or id of the dialogs which the user + joined. Ref: https://docs.telethon.dev/en/latest/conce + pts/entities.html#getting-entities(arg_num >= 1) + -u [entity_like [entity_like ...]], --users [entity_like [entity_like ...]] + Get the messages from the user entity/entities. If not + input, gets all users messages. Ref: https://docs.tele + thon.dev/en/latest/concepts/entities.html#getting- + entities(arg_num >= 1) + -m, --me Get messages from the current user who is logged in. + (arg_num = 0) + -ac, --all-chats Iterate over all the chat entity/entities that the + current user joined. (arg_num = 0) + -l int, --limit int Number of messages to be retrieved. Slower when more + than 3000. Ref: https://docs.telethon.dev/en/latest/mo + dules/client.html#telethon.client.messages.MessageMeth + ods.iter_messages (arg_num = 1) (default: unlimited) + -ofd int, --offset-day int + Offset day (messages previous to this day will be + retrieved). Exclusive. (arg_num = 1) + -ofi int, --offset-id int + Offset message ID (only messages previous to the given + ID will be retrieved). Exclusive. (arg_num = 1) + -mxi int, --max-id int + All the messages with a higher (newer) ID or equal to + this will be excluded. (arg_num = 1) + -mni int, --min-id int + All the messages with a lower (older) ID or equal to + this will be excluded. (arg_num = 1) + -aof int, --add-offset int + Additional message offset (all of the specified + offsets + this offset = older messages). (arg_num = 1) + -s str, --search str The string to be used as a search query. Give the same + result as other Telegram official clients meaning it's + not optimized for some non-English languages. (arg_num + = 1) + -f type, --filter type + The filter to use before returning messages. For + instance, "photos" for "InputMessagesFilterPhotos" + would yield only messages containing photos. When + using "empty" filter, you must give option "--search". + Available MessagesFilters: chatphotos, contacts, + document, empty, geo, gif, music, mentions, + phonecalls, photovideo, photos, roundvideo, + roundvoice, url, video, voice (arg_num = 1) + -wt int, --wait-time int + Wait time (in seconds) between different + GetHistoryRequest. Use this parameter to avoid hitting + the FloodWaitError as needed. If left to None, it will + default to 1 second only if the limit is higher than + 3000. If the ids parameter is used, this time will + default to 10 seconds only if the amount of IDs is + higher than 300. (arg_num = 1) + -ids [int [int ...]], --ids [int [int ...]] + A single integer ID (or several IDs) for the message + that should be returned. This parameter takes + precedence over the rest (which will be ignored if + this is set). This can for instance be used to get the + message with ID 123 from a channel. Note that if the + message doesn't exist, None will appear in its place, + so that zipping the list of IDs with the messages can + match one-to-one. (arg_num >= 1) + -r, --reverse The messages will be returned in reverse order (from + oldest to newest, instead of the default newest to + oldest). This also means that the meaning of "-- + offset-id" and "--offset-day" parameters is reversed, + although they will still be exclusive. "--min-id" + becomes equivalent to "--offset-id" instead of being " + --max-id" as well since messages are returned in + ascending order. (arg_num = 0) + +Process Options: + Options to determine how to process the messages after retrieving them. + + -op, --only-print Only print message instead of deleting them. (arg_num + = 0) + -fs [type [type ...]], --filters [type [type ...]] + The filters to use after returning the messages from + "iter_messages". So using it will delete equal to or + less amount of messages than the argument set to "-- + limit". It run slower than option "--filter", but + supports multiple filters. And it support "empty" type + without input "--search". Available MessageMedia + filters: contact, document, empty, game, geo, geolive, + invoice, photo, poll, unsupported, venue, webpage Ref: + https://tl.telethon.dev/types/message_media.html(arg_n + um >= 1) + +Information Options: + Options to get extra information. + + -ll int, --log-level int + Print different kinds of messages. 0 for nothing. 1 + for basic. 2 for more content. (arg_num = 1) (default: + 2) + -h, --help Show delethon help message and exit. (arg_num = 0) + -v, --version Show delethon version and exit. (arg_num = 0) + +Make sure the argument with space is in quotes. +The default value is used +when the option is not given at the command line. +"(arg_num)" means if the option is given, +the number of the arguments is required. +Author: Bing Ling +Email: binglinggroup@outlook.com +Bug report: https://github.com/BingLingGroup/delethon +``` + + ↑  + +#### Internationalization + +Delethon supports multi-language command line user interface by [GNU gettext](https://www.gnu.org/software/gettext/). Now supports `zh_CN` and default `en_US`. More info about this [lang codes format](https://www.gnu.org/software/gettext/manual/gettext.html#Locale-Names). The program will automatically detect the os locale and use the one supported. For windows 10, it seems adjusting the `Region`-`Regional format` is Ok. + +Of course, delethon offers a method to override the os locale. Just create a txt file without extension named `locale`, containing the lang codes at the beginning of the file, at the command line current working directory. When delethon starts, it will detect this file and read the lang code inside it and apply it if supported. + +If you want to translate this program into other languages, first install the gettext utilities. Then you can run `python scripts/update_po_files.py lang_code` to create the locale files which you want to translate into. And then use [POEditor](https://poeditor.com/) to edit po files. [update_po_files.py](scripts/update_po_files.py) can also automatically merge the position info into the old po files and compile the po files into mo files which the program read them. So it's useful when the codes changed, you can merge the positional changes into the translations automatically. + + ↑  + +### Bugs report + +Bugs and suggestions can be reported at [issues](https://github.com/BingLingGroup/delethon/issues). + +### Build + +Current windows build is built by [pyinstaller script](scripts/pyinstaller_build.bat). + +[create_release.py](scripts/create_release.py) is used to make the release package. diff --git a/delethon/__init__.py b/delethon/__init__.py index 6a4ddd6..e9964ff 100644 --- a/delethon/__init__.py +++ b/delethon/__init__.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines delethon's commandline entry point functionality. diff --git a/delethon/__main__.py b/delethon/__main__.py index 27a887c..2696483 100644 --- a/delethon/__main__.py +++ b/delethon/__main__.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines delethon's entry point. diff --git a/delethon/constants.py b/delethon/constants.py index 782e0d7..dea101d 100644 --- a/delethon/constants.py +++ b/delethon/constants.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines constants used by delethon. diff --git a/delethon/data/locale/zh_CN/LC_MESSAGES/delethon.options.po b/delethon/data/locale/zh_CN/LC_MESSAGES/delethon.options.po index b828393..579a06d 100644 --- a/delethon/data/locale/zh_CN/LC_MESSAGES/delethon.options.po +++ b/delethon/data/locale/zh_CN/LC_MESSAGES/delethon.options.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-09 18:05+0800\n" -"PO-Revision-Date: 2020-03-09 18:06+0800\n" +"POT-Creation-Date: 2020-03-11 12:19+0800\n" +"PO-Revision-Date: 2020-03-11 12:20+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -228,7 +228,7 @@ msgstr "获得当前登录用户参加的所有对话实体。(参数个数为 #: delethon/options.py:202 delethon/options.py:213 delethon/options.py:222 #: delethon/options.py:233 delethon/options.py:243 delethon/options.py:253 -#: delethon/options.py:285 delethon/options.py:299 delethon/options.py:347 +#: delethon/options.py:285 delethon/options.py:299 delethon/options.py:349 msgid "int" msgstr "整数" @@ -351,31 +351,39 @@ msgstr "只在屏幕上输出消息而非删除他们。(参数个数为0)" #: delethon/options.py:335 msgid "" -"The filters to use after returning the messages from \"iter_messages\". It " -"run slower than option \"--filter\", but supports multiple filters. And it " -"support \"empty\" type without input \"--search\". Available MessageMedia " -"filters: contact, document, empty, game, geo, geolive, invoice, photo, poll, " -"unsupported, venue, webpage Ref: https://tl.telethon.dev/types/message_media." -"html(arg_num >= 1)" +"The filters to use after returning the messages from \"iter_messages\". So " +"using it will delete equal to or less amount of messages than the argument " +"set to \"--limit\". It run slower than option \"--filter\", but supports " +"multiple filters. And it support \"empty\" type without input \"--search\". " +"Available MessageMedia filters: contact, document, empty, game, geo, " +"geolive, invoice, photo, poll, unsupported, venue, webpage Ref: https://tl." +"telethon.dev/types/message_media.html(arg_num >= 1)" msgstr "" -"在从\"iter_message\"方法取回消息后进行筛选的分类器。会比选项\"--filter\"更" -"慢,但支持多个分类同时输入。同时在输入\"empty\"类时不需要输入\"--search\"选" -"项。可用的MessageMedia分类器:contact, document, empty, game, geo, geolive, " -"invoice, photo, poll, unsupported, venue, webpage 参考:https://tl.telethon." -"dev/types/message_media.html(参数个数大于等于1)" - -#: delethon/options.py:351 +"在从\"iter_message\"方法取回消息后进行筛选的分类器。所以使用它会删除小于等于" +"\"--limit\"选项提供的消息数量。会比选项\"--filter\"更慢,但支持多个分类同时输" +"入。同时在输入\"empty\"类时不需要输入\"--search\"选项。可用的MessageMedia分类" +"器:contact, document, empty, game, geo, geolive, invoice, photo, poll, " +"unsupported, venue, webpage 参考:https://tl.telethon.dev/types/" +"message_media.html(参数个数大于等于1)" + +#: delethon/options.py:353 +#, python-format msgid "" "Print different kinds of messages. 0 for nothing. 1 for basic. 2 for more " -"content. (arg_num = 1)" +"content. (arg_num = 1) (default: %(default)s)" msgstr "" "在屏幕上输出不同类别的消息。0为不输出。1为基本信息。2则是更多的信息。(参数个" -"数为1)" +"数为1)(默认参数为%(default)s)" -#: delethon/options.py:357 +#: delethon/options.py:360 #, python-format msgid "Show %(prog)s help message and exit. (arg_num = 0)" msgstr "显示%(prog)s的帮助信息并退出。(参数个数为0)" +#: delethon/options.py:368 +#, python-format +msgid "Show %(prog)s version and exit. (arg_num = 0)" +msgstr "显示%(prog)s的版本信息并退出。(参数个数为0)" + #~ msgid "Operation Options" #~ msgstr "操作选项" diff --git a/delethon/metadata.py b/delethon/metadata.py index 76c1b7a..677bf99 100644 --- a/delethon/metadata.py +++ b/delethon/metadata.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines delethon's metadata. diff --git a/delethon/options.py b/delethon/options.py index f56254b..6acf409 100644 --- a/delethon/options.py +++ b/delethon/options.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines delethon's options. @@ -69,7 +69,7 @@ def get_cmd_args(): '/client.html#telethon.client.messages.MessageMethods.iter_messages') ) - operation_group = parser.add_argument_group( + process_group = parser.add_argument_group( _('Process Options'), _('Options to determine how to process the messages after retrieving them.') ) @@ -322,17 +322,19 @@ def get_cmd_args(): "well since messages are returned in ascending order. " "(arg_num = 0)")) - operation_group.add_argument( + process_group.add_argument( '-op', '--only-print', action='store_true', help=_("Only print message instead of deleting them. " "(arg_num = 0)")) - operation_group.add_argument( + process_group.add_argument( '-fs', '--filters', nargs='*', metavar=_('type'), help=_("The filters to use after returning the messages from \"iter_messages\". " + "So using it will delete equal to or less amount of messages than " + "the argument set to \"--limit\". " "It run slower than option \"--filter\", but supports multiple filters. " "And it support \"empty\" type without input \"--search\". " "Available MessageMedia filters: contact, document, empty, " @@ -349,11 +351,20 @@ def get_cmd_args(): default=2, choices=range(1, 3), help=_("Print different kinds of messages. " - "0 for nothing. 1 for basic. 2 for more content. (arg_num = 1)")) + "0 for nothing. 1 for basic. 2 for more content." + " (arg_num = 1) (default: %(default)s)")) info_group.add_argument( '-h', '--help', action='help', help=_("Show %(prog)s help message and exit. (arg_num = 0)")) + info_group.add_argument( + '-v', '--version', + action='version', + version='%(prog)s ' + metadata.VERSION + + ' by ' + metadata.AUTHOR + ' <' + + metadata.AUTHOR_EMAIL + '>', + help=_("Show %(prog)s version and exit. (arg_num = 0)")) + return parser.parse_args() diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md new file mode 100644 index 0000000..7a50b91 --- /dev/null +++ b/docs/CHANGELOG.zh-Hans.md @@ -0,0 +1,31 @@ +## Changelog + +[简体中文](docs/CHANGELOG.zh-Hans.md) + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## TOC + +- [Unreleased](#unreleased) + - [Added](#addedunreleased) + - [Changed](#changedunreleased) +- [0.1.0-alpha - 2020-03-11](#010-alpha---2020-03-11) + - [Added](#added040-alpha) + +Click up arrow to go back to TOC. + +### [Unreleased] + +### [0.1.0-alpha] - 2020-03-11 + +#### Added(0.1.0-alpha) + +- Add basic messages deleting functions. + + ↑  + +[Unreleased]: https://github.com/BingLingGroup/autosub/compare/0.1.0-alpha...HEAD +[0.1.0-alpha]: https://github.com/BingLingGroup/autosub/releases/tag/0.1.0-alpha diff --git a/docs/README.zh-Hans.md b/docs/README.zh-Hans.md new file mode 100644 index 0000000..0e90956 --- /dev/null +++ b/docs/README.zh-Hans.md @@ -0,0 +1,290 @@ +# Delethon + + + +[English](../README.md) + +[更新日志](../CHANGELOG.md). + + + +图标字体: [source-han-serif](https://source.typekit.com/source-han-serif/) ([OFL 1.1](https://github.com/adobe-fonts/source-han-serif/blob/master/LICENSE.txt)) + +### 目录 + +1. [介绍](#介绍) +2. [证书](#证书) +3. [依赖](#依赖) +4. [下载和安装](#下载和安装) + - 4.1 [分支](#分支) + - 4.2 [在Ubuntu安装](#在ubuntu安装) + - 4.3 [在Windows安装](#在windows安装) +5. [用法](#用法) + - 6.1 [典型用法](#典型用法) + - 6.2 [选项](#选项) + - 6.3 [国际化](#国际化) +6. [问题报告](#问题报告) +7. [构建](#构建) + +点击上箭头以返回目录。 + +### 介绍 + +基于Telethon删除Telegram消息。 + +它能做到: + +- [x] 删除登录用户在群聊的消息,删除后所有人不可见。 +- [x] 删除特定种类的消息。 +- [x] 打印而不是删除消息。 + +它不能做到: + +- [ ] 删除已被缓存或者导出到本地的消息。 +- [ ] 删除群组最近活动中的消息。 +- [ ] 删除群组中其他人的消息,除非你有群组管理员权限。 + +### 证书 + +[GPLv3](../LICENSE) + +### 依赖 + +[requirements.txt](../requirements.txt) + +Python >= 3.5 + +### 下载和安装 + +至于git的安装,如果你不想通过pip的[VCS](https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support)支持来安装python包或者只是不想碰git的环境变量这些东西,你可以手动点击clone and download来下载源码并在[本地](https://pip.pypa.io/en/stable/reference/pip_install/#description)进行安装。指令如下。 + +```batch +cd the_directory_contains_the_source_code +pip install . +``` + +#### 分支 + +[master分支](https://github.com/BingLingGroup/delethon/tree/master) + +- 代码会在新版本发布时更新。 + +[dev分支](https://github.com/BingLingGroup/delethon/tree/dev) + +- 最新的代码会推送到这个分支。如果有新版本发布,会被合并到master分支。 + + ↑  + +#### 在Ubuntu安装 + +包括依赖安装指令。 + +从`master`分支安装。 + +```bash +apt install python3 python-pip3 git -y +pip3 install git+https://github.com/BingLingGroup/delethon.git@master +``` + + ↑  + +#### 在Windows安装 + +你可以直接去[发布页](https://github.com/BingLingGroup/delethon/releases)下载Windows的最新发布版。包内自带懒人批处理。你可以使用Notepad++对其进行手动修改。或者把含有exe的目录放到系统环境变量里,这样你就可以在别的目录也使用delethon了,前提是那个目录没有权限限制。 + +建议:`Shift - 右键`是打开当前目录Powershell的快捷键。Powershell打开当前目录的exe需要输入这样的格式`.\delethon`。 + +或者通过[choco](https://chocolatey.org)来安装Python环境(如果你还没有),然后安装这个包。 + +命令行安装choco的指令如下。(不是Powershell) + +```batch +@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" +``` + +从`master`分支安装。 + +```batch +choco install git python curl -y +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py +python get-pip.py +pip install git+https://github.com/BingLingGroup/delethon.git@master +``` + + ↑  + +### Usage + +你需要从[Telegram app](https://my.telegram.org/apps)中获得`api_id`和`api_hash`来登录。记得不要把这些编号发出去或者透露给任何人。 + +如果用户是第一次登录,或者会话文件尚不存在,程序会请求登录验证,和其他Telegram客户端一样。 + +不使用其他Telegram客户端,而使用delethon的几个典型场景: + +- 删除已登录用户在群组中的所有记录,而不是要求群组管理员协助删除。 +- 如果已登录用户是群组管理员,可以让其定时删除所有群组聊天记录。 + +使用本地`SOCKS5`代理`127.0.0.1:1080`登录。 + +``` +delethon -pt ...(其他选项) +``` + +删除某些聊天中已登录用户的消息。 + +``` +delethon -ai api_id -ah api_hash -c "聊天1" "聊天2" -m ...(其他选项) +``` + +安静地删除。 + +``` +delethon -ll 0 ...(其他选项) +``` + +只删除文字消息。(但不包括含文字的照片消息) + +``` +delethon -fs empty ...(其他选项) +``` + + ↑  + +#### 选项 + +帮助信息的完整清单。 + +``` +$ delethon -h +usage: + 用法:delethon [选项] + +基于Telethon删除Telegram消息。 + +客户端选项: + 用于启动Telethon客户端的选项。 + + -ai API_ID, --api-id API_ID + Telegram应用api_id。输入它或者设置环境变量“TELEGRAM_API_ID”。你能从https + ://my.telegram.org/apps中获得一个。(参数个数为1)(默认参数为None) + -ah API_HASH, --api-hash API_HASH + Telegram应用api_hash。输入它或者设置环境变量“TELEGRAM_API_HASH”。你能从h + ttps://my.telegram.org/apps中获得一个。(参数个数为1)(默认参数为None) + -sf 路径, --session-file 路径 + Telegram会话文件路径。参考:https://docs.telethon.dev/en/latest/ + concepts/sessions.html(参数个数为1)(默认参数为Telethon) + +代理选项: + 让Telethon使用代理服务器的选项。 + + -pt [代理类型], --proxy-type [代理类型] + PySocks或者MTProto代理。可用类型:"SOCKS5", "SOCKS4", "HTTP", "M + TPROTO"。使用"MTPROTO"时,其类型为"ConnectionTcpMTProxyRandomiz + edIntermediate"。如果环境变量"HTTP_PROXY"存在,而这个选项没有使用,程序就会用它。 + 参考:https://docs.telethon.dev/en/latest/basic/signing- + in.html#signing-in-behind-a-proxy + 如果参数个数是0,使用const类型。(参数个数为0或1)(const为SOCKS5) + -pa 地址, --proxy-address 地址 + IP地址或者代理服务器的DNS名称。(参数个数为1)(默认参数为127.0.0.1) + -pp 端口, --proxy-port 端口 + 代理服务器的端口。(参数个数为1)(默认参数为1080) + -pu 用户名, --proxy-username 用户名 + 设置代理用户名。(参数个数为1) + -ps 密码, --proxy-password 密码 + 设置代理密码。如果使用"MTPROTO",这个参数则会代表"secret"。(参数个数为1) + +迭代消息选项: + 用于控制Telethon iter_messages方法的选项。参考:https://docs.telethon.dev/en/latest/modules/client.html#telethon.client.messages.MessageMethods.iter_messages + + -c [实体类 [实体类 ...]], --chats [实体类 [实体类 ...]] + 从单个对话实体或多个对话实体中获取消息。实体类可以是Telegram用户名,群名等等。如果无法得到,程序会使 + 用此选项去匹配用户已经加入的对话的实体名称或者id。参考:https://docs.telethon.dev + /en/latest/concepts/entities.html#getting- + entities(参数个数大于等于1) + -u [实体类 [实体类 ...]], --users [实体类 [实体类 ...]] + 从单个用户实体或多个用户实体获得消息。如果没有输入,会获取所有用户的消息。参考https://docs.te + lethon.dev/en/latest/concepts/entities.html#getting- + entities(参数个数大于等于1) + -m, --me 获取当前登录用户发送的消息。(参数个数为0) + -ac, --all-chats 获得当前登录用户参加的所有对话实体。(参数个数为0) + -l 整数, --limit 整数 需要取回的消息数量。超过3000时会变慢。参考:https://docs.telethon.dev/en/l + atest/modules/client.html#telethon.client.messages.Mes + sageMethods.iter_messages (参数个数为1)(默认不限制数量) + -ofd 整数, --offset-day 整数 + 偏移日期(比这天早的消息会被取回)。独占性。(参数个数为1) + -ofi 整数, --offset-id 整数 + 偏移消息ID(只有比这个ID更早的消息才会被取回)。独占性。(参数个数为1) + -mxi 整数, --max-id 整数 所有比这个ID数值更高也就是更新的消息会被排除。(参数个数为1) + -mni 整数, --min-id 整数 所有比这个ID数值更小也就是更旧的消息会被排除。(参数个数为1) + -aof 整数, --add-offset 整数 + 额外消息偏移(所有制ID那个的偏移加上这个偏移=更旧的消息)。(参数个数为1) + -s 字符串, --search 字符串 用来搜索的字符串。和其他Telegram官方客户端得到的搜索结果一样,意味着对部分非英语语言未做优化。(参数 + 个数为1) + -f 类型, --filter 类型 在取回消息前进行筛选的分类器。譬如,输入"photos"等同于"InputMessagesFilterPho + tos"将会只产生含图片的消息。使用"empty"筛选时,你必须提供"-s"选项。可用消息筛选类型:chat + photos, contacts, document, empty, geo, gif, music, + mentions, phonecalls, photovideo, photos, roundvideo, + roundvoice, url, video, voice(参数个数为1) + -wt 整数, --wait-time 整数 + 在不同的GetHistoryRequest之间的等待时间(单位为秒)。使用这个选项来避免达到FloodWai + tError。如果不输入,超过3000个消息时的等待默认为1秒。如果id参数使用了,id超过300时,这个时 + 间将被设置为10秒。(参数个数为1) + -ids [整数 [整数 ...]], --ids [整数 [整数 ...]] + 会被取回的单个或多个消息ID。这个参数优先于其他参数。譬如可用于取得频道里第123条消息。注意如果消 息不存在 + ,会返回None,所以将包含ID的列表压缩在一起能得到一对一的结果。(参数个数大于等于1) + -r, --reverse 消息会倒序返回(从最旧的到最新的,而不是默认最新的到最旧的)。这也意味着选项"--offset-id"和" + --offset-day"中的参数也被反转了,尽管他们仍然是独占性的。 同样地,"--min-id"等效于" + --offset-id"而非"--max-id"因为消息会按照升序返回。(参数个数为0) + +处理选项: + 在取回消息后决定如何处理消息的选项。 + + -op, --only-print 只在屏幕上输出消息而非删除他们。(参数个数为0) + -fs [类型 [类型 ...]], --filters [类型 [类型 ...]] + 在从"iter_message"方法取回消息后进行筛选的分类器。所以使用它会删除小于等于"-- + limit"选项提供的消息数量。会比选项"-- + filter"更慢,但支持多个分类同时输入。同时在输入"empty"类时不需要输入"-- + search"选项。可用的MessageMedia分类器:contact, document, empty, + game, geo, geolive, invoice, photo, poll, unsupported, + venue, webpage 参考:https://tl.telethon.dev/types/messag + e_media.html(参数个数大于等于1) + +信息选项: + 用于获取额外信息的选项。 + + -ll 整数, --log-level 整数 + 在屏幕上输出不同类别的消息。0为不输出。1为基本信息。2则是更多的信息。(参数个数为1)(默认参数为2) + -h, --help 显示delethon的帮助信息并退出。(参数个数为0) + -v, --version 显示delethon的版本信息并退出。(参数个数为0) + +确保有空格的参数被引号包围。 +默认参数指的是, +如果选项没有在命令行中提供时会使用的参数。 +"参数个数"指的是如果提供了选项, +该选项所需要的参数个数。 +作者: Bing Ling +Email: binglinggroup@outlook.com +问题反馈: https://github.com/BingLingGroup/delethon +``` + + ↑  + +#### 国际化 + +Delethon通过[GNU gettext](https://www.gnu.org/software/gettext/)支持多语言命令行界面。现在支持`zh_CN`和`en_US`。关于这种语言代码的格式可见[此文档](https://www.gnu.org/software/gettext/manual/gettext.html#Locale-Names)。程序会自动检测操作系统的语言,并选择其支持的语言。对于windows 10而言,只要修改`区域`-`区域格式`即可。 + +当然,delethon提供了不依靠操作系统语言来加载语言的方法。只要创建一个txt文件,去掉它的文件扩展名,命名为`locale`,在文件开头的位置输入语言代码,同时该文件放在运行delethon命令行的目录,delethon就会自动检测并读取这个文件里的语言代码,如果支持就会自动加载该语言。 + +如果你想把这个程序翻译成别的语言,首先安装gettext工具。然后你可以运行`python scripts/update_po_files.py lang_code`来创建你要翻译的语言文件。然后使用[POEditor](https://poeditor.com/)来编辑po文件。[update_po_files.py](../scripts/update_po_files.py)也可以自动合并位置信息到旧的po文件,并将po文件编译成程序使用的mo文件。所以如果代码改变时,你可以通过这个脚本,自动地将位置信息变化合并到翻译中。 + + ↑  + +### 问题反馈 + +问题和建议可以反馈在[issues](https://github.com/BingLingGroup/delethon/issues)。 + +### 构建 + +当前的windows构建由[pyinstaller脚本](../scripts/pyinstaller_build.bat)制作。 + +[create_release.py](../scripts/create_release.py)被用于制作发布包。 diff --git a/docs/issue_labels.json b/docs/issue_labels.json new file mode 100644 index 0000000..5c2dfa7 --- /dev/null +++ b/docs/issue_labels.json @@ -0,0 +1,74 @@ +[ + { + "name": "Priority: Critical", + "color": "#F48FB1" + }, + { + "name": "Priority: High", + "color": "#EF9A9A" + }, + { + "name": "Priority: Low", + "color": "#9FA8DA" + }, + { + "name": "Priority: Medium", + "color": "#CE93D8" + }, + { + "name": "Status: Abandoned", + "color": "#BCAAA4" + }, + { + "name": "Status: Accepted", + "color": "#a5d6a7" + }, + { + "name": "Status: Blocked", + "color": "#B0BEC5" + }, + { + "name": "Status: Completed", + "color": "#FDF6E3" + }, + { + "name": "Status: In Progress", + "color": "#EEE8D5" + }, + { + "name": "Status: Review Needed", + "color": "#FFF59D" + }, + { + "name": "Type: Bug", + "color": "#FF6E40" + }, + { + "name": "Type: Duplicated", + "color": "#B0BEC5" + }, + { + "name": "Type: Enhancement", + "color": "#80DEEA" + }, + { + "name": "Type: Help Wanted", + "color": "#FFE082" + }, + { + "name": "Type: Invalid", + "color": "#B0BEC5" + }, + { + "name": "Type: Maintenance", + "color": "#80cbc4" + }, + { + "name": "Type: Pin", + "color": "#00b0ff" + }, + { + "name": "Type: Question", + "color": "#E6EE9C" + } +] \ No newline at end of file diff --git a/scripts/create_release.py b/scripts/create_release.py index 1e2f297..d39d69a 100644 --- a/scripts/create_release.py +++ b/scripts/create_release.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines release creation scripts. @@ -115,7 +115,7 @@ def copytree(src, os.makedirs(target_data_pyi) copytree(src="{}/data".format(package_name), dst=target_data, exts=[".mo"], is_recursive=True) copytree(src="{}/data".format(package_name), dst=target_data_pyi, exts=[".mo"], is_recursive=True) - copytree(src=".build_and_dist/{}.dist".format(release_name), dst=target_nuitka, is_recursive=True) + # copytree(src=".build_and_dist/{}.dist".format(release_name), dst=target_nuitka, is_recursive=True) # command = "7z a -sdel \".release/{release_name}-{version}-win-x64-nuitka.7z\" \"{target}\"".format( # release_name=release_name, diff --git a/setup.py b/setup.py index 2f3d875..5b94558 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os try: @@ -15,10 +15,14 @@ with open(os.path.join(here, NAME, "metadata.py")) as metafile: exec(metafile.read(), metadata) +with open('README.md', 'r', encoding='utf-8') as f: + long_description = f.read() + setup( name=metadata['NAME'], version=metadata['VERSION'], description=metadata['DESCRIPTION'], + long_description=long_description, author=metadata['AUTHOR'], author_email=metadata['AUTHOR_EMAIL'], url=metadata['HOMEPAGE'],