203 Commits

Author SHA1 Message Date
32e6c4e96f Updated to 0.3 2023-07-06 15:24:46 +03:00
8c27fb7c37 Small fixes (#32)
* `bot.max_concurrent_transmissions` reduced to only 1
* Fixed using UnauthorizedClient when not needed

Co-authored-by: profitroll <vozhd.kk@gmail.com>
Reviewed-on: #32
2023-07-06 15:21:21 +03:00
82467518da Merge branch 'master' of https://git.end-play.xyz/profitroll/TelegramPoster 2023-07-03 12:47:29 +02:00
c0085b8000 Merge branch 'dev' 2023-07-03 12:43:43 +02:00
a7e79eb254 Updated README 2023-07-03 12:34:55 +02:00
dc774262f8 Locale for console is gone for good 2023-07-03 11:42:28 +02:00
987f642578 CLI is back and updated 2023-07-03 11:27:15 +02:00
f7df4d8ddc Bump libbot to 1.8 2023-07-03 11:04:39 +02:00
c2619a1370 Update dependency pillow to v10 (#29)
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [pillow](https://python-pillow.org) ([source](https://github.com/python-pillow/Pillow), [changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst)) | major | `~=9.4.0` -> `~=10.0.0` |

---

### Release Notes

<details>
<summary>python-pillow/Pillow</summary>

### [`v10.0.0`](https://github.com/python-pillow/Pillow/blob/HEAD/CHANGES.rst#&#8203;1000-2023-07-01)

[Compare Source](https://github.com/python-pillow/Pillow/compare/9.5.0...10.0.0)

-   Fixed deallocating mask images [#&#8203;7246](https://github.com/python-pillow/Pillow/issues/7246)
    \[radarhere]

-   Added ImageFont.MAX_STRING_LENGTH [#&#8203;7244](https://github.com/python-pillow/Pillow/issues/7244)
    \[radarhere, hugovk]

-   Fix Windows build with pyproject.toml [#&#8203;7230](https://github.com/python-pillow/Pillow/issues/7230)
    \[hugovk, nulano, radarhere]

-   Do not close provided file handles with libtiff [#&#8203;7199](https://github.com/python-pillow/Pillow/issues/7199)
    \[radarhere]

-   Convert to HSV if mode is HSV in getcolor() [#&#8203;7226](https://github.com/python-pillow/Pillow/issues/7226)
    \[radarhere]

-   Added alpha_only argument to getbbox() [#&#8203;7123](https://github.com/python-pillow/Pillow/issues/7123)
    \[radarhere. hugovk]

-   Prioritise speed in *repr_png* [#&#8203;7242](https://github.com/python-pillow/Pillow/issues/7242)
    \[radarhere]

-   Do not use CFFI access by default on PyPy [#&#8203;7236](https://github.com/python-pillow/Pillow/issues/7236)
    \[radarhere]

-   Limit size even if one dimension is zero in decompression bomb check [#&#8203;7235](https://github.com/python-pillow/Pillow/issues/7235)
    \[radarhere]

-   Use --config-settings instead of deprecated --global-option [#&#8203;7171](https://github.com/python-pillow/Pillow/issues/7171)
    \[radarhere]

-   Better C integer definitions [#&#8203;6645](https://github.com/python-pillow/Pillow/issues/6645)
    \[Yay295, hugovk]

-   Fixed finding dependencies on Cygwin [#&#8203;7175](https://github.com/python-pillow/Pillow/issues/7175)
    \[radarhere]

-   Changed grabclipboard() to use PNG instead of JPG compression on macOS [#&#8203;7219](https://github.com/python-pillow/Pillow/issues/7219)
    \[abey79, radarhere]

-   Added in_place argument to ImageOps.exif_transpose() [#&#8203;7092](https://github.com/python-pillow/Pillow/issues/7092)
    \[radarhere]

-   Fixed calling putpalette() on L and LA images before load() [#&#8203;7187](https://github.com/python-pillow/Pillow/issues/7187)
    \[radarhere]

-   Fixed saving TIFF multiframe images with LONG8 tag types [#&#8203;7078](https://github.com/python-pillow/Pillow/issues/7078)
    \[radarhere]

-   Fixed combining single duration across duplicate APNG frames [#&#8203;7146](https://github.com/python-pillow/Pillow/issues/7146)
    \[radarhere]

-   Remove temporary file when error is raised [#&#8203;7148](https://github.com/python-pillow/Pillow/issues/7148)
    \[radarhere]

-   Do not use temporary file when grabbing clipboard on Linux [#&#8203;7200](https://github.com/python-pillow/Pillow/issues/7200)
    \[radarhere]

-   If the clipboard fails to open on Windows, wait and try again [#&#8203;7141](https://github.com/python-pillow/Pillow/issues/7141)
    \[radarhere]

-   Fixed saving multiple 1 mode frames to GIF [#&#8203;7181](https://github.com/python-pillow/Pillow/issues/7181)
    \[radarhere]

-   Replaced absolute PIL import with relative import [#&#8203;7173](https://github.com/python-pillow/Pillow/issues/7173)
    \[radarhere]

-   Replaced deprecated Py_FileSystemDefaultEncoding for Python >= 3.12 [#&#8203;7192](https://github.com/python-pillow/Pillow/issues/7192)
    \[radarhere]

-   Improved wl-paste mimetype handling in ImageGrab [#&#8203;7094](https://github.com/python-pillow/Pillow/issues/7094)
    \[rrcgat, radarhere]

-   Added *repr_jpeg*() for IPython display_jpeg [#&#8203;7135](https://github.com/python-pillow/Pillow/issues/7135)
    \[n3011, radarhere, nulano]

-   Use "/sbin/ldconfig" if ldconfig is not found [#&#8203;7068](https://github.com/python-pillow/Pillow/issues/7068)
    \[radarhere]

-   Prefer screenshots using XCB over gnome-screenshot [#&#8203;7143](https://github.com/python-pillow/Pillow/issues/7143)
    \[nulano, radarhere]

-   Fixed joined corners for ImageDraw rounded_rectangle() odd dimensions [#&#8203;7151](https://github.com/python-pillow/Pillow/issues/7151)
    \[radarhere]

-   Support reading signed 8-bit TIFF images [#&#8203;7111](https://github.com/python-pillow/Pillow/issues/7111)
    \[radarhere]

-   Added width argument to ImageDraw regular_polygon [#&#8203;7132](https://github.com/python-pillow/Pillow/issues/7132)
    \[radarhere]

-   Support I mode for ImageFilter.BuiltinFilter [#&#8203;7108](https://github.com/python-pillow/Pillow/issues/7108)
    \[radarhere]

-   Raise error from stderr of Linux ImageGrab.grabclipboard() command [#&#8203;7112](https://github.com/python-pillow/Pillow/issues/7112)
    \[radarhere]

-   Added unpacker from I;16B to I;16 [#&#8203;7125](https://github.com/python-pillow/Pillow/issues/7125)
    \[radarhere]

-   Support float font sizes [#&#8203;7107](https://github.com/python-pillow/Pillow/issues/7107)
    \[radarhere]

-   Use later value for duplicate xref entries in PdfParser [#&#8203;7102](https://github.com/python-pillow/Pillow/issues/7102)
    \[radarhere]

-   Load before getting size in **getstate** [#&#8203;7105](https://github.com/python-pillow/Pillow/issues/7105)
    \[bigcat88, radarhere]

-   Fixed type handling for include and lib directories [#&#8203;7069](https://github.com/python-pillow/Pillow/issues/7069)
    \[adisbladis, radarhere]

-   Remove deprecations for Pillow 10.0.0 [#&#8203;7059](https://github.com/python-pillow/Pillow/issues/7059), [#&#8203;7080](https://github.com/python-pillow/Pillow/issues/7080)
    \[hugovk, radarhere]

-   Drop support for soon-EOL Python 3.7 [#&#8203;7058](https://github.com/python-pillow/Pillow/issues/7058)
    \[hugovk, radarhere]

### [`v9.5.0`](https://github.com/python-pillow/Pillow/blob/HEAD/CHANGES.rst#&#8203;950-2023-04-01)

[Compare Source](https://github.com/python-pillow/Pillow/compare/9.4.0...9.5.0)

-   Added ImageSourceData to TAGS_V2 [#&#8203;7053](https://github.com/python-pillow/Pillow/issues/7053)
    \[radarhere]

-   Clear PPM half token after use [#&#8203;7052](https://github.com/python-pillow/Pillow/issues/7052)
    \[radarhere]

-   Removed absolute path to ldconfig [#&#8203;7044](https://github.com/python-pillow/Pillow/issues/7044)
    \[radarhere]

-   Support custom comments and PLT markers when saving JPEG2000 images [#&#8203;6903](https://github.com/python-pillow/Pillow/issues/6903)
    \[joshware, radarhere, hugovk]

-   Load before getting size in **array_interface** [#&#8203;7034](https://github.com/python-pillow/Pillow/issues/7034)
    \[radarhere]

-   Support creating BGR;15, BGR;16 and BGR;24 images, but drop support for BGR;32 [#&#8203;7010](https://github.com/python-pillow/Pillow/issues/7010)
    \[radarhere]

-   Consider transparency when applying APNG blend mask [#&#8203;7018](https://github.com/python-pillow/Pillow/issues/7018)
    \[radarhere]

-   Round duration when saving animated WebP images [#&#8203;6996](https://github.com/python-pillow/Pillow/issues/6996)
    \[radarhere]

-   Added reading of JPEG2000 comments [#&#8203;6909](https://github.com/python-pillow/Pillow/issues/6909)
    \[radarhere]

-   Decrement reference count [#&#8203;7003](https://github.com/python-pillow/Pillow/issues/7003)
    \[radarhere, nulano]

-   Allow libtiff_support_custom_tags to be missing [#&#8203;7020](https://github.com/python-pillow/Pillow/issues/7020)
    \[radarhere]

-   Improved I;16N support [#&#8203;6834](https://github.com/python-pillow/Pillow/issues/6834)
    \[radarhere]

-   Added QOI reading [#&#8203;6852](https://github.com/python-pillow/Pillow/issues/6852)
    \[radarhere, hugovk]

-   Added saving RGBA images as PDFs [#&#8203;6925](https://github.com/python-pillow/Pillow/issues/6925)
    \[radarhere]

-   Do not raise an error if os.environ does not contain PATH [#&#8203;6935](https://github.com/python-pillow/Pillow/issues/6935)
    \[radarhere, hugovk]

-   Close OleFileIO instance when closing or exiting FPX or MIC [#&#8203;7005](https://github.com/python-pillow/Pillow/issues/7005)
    \[radarhere]

-   Added **int** to IFDRational for Python >= 3.11 [#&#8203;6998](https://github.com/python-pillow/Pillow/issues/6998)
    \[radarhere]

-   Added memoryview support to Dib.frombytes() [#&#8203;6988](https://github.com/python-pillow/Pillow/issues/6988)
    \[radarhere, nulano]

-   Close file pointer copy in the libtiff encoder if still open [#&#8203;6986](https://github.com/python-pillow/Pillow/issues/6986)
    \[fcarron, radarhere]

-   Raise an error if ImageDraw co-ordinates are incorrectly ordered [#&#8203;6978](https://github.com/python-pillow/Pillow/issues/6978)
    \[radarhere]

-   Added "corners" argument to ImageDraw rounded_rectangle() [#&#8203;6954](https://github.com/python-pillow/Pillow/issues/6954)
    \[radarhere]

-   Added memoryview support to frombytes() [#&#8203;6974](https://github.com/python-pillow/Pillow/issues/6974)
    \[radarhere]

-   Allow comments in FITS images [#&#8203;6973](https://github.com/python-pillow/Pillow/issues/6973)
    \[radarhere]

-   Support saving PDF with different X and Y resolutions [#&#8203;6961](https://github.com/python-pillow/Pillow/issues/6961)
    \[jvanderneutstulen, radarhere, hugovk]

-   Fixed writing int as UNDEFINED tag [#&#8203;6950](https://github.com/python-pillow/Pillow/issues/6950)
    \[radarhere]

-   Raise an error if EXIF data is too long when saving JPEG [#&#8203;6939](https://github.com/python-pillow/Pillow/issues/6939)
    \[radarhere]

-   Handle more than one directory returned by pkg-config [#&#8203;6896](https://github.com/python-pillow/Pillow/issues/6896)
    \[sebastic, radarhere]

-   Do not retry past formats when loading all formats for the first time [#&#8203;6902](https://github.com/python-pillow/Pillow/issues/6902)
    \[radarhere]

-   Do not retry specified formats if they failed when opening [#&#8203;6893](https://github.com/python-pillow/Pillow/issues/6893)
    \[radarhere]

-   Do not unintentionally load TIFF format at first [#&#8203;6892](https://github.com/python-pillow/Pillow/issues/6892)
    \[radarhere]

-   Stop reading when EPS line becomes too long [#&#8203;6897](https://github.com/python-pillow/Pillow/issues/6897)
    \[radarhere]

-   Allow writing IFDRational to BYTE tag [#&#8203;6890](https://github.com/python-pillow/Pillow/issues/6890)
    \[radarhere]

-   Raise ValueError for BoxBlur filter with negative radius [#&#8203;6874](https://github.com/python-pillow/Pillow/issues/6874)
    \[hugovk, radarhere]

-   Support arbitrary number of loaded modules on Windows [#&#8203;6761](https://github.com/python-pillow/Pillow/issues/6761)
    \[javidcf, radarhere, nulano]

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41NC4wIiwidXBkYXRlZEluVmVyIjoiMzUuNTQuMCJ9-->

Co-authored-by: Renovate <renovate@git.end-play.xyz>
Reviewed-on: https://git.end-play.xyz/profitroll/TelegramPoster/pulls/29
Co-authored-by: Renovate <renovate@noreply.localhost>
Co-committed-by: Renovate <renovate@noreply.localhost>
2023-07-03 11:37:48 +03:00
15b272ae35 max_concurrent_transmissions is now 3 by default 2023-07-01 15:43:07 +02:00
28b5449f2a Improved /shutdown 2023-06-30 11:34:15 +02:00
bfec702bef Config cleanup 2023-06-30 11:34:06 +02:00
fd0c4c0545 Bump libbot to 1.7 2023-06-30 11:33:34 +02:00
11dbf3239d Removed deprecated collection 2023-06-28 10:52:00 +02:00
3d87f035e7 Added /language for owner 2023-06-28 10:48:14 +02:00
d8245934e2 Fixed wrong db record 2023-06-28 10:45:23 +02:00
420a4cb7eb Fixed locale strings and commands 2023-06-28 10:43:13 +02:00
b747dde664 Added missing requirement 2023-06-28 10:39:39 +02:00
10c60ae932 WIP: /language system 2023-06-28 10:37:18 +02:00
6f8b560acc WIP: New User system 2023-06-28 10:15:45 +02:00
93f3439a11 Fixed response type check 2023-06-28 08:59:40 +02:00
9e0a815062 Fixed markup 2023-06-28 08:57:09 +02:00
51da210817 Small fix 2023-06-28 08:56:21 +02:00
e06cb4b377 /remove command fixed 2023-06-28 08:53:15 +02:00
97b3aa1505 Starting scripts and README were updated 2023-06-28 08:22:18 +02:00
5adb004a2a API usage overhaul (#27)
* `/report` command added
* Updated to libbot 1.5
* Moved to [PhotosAPI_Client](https://git.end-play.xyz/profitroll/PhotosAPI_Client) v0.5.0 from using self-made API client
* Video support (almost stable)
* Bug fixes and improvements

Co-authored-by: profitroll <vozhd.kk@gmail.com>
Reviewed-on: #27
2023-06-28 00:57:30 +03:00
f003638128 Update 'requirements.txt' 2023-06-28 00:57:13 +03:00
e9e68cb6b3 Update dependency pymongo to v4.4.0 (#25)
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [pymongo](https://github.com/mongodb/mongo-python-driver) | minor | `==4.3.3` -> `==4.4.0` |

---

### Release Notes

<details>
<summary>mongodb/mongo-python-driver</summary>

### [`v4.4.0`](https://github.com/mongodb/mongo-python-driver/releases/tag/4.4.0): PyMongo 4.4.0

[Compare Source](https://github.com/mongodb/mongo-python-driver/compare/4.3.3...4.4.0)

Release notes: https://www.mongodb.com/community/forums/t/pymongo-4-4-released/232211

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41NC4wIiwidXBkYXRlZEluVmVyIjoiMzUuNTQuMCJ9-->

Co-authored-by: Renovate <renovate@git.end-play.xyz>
Reviewed-on: #25
Co-authored-by: Renovate <renovate@noreply.localhost>
Co-committed-by: Renovate <renovate@noreply.localhost>
2023-06-21 22:45:23 +03:00
bd62149a2c Update dependency ujson to v5.8.0 (#24)
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ujson](https://github.com/ultrajson/ultrajson) | minor | `==5.7.0` -> `==5.8.0` |

---

### Release Notes

<details>
<summary>ultrajson/ultrajson</summary>

### [`v5.8.0`](https://github.com/ultrajson/ultrajson/releases/tag/5.8.0)

[Compare Source](https://github.com/ultrajson/ultrajson/compare/5.7.0...5.8.0)

#### Added

-   Build wheel for Python 3.12 beta (built against 3.12.0b2) ([#&#8203;594](https://github.com/ultrajson/ultrajson/issues/594)) [@&#8203;hugovk](https://github.com/hugovk)

#### Changed

-   Drop support for Python 3.7 ([#&#8203;595](https://github.com/ultrajson/ultrajson/issues/595)) [@&#8203;hugovk](https://github.com/hugovk)

#### Fixed

-   Include BSD-3-Clause and TCL license text ([#&#8203;584](https://github.com/ultrajson/ultrajson/issues/584)) [@&#8203;musicinmybrain](https://github.com/musicinmybrain)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41NC4wIiwidXBkYXRlZEluVmVyIjoiMzUuNTQuMCJ9-->

Co-authored-by: Renovate <renovate@git.end-play.xyz>
Reviewed-on: https://git.end-play.xyz/profitroll/TelegramPoster/pulls/24
Co-authored-by: Renovate <renovate@noreply.localhost>
Co-committed-by: Renovate <renovate@noreply.localhost>
2023-06-11 12:29:02 +03:00
e5b2584d4c Bug fixes and Pyrogram bump (#23)
Co-authored-by: Renovate <renovate@git.end-play.xyz>
Co-authored-by: profitroll <vozhd.kk@gmail.com>
Reviewed-on: #23
2023-05-16 15:45:23 +03:00
76fc4981cc Merge branch 'master' into dev 2023-05-16 15:45:11 +03:00
337a7b28aa Fixed coroutines not being awaited 2023-05-16 12:30:56 +02:00
93804345df Update dependency pyrogram to v2.0.106 (#22)
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [pyrogram](https://github.com/pyrogram) ([source](https://github.com/pyrogram/pyrogram)) | patch | `==2.0.104` -> `==2.0.106` |

---

### Release Notes

<details>
<summary>pyrogram/pyrogram</summary>

### [`v2.0.106`](https://github.com/pyrogram/pyrogram/compare/v2.0.105...v2.0.106)

[Compare Source](https://github.com/pyrogram/pyrogram/compare/v2.0.105...v2.0.106)

### [`v2.0.105`](https://github.com/pyrogram/pyrogram/compare/v2.0.104...v2.0.105)

[Compare Source](https://github.com/pyrogram/pyrogram/compare/v2.0.104...v2.0.105)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41NC4wIiwidXBkYXRlZEluVmVyIjoiMzUuNTQuMCJ9-->

Reviewed-on: #22
Co-authored-by: Renovate <renovate@git.end-play.xyz>
Co-committed-by: Renovate <renovate@git.end-play.xyz>
2023-05-08 11:51:15 +03:00
f5b3335af0 master (#21)
Co-authored-by: Renovate <renovate@git.end-play.xyz>
Co-authored-by: profitroll <vozhd.kk@gmail.com>
Reviewed-on: #21
2023-04-24 14:38:03 +03:00
fc8f49b487 Commented random_pic_response output 2023-04-24 13:36:58 +02:00
c6cba6de2f Merge branch 'dev' 2023-04-24 13:33:33 +02:00
adef3b3afc Changed versioning prefix in code 2023-04-24 12:53:22 +02:00
853c3c7cea dev (#19)
* Config file changes
* Commands `/remove`, `/import` and `/export`

Co-authored-by: profitroll <vozhd.kk@gmail.com>
Co-authored-by: Profitroll <47523801+profitrollgame@users.noreply.github.com>
Co-authored-by: Renovate <renovate@git.end-play.xyz>
Reviewed-on: #19
2023-04-24 13:48:22 +03:00
fe60b3f8a5 Changed album config path 2023-04-24 12:44:10 +02:00
aa82a8f382 Fixed SyntaxError 2023-04-24 12:40:06 +02:00
826e031a39 Update dependency pyrogram to v2.0.104 (#18)
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [pyrogram](https://github.com/pyrogram) ([source](https://github.com/pyrogram/pyrogram)) | patch | `==2.0.102` -> `==2.0.104` |

---

### Release Notes

<details>
<summary>pyrogram/pyrogram</summary>

### [`v2.0.104`](https://github.com/pyrogram/pyrogram/compare/v2.0.103...v2.0.104)

[Compare Source](https://github.com/pyrogram/pyrogram/compare/v2.0.103...v2.0.104)

### [`v2.0.103`](https://github.com/pyrogram/pyrogram/compare/v2.0.102...v2.0.103)

[Compare Source](https://github.com/pyrogram/pyrogram/compare/v2.0.102...v2.0.103)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41NC4wIiwidXBkYXRlZEluVmVyIjoiMzUuNTQuMCJ9-->

Reviewed-on: #18
Co-authored-by: Renovate <renovate@git.end-play.xyz>
Co-committed-by: Renovate <renovate@git.end-play.xyz>
2023-04-24 13:36:39 +03:00
0681338970 Update dependency psutil to v5.9.5 (#17)
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [psutil](https://github.com/giampaolo/psutil) | patch | `==5.9.4` -> `==5.9.5` |

---

### Release Notes

<details>
<summary>giampaolo/psutil</summary>

### [`v5.9.5`](https://github.com/giampaolo/psutil/blob/HEAD/HISTORY.rst#&#8203;595)

[Compare Source](https://github.com/giampaolo/psutil/compare/release-5.9.4...release-5.9.5)

\=====

2023-04-17

**Enhancements**

-   2196\_: in case of exception, display a cleaner error traceback by hiding the
    `KeyError` bit deriving from a missed cache hit.
-   2217\_: print the full traceback when a `DeprecationWarning` or `UserWarning`
    is raised.
-   2230\_, \[OpenBSD]: `psutil.net_connections`\_ implementation was rewritten from
    scratch:
    -   We're now able to retrieve the path of AF_UNIX sockets (before it was an
        empty string)
    -   The function is faster since it no longer iterates over all processes.
    -   No longer produces duplicate connection entries.
-   2238\_: there are cases where `Process.cwd()`\_ cannot be determined
    (e.g. directory no longer exists), in which case we returned either `None`
    or an empty string. This was consolidated and we now return `""` on all
    platforms.
-   2239\_, \[UNIX]: if process is a zombie, and we can only determine part of the
    its truncated `Process.name()`\_ (15 chars), don't fail with `ZombieProcess`\_
    when we try to guess the full name from the `Process.cmdline()`\_. Just
    return the truncated name.
-   2240\_, \[NetBSD], \[OpenBSD]: add CI testing on every commit for NetBSD and
    OpenBSD platforms (python 3 only).

**Bug fixes**

-   1043\_, \[OpenBSD] `psutil.net_connections`\_ returns duplicate entries.
-   1915\_, \[Linux]: on certain kernels, `"MemAvailable"` field from
    `/proc/meminfo` returns `0` (possibly a kernel bug), in which case we
    calculate an approximation for `available` memory which matches "free"
    CLI utility.
-   2164\_, \[Linux]: compilation fails on kernels < 2.6.27 (e.g. CentOS 5).
-   2186\_, \[FreeBSD]: compilation fails with Clang 15.  (patch by Po-Chuan Hsieh)
-   2191\_, \[Linux]: `disk_partitions()`*: do not unnecessarily read
    /proc/filesystems and raise `AccessDenied`* unless user specified `all=False`
    argument.
-   2216\_, \[Windows]: fix tests when running in a virtual environment (patch by
    Matthieu Darbois)
-   2225\_, \[POSIX]: `users()`\_ loses precision for `started` attribute (off by
    1 minute).
-   2229\_, \[OpenBSD]: unable to properly recognize zombie processes.
    `NoSuchProcess`\_ may be raised instead of `ZombieProcess`\_.
-   2231\_, \[NetBSD]: *available*  `virtual_memory()`\_ is higher than *total*.
-   2234\_, \[NetBSD]: `virtual_memory()`\_ metrics are wrong: *available* and
    *used* are too high. We now match values shown by *htop* CLI utility.
-   2236\_, \[NetBSD]: `Process.num_threads()`\_ and `Process.threads()`\_ return
    threads that are already terminated.
-   2237\_, \[OpenBSD], \[NetBSD]: `Process.cwd()`\_ may raise `FileNotFoundError`
    if cwd no longer exists. Return an empty string instead.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41NC4wIiwidXBkYXRlZEluVmVyIjoiMzUuNTQuMCJ9-->

Reviewed-on: #17
Co-authored-by: Renovate <renovate@git.end-play.xyz>
Co-committed-by: Renovate <renovate@git.end-play.xyz>
2023-04-24 13:36:12 +03:00
7c8e07bbc9 Made some dependencies strict 2023-04-24 12:13:14 +02:00
ad653146e1 Update dependency pillow to ~=9.5.0 (#15)
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [pillow](https://python-pillow.org) ([source](https://github.com/python-pillow/Pillow), [changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst)) | minor | `~=9.4.0` -> `~=9.5.0` |

---

### Release Notes

<details>
<summary>python-pillow/Pillow</summary>

### [`v9.5.0`](https://github.com/python-pillow/Pillow/blob/HEAD/CHANGES.rst#&#8203;950-2023-04-01)

[Compare Source](https://github.com/python-pillow/Pillow/compare/9.4.0...9.5.0)

-   Added ImageSourceData to TAGS_V2 [#&#8203;7053](https://github.com/python-pillow/Pillow/issues/7053)
    \[radarhere]

-   Clear PPM half token after use [#&#8203;7052](https://github.com/python-pillow/Pillow/issues/7052)
    \[radarhere]

-   Removed absolute path to ldconfig [#&#8203;7044](https://github.com/python-pillow/Pillow/issues/7044)
    \[radarhere]

-   Support custom comments and PLT markers when saving JPEG2000 images [#&#8203;6903](https://github.com/python-pillow/Pillow/issues/6903)
    \[joshware, radarhere, hugovk]

-   Load before getting size in **array_interface** [#&#8203;7034](https://github.com/python-pillow/Pillow/issues/7034)
    \[radarhere]

-   Support creating BGR;15, BGR;16 and BGR;24 images, but drop support for BGR;32 [#&#8203;7010](https://github.com/python-pillow/Pillow/issues/7010)
    \[radarhere]

-   Consider transparency when applying APNG blend mask [#&#8203;7018](https://github.com/python-pillow/Pillow/issues/7018)
    \[radarhere]

-   Round duration when saving animated WebP images [#&#8203;6996](https://github.com/python-pillow/Pillow/issues/6996)
    \[radarhere]

-   Added reading of JPEG2000 comments [#&#8203;6909](https://github.com/python-pillow/Pillow/issues/6909)
    \[radarhere]

-   Decrement reference count [#&#8203;7003](https://github.com/python-pillow/Pillow/issues/7003)
    \[radarhere, nulano]

-   Allow libtiff_support_custom_tags to be missing [#&#8203;7020](https://github.com/python-pillow/Pillow/issues/7020)
    \[radarhere]

-   Improved I;16N support [#&#8203;6834](https://github.com/python-pillow/Pillow/issues/6834)
    \[radarhere]

-   Added QOI reading [#&#8203;6852](https://github.com/python-pillow/Pillow/issues/6852)
    \[radarhere, hugovk]

-   Added saving RGBA images as PDFs [#&#8203;6925](https://github.com/python-pillow/Pillow/issues/6925)
    \[radarhere]

-   Do not raise an error if os.environ does not contain PATH [#&#8203;6935](https://github.com/python-pillow/Pillow/issues/6935)
    \[radarhere, hugovk]

-   Close OleFileIO instance when closing or exiting FPX or MIC [#&#8203;7005](https://github.com/python-pillow/Pillow/issues/7005)
    \[radarhere]

-   Added **int** to IFDRational for Python >= 3.11 [#&#8203;6998](https://github.com/python-pillow/Pillow/issues/6998)
    \[radarhere]

-   Added memoryview support to Dib.frombytes() [#&#8203;6988](https://github.com/python-pillow/Pillow/issues/6988)
    \[radarhere, nulano]

-   Close file pointer copy in the libtiff encoder if still open [#&#8203;6986](https://github.com/python-pillow/Pillow/issues/6986)
    \[fcarron, radarhere]

-   Raise an error if ImageDraw co-ordinates are incorrectly ordered [#&#8203;6978](https://github.com/python-pillow/Pillow/issues/6978)
    \[radarhere]

-   Added "corners" argument to ImageDraw rounded_rectangle() [#&#8203;6954](https://github.com/python-pillow/Pillow/issues/6954)
    \[radarhere]

-   Added memoryview support to frombytes() [#&#8203;6974](https://github.com/python-pillow/Pillow/issues/6974)
    \[radarhere]

-   Allow comments in FITS images [#&#8203;6973](https://github.com/python-pillow/Pillow/issues/6973)
    \[radarhere]

-   Support saving PDF with different X and Y resolutions [#&#8203;6961](https://github.com/python-pillow/Pillow/issues/6961)
    \[jvanderneutstulen, radarhere, hugovk]

-   Fixed writing int as UNDEFINED tag [#&#8203;6950](https://github.com/python-pillow/Pillow/issues/6950)
    \[radarhere]

-   Raise an error if EXIF data is too long when saving JPEG [#&#8203;6939](https://github.com/python-pillow/Pillow/issues/6939)
    \[radarhere]

-   Handle more than one directory returned by pkg-config [#&#8203;6896](https://github.com/python-pillow/Pillow/issues/6896)
    \[sebastic, radarhere]

-   Do not retry past formats when loading all formats for the first time [#&#8203;6902](https://github.com/python-pillow/Pillow/issues/6902)
    \[radarhere]

-   Do not retry specified formats if they failed when opening [#&#8203;6893](https://github.com/python-pillow/Pillow/issues/6893)
    \[radarhere]

-   Do not unintentionally load TIFF format at first [#&#8203;6892](https://github.com/python-pillow/Pillow/issues/6892)
    \[radarhere]

-   Stop reading when EPS line becomes too long [#&#8203;6897](https://github.com/python-pillow/Pillow/issues/6897)
    \[radarhere]

-   Allow writing IFDRational to BYTE tag [#&#8203;6890](https://github.com/python-pillow/Pillow/issues/6890)
    \[radarhere]

-   Raise ValueError for BoxBlur filter with negative radius [#&#8203;6874](https://github.com/python-pillow/Pillow/issues/6874)
    \[hugovk, radarhere]

-   Support arbitrary number of loaded modules on Windows [#&#8203;6761](https://github.com/python-pillow/Pillow/issues/6761)
    \[javidcf, radarhere, nulano]

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41NC4wIiwidXBkYXRlZEluVmVyIjoiMzUuNTQuMCJ9-->

Reviewed-on: https://git.end-play.xyz/profitroll/TelegramPoster/pulls/15
Co-authored-by: Renovate <renovate@git.end-play.xyz>
Co-committed-by: Renovate <renovate@git.end-play.xyz>
2023-04-20 16:04:39 +03:00
e5f80d9702 Updated Renovate config 2023-04-20 13:41:14 +02:00
6f03d5c18f Configure Renovate (#14)
Welcome to [Renovate](https://github.com/renovatebot/renovate)! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.

---
### Detected Package Files

 * `requirements.txt` (pip_requirements)

### Configuration Summary

Based on the default config's presets, Renovate will:

  - Start dependency updates only once this onboarding PR is merged
  - Enable Renovate Dependency Dashboard creation.
  - Use semantic commit type `fix` for dependencies and `chore` for all others if semantic commits are in use.
  - Ignore `node_modules`, `bower_components`, `vendor` and various test/tests directories.
  - Group known monorepo packages together.
  - Use curated list of recommended non-monorepo package groupings.
  - Apply crowd-sourced package replacement rules.
  - Apply crowd-sourced workarounds for known problems with packages.

🔡 Would you like to change the way Renovate is upgrading your dependencies? Simply edit the `.renovaterc` in this branch with your custom config and the list of Pull Requests in the "What to Expect" section below will be updated the next time Renovate runs.

---

### What to Expect

It looks like your repository dependencies are already up-to-date and no Pull Requests will be necessary right away.

---

 Got questions? Check out Renovate's [Docs](https://docs.renovatebot.com/), particularly the Getting Started section.
If you need any further assistance then you can also [request help here](https://github.com/renovatebot/renovate/discussions).

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Reviewed-on: #14
Co-authored-by: Renovate <renovate@git.end-play.xyz>
Co-committed-by: Renovate <renovate@git.end-play.xyz>
2023-04-20 14:40:36 +03:00
2b520760d3 Fixed branch name in Renovate config 2023-04-20 13:35:52 +02:00
9d340b32c1 Added Renovate config 2023-04-20 13:32:52 +02:00
4dd754055e Removed optional dependencies as a concept 2023-03-23 15:13:38 +01:00
ae654d686e TgCrypto is no longer optional dependency 2023-03-23 15:12:53 +01:00
af2bcd088f Album check returned 2023-03-22 15:52:34 +01:00
Profitroll
cc6523f604 Added updates checker 2023-03-22 11:03:03 +01:00
Profitroll
5ad52aa3f8 Changed aiohttp module location 2023-03-22 11:02:55 +01:00
Profitroll
45789ad013 Updates wiki init 2023-03-22 11:02:13 +01:00
Profitroll
4422a13ba9 Improved async context 2023-03-22 10:33:21 +01:00
f82c7b309f Added media removal 2023-03-21 14:34:25 +01:00
399fc5050d Updated user messages 2023-03-20 14:50:57 +01:00
56adb16a3e Replaced strings 2023-03-20 13:59:22 +01:00
1684c5177c Replaced /reboot with /shutdown 2023-03-20 13:56:18 +01:00
fba52bcfc4 Updated docs 2023-03-20 13:55:55 +01:00
20666fc0f8 Improved shutdown 2023-03-20 13:55:42 +01:00
03b6bbe039 Prototype: Files import 2023-03-20 12:03:03 +01:00
1749d49a52 Fixed enumerate error 2023-03-18 21:17:04 +01:00
a4323981fb WIP: Media import/export 2023-03-18 20:53:26 +01:00
06b6b49f43 This commit closes #13 2023-03-17 14:51:41 +01:00
1f345e87f7 Improved logging 2023-03-17 14:44:37 +01:00
717586a9f0 Improved logging 2023-03-17 14:13:28 +01:00
95351f247c This commit closed #12 2023-03-17 13:52:16 +01:00
b5e3abd4ad WIP: default config replacement for (#12) 2023-03-16 16:32:26 +01:00
4ec69c2a05 This commit closes #9 2023-03-16 15:03:14 +01:00
Profitroll
62e0a4986c WIP: ID returns 2023-03-16 12:58:57 +01:00
Profitroll
be8f0262d0 This commit closes #11 2023-03-15 21:58:14 +01:00
Profitroll
ba5a0f116c Merge branch 'dev' of https://git.end-play.xyz/profitroll/TelegramPoster into dev 2023-03-15 21:52:48 +01:00
Profitroll
e85adeafd0 Added info about venv to the README 2023-03-15 21:50:06 +01:00
87d2a2c6d3 Improved README 2023-03-13 13:02:06 +01:00
bc6080e832 Added venv guide to README 2023-03-13 11:33:30 +01:00
9bf4663b9e Made execution order correct 2023-03-12 22:58:55 +01:00
b74ce9ec89 Small fixes 2023-03-12 22:58:41 +01:00
6ed3673682 Fixed a typo 2023-03-12 22:45:06 +01:00
c593be156d Rearranged content 2023-03-12 22:30:35 +01:00
c96f98560c WIP: New readme 2023-03-12 22:29:53 +01:00
e1c1b58ffb Added warning about readme not being ready yet 2023-03-12 22:26:16 +01:00
bd2a1f0b12 WIP: New readme 2023-03-12 22:23:02 +01:00
8cc7808afb Disabled slash-escape for .json 2023-03-12 22:14:41 +01:00
6684c4d750 Bump Pyrogram to 2.0.102 2023-03-12 22:14:23 +01:00
c670db72fa Added user-friendly CLI 2023-03-12 22:14:03 +01:00
48acab2d5e WIP: New readme 2023-03-12 19:57:22 +01:00
62f076148c Wiki pages init 2023-03-12 19:43:51 +01:00
59b504e6d9 Temp: removed strings about API based in config 2023-03-12 19:34:27 +01:00
ad281ba981 WIP: New readme 2023-03-12 19:25:35 +01:00
0073120bf2 Moved ujson to required dependencies 2023-03-12 14:54:06 +01:00
244173e556 Bumped Pyrogram to 2.0.101 2023-03-12 14:25:22 +01:00
98e9c5f5a2 Fixed line being displayed incorrectly 2023-03-09 16:17:35 +01:00
a8545dd097 Fixed project name align 2023-03-09 16:16:38 +01:00
3f22340852 Added license and code style badges 2023-03-09 11:48:50 +01:00
c2fb88ed65 Bumped APScheduler to 3.10.1 2023-03-09 11:35:02 +01:00
88692ebc85 Now using black for formatting 2023-03-09 11:33:02 +01:00
4331af415e Moved to aiohttp and aiofiles 2023-03-02 22:38:48 +01:00
a913ba19c6 WIP: aiohttp migration 2023-03-02 16:39:59 +01:00
2387823151 Added missing texts 2023-02-25 23:31:09 +01:00
88f8bb4a52 WIP: Photos and queue removal 2023-02-25 23:19:08 +01:00
cf6c1f03d7 Disabled notification for accepted submissions 2023-02-25 23:12:33 +01:00
0a309a9f59 Added one more rule 2023-02-25 23:10:57 +01:00
7810f3b7b9 Fixed absence of None check 2023-02-24 21:06:18 +01:00
7b2534012d Fixed typo 2023-02-24 13:48:06 -05:00
6e8b47cf4b Improved submissions randomness 2023-02-24 13:33:34 -05:00
c27b1c5a5b Temporarily disabled album creation on start 2023-02-24 13:25:57 -05:00
c7228a006b Improved randomness 2023-02-24 13:25:36 -05:00
64ae3fb047 Added option to mention submissions 2023-02-24 12:39:33 -05:00
Profitroll
056fc52353 This commit closes #4 and closes #6 2023-02-19 20:54:58 +01:00
Profitroll
8bafd0cb35 This commit closes #3 2023-02-19 20:44:00 +01:00
Profitroll
fd47217bad This commit closes #5 2023-02-19 20:31:08 +01:00
Profitroll
6b7b5c22f2 Reverted web preview disable 2023-02-18 00:58:09 +01:00
Profitroll
b3698cfa70 Added support for duplicates access tokens 2023-02-18 00:55:58 +01:00
Profitroll
7607003f55 Added callback message for "nothing" 2023-02-17 23:45:55 +01:00
Profitroll
7918049f49 Fixed language code typo 2023-02-17 23:18:54 +01:00
Profitroll
fcd59b7aca Fixed caption display 2023-02-17 23:18:34 +01:00
Profitroll
8c478072c6 Fixed reply message not getting quoted 2023-02-17 23:18:19 +01:00
Profitroll
b766d0c52c Improved linting and removed unused imports 2023-02-17 22:59:03 +01:00
Profitroll
807e629ae7 Moved cooldowns to PosterUser class 2023-02-17 22:48:37 +01:00
Profitroll
87af9fd333 Fixed captions not getting detected 2023-02-17 22:26:07 +01:00
Profitroll
a54081a2ae Fixed some issues with locale 2023-02-17 21:58:46 +01:00
Profitroll
664284a6f8 Integrated previous commits 2023-02-17 21:55:38 +01:00
Profitroll
bd9917fb17 Replaced user block logic 2023-02-17 21:54:52 +01:00
Profitroll
68ea087963 Integrated interval-based schedule 2023-02-17 21:54:30 +01:00
Profitroll
d1813856d9 Imported callback "nothing" 2023-02-17 21:54:14 +01:00
Profitroll
cf204577e4 Added external address for links 2023-02-17 21:53:57 +01:00
Profitroll
68c887999e Divided admins and owner 2023-02-17 21:53:43 +01:00
Profitroll
642e17ee55 Image resize when too big 2023-02-17 16:46:44 +01:00
Profitroll
25af9b31f8 Changed Client to PosterClient 2023-02-17 16:46:33 +01:00
Profitroll
28fc359593 WIP: export and import 2023-02-17 16:46:13 +01:00
Profitroll
07203a9db9 Changed the way exceptions are handled 2023-02-17 16:45:51 +01:00
Profitroll
663a7b0db8 Submission without confirmation added 2023-02-17 16:44:56 +01:00
Profitroll
0d2e9fa6ec Using PosterClient instead of Client 2023-02-17 16:44:30 +01:00
Profitroll
c90e5eb697 Added Pillow to requirements 2023-02-17 16:44:03 +01:00
Profitroll
f4359aa6cd Added upload_pic method 2023-02-17 11:51:38 +01:00
4cd37be5dc WIP: New submission system 2023-02-16 16:41:01 +01:00
05042f01c6 Disabled WIP warning 2023-02-15 14:07:40 +01:00
5b1afe2c9e WIP: API usage as main 2023-02-15 14:06:06 +01:00
6eaa6019a3 Added tmp file size 2023-02-15 11:56:15 +01:00
493be818b8 Updated ignore 2023-02-15 11:56:05 +01:00
cf09017985 TMP: interval changes 2023-02-14 16:26:08 +01:00
7940cbe5a7 WIP: API usage as main 2023-02-14 16:25:56 +01:00
8e0fee4cb9 Added database support 2023-02-14 14:45:52 +01:00
08e03ba911 Moved handlers to another location 2023-02-14 11:38:54 +01:00
b589da5d8f Updated dependencies 2023-02-14 11:38:09 +01:00
a3a1be241c Small keyboard fix 2023-01-17 14:38:31 +01:00
9ce05589b0 Contextual keyboard [WIP] 2023-01-17 14:38:21 +01:00
c1ee988106 Added empty callback 2023-01-17 14:37:36 +01:00
aebe804b58 Optimized for API 2023-01-17 14:11:23 +01:00
9f0ed202da Updated ignore 2023-01-17 12:51:30 +01:00
b4a9595eb4 Renamed logging module 2023-01-17 11:43:10 +01:00
569fffd223 Updated requirements 2023-01-17 11:41:07 +01:00
f719befe40 Updated config 2023-01-17 11:40:59 +01:00
c4323f0b00 Moved to async 2023-01-10 13:06:24 +01:00
6facf428c5 Complete refactor 2023-01-10 12:52:44 +01:00
9261585f5f Added scheduler start 2023-01-09 19:01:07 +02:00
cddf1e211a Moved to apscheduler 2023-01-09 15:36:56 +01:00
cd5b73e7ff Small improvements 2022-11-03 12:13:02 +01:00
46ea9a2f74 Merge branch 'master' of https://git.profitroll.eu/profitroll/TelegramPoster 2022-11-03 12:12:41 +01:00
7a7f386891 Is now using argparse library 2022-11-03 12:10:59 +01:00
Profitroll
11255bbbd0 Pagination fixed 2022-10-05 21:37:37 +02:00
Profitroll
8ae50a4f97 Low number of files in queue reminder 2022-10-05 21:36:59 +02:00
Profitroll
46e3665749 Small fix 2022-09-24 17:03:20 +02:00
Profitroll
0e14ca600f Changed some imports' paths 2022-09-18 18:27:25 +02:00
Profitroll
c4177d1575 Optimized imports 2022-09-18 18:27:13 +02:00
Profitroll
f0c333968b "locale_log" explanation added 2022-09-18 18:13:40 +02:00
Profitroll
dfc1e36f07 Logging has been improved 2022-09-18 18:10:41 +02:00
Profitroll
fc21983305 Fixed absence of "block" & "unblock" buttons 2022-09-16 20:42:58 +02:00
58c5429e5c Imports were a bit optimized 2022-08-31 14:31:24 +02:00
6e1de38da0 Changed bot "mode" behavior 2022-08-30 14:10:05 +02:00
5848bca40a Changed a bit more due to "modes" update 2022-08-30 14:03:11 +02:00
da97606bb4 Commented on_raw_update event 2022-08-30 14:01:12 +02:00
91a1d7e349 Logging now has debug and bot has various modes 2022-08-30 13:53:17 +02:00
366a1d9201 Main executable name changed 2022-08-30 13:51:24 +02:00
Profitroll
aca61b8c1a AttributeError handling in get_submission 2022-08-22 11:51:40 +02:00
Profitroll
404a46ec15 Merge branch 'master' of https://git.end-play.xyz/profitroll/TelegramPoster 2022-08-14 18:27:39 +02:00
Profitroll
2591d26349 Admin now also gets user commands 2022-08-14 18:27:35 +02:00
0fdb365bb2 Custom locales added to readme 2022-08-12 10:12:41 +02:00
Profitroll
d4a2145036 A few strings fixed 2022-08-11 20:39:03 +02:00
3cd33b4769 Filesize limit 2022-08-11 13:38:42 +02:00
dd9ca838f7 Logging made better part 2 2022-08-11 12:01:31 +02:00
617e14f680 Logging made better part 1 2022-08-11 11:37:24 +02:00
f4dca4164c Additional exceptions added 2022-08-11 11:27:17 +02:00
673ecaaab9 Admin config path changed 2022-08-11 10:24:57 +02:00
d1f2401f51 Some changes to index and admin behavior 2022-08-11 10:14:37 +02:00
4075ddf4a3 Using index for captions 2022-08-11 10:10:35 +02:00
42257304fa Mime types 2022-08-11 09:59:30 +02:00
f2487d66a4 "for" removed 2022-08-10 13:17:02 +02:00
1399842372 Link fix 2022-08-10 13:09:04 +02:00
e03c862a35 Locales 2022-08-10 13:08:15 +02:00
ac509194da Start command added 2022-08-09 15:12:18 +02:00
e38b67495b User blocking improved 2022-08-09 14:44:06 +02:00
e18af786cf Submission: stage 2 2022-08-09 13:50:59 +02:00
5d29bfeff4 Submission feature development started 2022-08-09 13:02:52 +02:00
91a65d9b49 Changed requirements-check procedure 2022-08-09 12:31:11 +02:00
a29fd26046 Added start scripts 2022-08-09 12:30:36 +02:00
71d1efa82b "--cleanup-index" reformation 2022-08-09 11:58:40 +02:00
e0ecf98443 Added "--cleanup-index" parameter 2022-08-09 11:56:01 +02:00
f790cafbef Cleanup and move-sent execution logging 2022-08-09 11:51:57 +02:00
a4904235af :) 2022-08-09 11:48:58 +02:00
2535c566a1 Made a useful README 2022-08-09 11:46:15 +02:00
9cac021854 Added --cleanup arg 2022-08-09 11:45:52 +02:00
45 changed files with 2911 additions and 315 deletions

21
.gitignore vendored
View File

@@ -152,18 +152,13 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/
# ---> VisualStudioCode # Custom
.vscode/* config.json
!.vscode/settings.json *.session
!.vscode/tasks.json *.session-journal
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code venv
.history/ venv_linux
venv_windows
# Built Visual Studio Code Extensions .vscode
*.vsix
# Project

20
.renovaterc Normal file
View File

@@ -0,0 +1,20 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
],
"baseBranches": [
"dev"
],
"packageRules": [
{
"matchUpdateTypes": [
"minor",
"patch",
"pin",
"digest"
],
"automerge": true
}
]
}

112
README.md
View File

@@ -1,2 +1,110 @@
# TelegramPoster <h1 align="center">TelegramPoster</h1>
This bot is used for one and only task - post pictures from my personal archive.
<p align="center">
<a href="https://git.end-play.xyz/profitroll/TelegramPoster/src/branch/master/LICENSE"><img alt="License: GPL" src="https://img.shields.io/badge/License-GPL-blue"></a>
<a href="https://git.end-play.xyz/profitroll/TelegramPoster"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</p>
> Шукаєш інструкцію українською? А вона [ось тут](https://git.end-play.xyz/profitroll/TelegramPoster/src/branch/master/README_uk.md) знаходиться)
This bot is used for one and only task - post pictures from my personal archive. Here's its source code so you can also host a bot and have fun with it. Just don't exepect it to be brilliant. It is not. But hey, you can always fork it ;)
## Dependencies
* [Python 3.8+](https://www.python.org) (3.9+ recommended)
* [MongoDB](https://www.mongodb.com)
* [PhotosAPI](https://git.end-play.xyz/profitroll/PhotosAPI)
Use [MongoDB's installation manual](https://www.mongodb.com/docs/manual/installation) and [Photos API's README](https://git.end-play.xyz/profitroll/PhotosAPI/src/branch/master/README.md).
Please note that Photos API also requires MongoDB so it makes sense to install and configure Mongo first.
## Installation
To make this bot run at first you need to have a Python interpreter, Photos API, MongoDB and optionally git (if you want to update using `git pull`). You can also ignore git and simply download source code, should also work fine. After that you're ready to go.
> In this README I assume that you're using default python in your
> system and your system's PATH contains it. If your default python
> is `python3` or for example `/home/user/.local/bin/python3.9` - use it instead.
> If it's non-standard executable path - you should also change
> it in scripts you will use (`loop.sh`, `loop.bat`, `start.sh` and `start.bat`).
1. Install MongoDB and Photos API:
1. Install MongoDB by following [official installation manual](https://www.mongodb.com/docs/manual/installation)
2. Install Photos API by following [Photos API's README](https://git.end-play.xyz/profitroll/PhotosAPI/src/branch/master/README.md)
2. Download the bot:
1. `git clone -b dev https://git.end-play.xyz/profitroll/TelegramPoster.git` (if you're using git)
2. `cd TelegramPoster`
3. Create virtual environment [Optional]:
1. Install virtualenv module: `pip install virtualenv`
2. Create venv: `python -m venv .venv`
3. Activate it using `source .venv/bin/activate` on Linux, `.venv\Scripts\activate.bat` in CMD or `.venv\Scripts\Activate.ps1` in PowerShell.
4. Install project's dependencies:
`python -m pip install -r requirements.txt`
Without installing those - bot cannot work at all.
5. Configure required keys with your favorite text editor:
1. Copy config file: `cp config_example.json config.json`
2. Open `config.json` using your favorite text editor. For example `nano config.json`, but you can also edit it with vim, mcedit, or Notepad/Notepad++ on Windows
3. Change `"bot.owner"`, `"bot.api_id"`, `"bot.api_hash"` and `"bot.bot_token"` keys' values.
If you don't know where to find bot_token and your id - here you can find some hints: [get bot token](https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token), [get your id](https://www.alphr.com/telegram-find-user-id), [get api_hash and api_id](https://core.telegram.org/api/obtaining_api_id).
6. Configure database and API:
1. Configure database:
1. Change database host and port in keys `"database.host"` and `"database.port"`. For default local installation those will be `127.0.0.1` and `27017` respectively
2. Change database name to the one you like in `"database.name"`. It will be automatically created on start
3. If you've changed user and password to access the db, you should also change `"database.user"` and `"database.password"` keys, otherwise leave them `null` (default).
2. Configure Photos API:
1. Change `"posting.api.address"` and `"posting.api.address_external"` to the ones your API server uses
2. Run your bot using `python main.py --create-user --create-album` to configure its new user and album. You can also use manual user and album creation described [in the wiki](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-API). You can also change username, password and album in`"posting.api"` to the user and album you have if you already have Photos API album and user set up. In that case you don't need to create a new one.
7. Add bot to the channel:
To use your bot of course you need to have a channel or group otherwise it makes no sense to have such a bot. [Here](https://stackoverflow.com/a/33497769) you can find a quick guide how to add your bot to a channel. After that simply set `"posting.channel"` to your channel's ID and `"posting.comments"` to comments group's ID.
8. Configure posting time:
To make your bot post random content you need to configure `"posting.time"` with a list of "DD:MM" formatted strings or use `"posting.interval"` formatted as "XdXhXmXs". To use interval instead of selected time, set `"posting.use_interval"` to `true`.
9. Good to go, run it!
Make sure MongoDB and Photos API are running and use `python main.py` to start the bot.
Or you can also use `.\start.bat` on Windows and `bash ./start.sh` on Linux.
Additionally there are `loop.sh` and `loop.bat` available if you want your bot to start again after being stopped or after using `/shutdown` command.
If you need any further instructions on how to configure your bot or you had any difficulties doing so - please use [wiki in this repository](https://git.end-play.xyz/profitroll/TelegramPoster/wiki) to get more detailed instructions.
## CLI arguments
Of course bot also has them. You can perform some actions with them.
* `--create-user` - create new API user. Requires config key `"posting.api.address"` to be set;
* `--create-album` - create new API album. Requires API address and user config (`"posting.api"`) to be complete.
Examples:
* `python main.py --create-user`
* `python main.py --create-user --create-album`
## Tips and improvements
* You may want to configure your bot to work as a systemd service instead. There's [a tutorial for that](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-Service) in the wiki.
## Localization
Bot is capable of using custom locales. There are some that are pre-installed (English and Ukrainian), however you can add your own locales too.
All localization files are located in the `locale`. Just copy locale file of your choice, name it in accordance to [IETF language tags](https://en.wikipedia.org/wiki/IETF_language_tag) (if you want your locale to be compatible with Telegram's locales) or define your own name. Save it as json and you're good to go. If you want to change default locale for messages - edit `"locale"` parameter in the `config.json`.
We recommend to only make changes to your custom locale. Or at least always have your backup of for example `en.json` as your fallback.

108
README_uk.md Normal file
View File

@@ -0,0 +1,108 @@
<h1 align="center">TelegramPoster</h1>
<p align="center">
<a href="https://git.end-play.xyz/profitroll/TelegramPoster/src/branch/master/LICENSE"><img alt="License: GPL" src="https://img.shields.io/badge/License-GPL-blue"></a>
<a href="https://git.end-play.xyz/profitroll/TelegramPoster"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</p>
Цей бот використовується для однієї-єдиної задачі - публікувати фотографії з мого особистого архіву. Ось його код, тож ви також можете запустити бота і погратися з ним самостійно. Тільки не очікуйте, що він буде ідеальним. Це не так. Але ви завжди можете його форкнути ;)
## Залежності
* [Python 3.8+](https://www.python.org) (рекомендується 3.9+)
* [MongoDB](https://www.mongodb.com)
* [PhotosAPI](https://git.end-play.xyz/profitroll/PhotosAPI)
Користуйтесь [інструкцією зі встановлення MongoDB](https://www.mongodb.com/docs/manual/installation) та [README Photos API](https://git.end-play.xyz/profitroll/PhotosAPI/src/branch/master/README.md).
Зверніть увагу, що Photos API також потребує MongoDB, тому має сенс спочатку встановити й налаштувати Mongo.
## Встановлення
Щоб запустити бота, вам потрібно мати інтерпретатор Python, Photos API, MongoDB і, за бажанням, git (якщо ви хочете оновлювати за допомогою `git pull`). Ви також можете проігнорувати git і просто завантажити вихідний код, це також повинно спрацювати. Після цього ви готові до роботи.
> У цьому README я припускаю, що ви використовуєте python за замовчуванням у вашій
> системі, і він міститься у вашому системному PATH. Якщо ваш python за замовчуванням
> це `python3` або, наприклад, `/home/user/.local/bin/python3.9` - використовуйте його.
> Якщо це нестандартний шлях до виконуваного файлу - вам також слід змінити
> його у скриптах, які ви будете використовувати (`loop.sh`, `loop.bat`, `start.sh` та `start.bat`).
1. Встановіть MongoDB та Photos API:
1. Встановіть MongoDB, дотримуючись [офіційного посібника зі встановлення](https://www.mongodb.com/docs/manual/installation)
2. Встановіть Photos API, дотримуючись [README Photos API](https://git.end-play.xyz/profitroll/PhotosAPI/src/branch/master/README.md)
2. Завантажте бота:
1. `git clone https://git.end-play.xyz/profitroll/TelegramPoster.git` (якщо ви використовуєте git)
2. `cd TelegramPoster`
3. Створіть віртуальне середовище [Необов'язково]:
1. Встановіть модуль virtualenv: `pip install virtualenv`
2. Створіть venv: `python -m venv .venv`
3. Активуйте його за допомогою `ource .venv/bin/activate` в Linux, `.venv\Scripts\activate.bat` в CMD або `.venv\Scripts\Activate.ps1` в PowerShell.
4. Встановіть залежності проекту:
`python -m pip install -r requirements.txt`.
Без їх встановлення бот не зможе працювати взагалі.
5. Налаштуйте необхідні ключі за допомогою вашого улюбленого текстового редактора:
1. Скопіюйте конфігураційний файл: `cp config_example.json config.json`
2. Відкрийте `config.json` за допомогою вашого улюбленого текстового редактора. Наприклад, `nano config.json`, але ви також можете відредагувати його за допомогою vim, mcedit або Notepad/Notepad++ на Windows
3. Змініть значення ключів `"bot.owner"`, `"bot.api_id"`, `"bot.api_hash"` і `"bot.bot_token"`.
Якщо ви не знаєте, де знайти bot_token і ваш id - тут ви можете знайти кілька підказок: [отримати токен бота](https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token), [отримати свій id](https://www.alphr.com/telegram-find-user-id), [отримати api_hash та api_id](https://core.telegram.org/api/obtaining_api_id).
6. Налаштування бази даних та API:
1. Налаштуйте базу даних:
1. Змініть хост і порт бази даних у ключах `"database.host"` і `"database.port"`. Для локальної установки за замовчуванням це будуть `127.0.0.1` і `27017` відповідно
2. Змініть ім'я бази даних в `"database.name"`. Вона буде автоматично створена при запуску
3. Якщо ви змінили користувача та пароль для доступу до бази даних, вам також слід змінити ключі `"database.user"` та `"database.password"`, інакше залиште їх `null` (за замовчуванням).
2. Налаштуйте Photos API:
1. Змініть `"posting.api.address"` та `"posting.api.address_external"` на ті, що використовує ваш сервер API
2. Запустіть бота за допомогою `python main.py --create-user --create-album`, щоб налаштувати нового користувача та альбом. Ви також можете скористатися ручним створенням користувача і альбому, описаним [у вікі](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-API). Ви також можете змінити ім'я користувача, пароль і альбом у `"posting.api"` на користувача і альбом, які у вас є, якщо у вас вже налаштовані альбом і користувач Photos API. У цьому випадку вам не потрібно створювати нові.
7. Додайте бота до каналу:
Щоб використовувати бота, вам, звичайно, потрібно мати канал або групу, інакше немає сенсу мати такого бота. [Тут](https://stackoverflow.com/a/33497769) ви можете знайти короткий посібник, як додати бота до каналу. Після цього просто встановіть `"posting.channel"` на ID вашого каналу і `"posting.comments"` на ID групи коментарів.
8. Налаштуйте час публікації:
Щоб ваш бот публікував випадковий контент, вам потрібно налаштувати `"posting.time"` зі списком рядків у форматі "ДД:ММ" або використовувати `"posting.interval"` у форматі "XdXhXmXs". Щоб використовувати інтервал замість вибраного часу, встановіть `"posting.use_interval"` у значення `true`.
9. Готово, запускайте!
Переконайтеся, що MongoDB і Photos API запущені і використовуйте `python main.py` для запуску бота.
Або ви також можете використовувати `.\start.bat` в Windows і `bash ./start.sh` в Linux.
Додатково доступні `loop.sh` і `loop.bat`, якщо ви хочете, щоб ваш бот запустився знову після зупинки або після використання команди `/shutdown`.
Якщо вам потрібні додаткові інструкції щодо налаштування бота або у вас виникли труднощі - скористайтеся [вікі в цьому репозиторії](https://git.end-play.xyz/profitroll/TelegramPoster/wiki), щоб отримати детальніші інструкції.
## CLI аргументи
Звичайно, бот також має CLI аргументи. За допомогою них можна виконувати деякі дії.
* `--create-user` - створити нового користувача API. Потребує встановленого конфігураційного ключа `"posting.api.address"`;
* `--create-album` - створити новий альбом API. Вимагає заповнених адреси API та конфігурації користувача (`"posting.api"`).
Приклади:
* `python main.py --create-user`
* `python main.py --create-user --create-album`
## Поради та покращення
* Можливо, ви захочете налаштувати бота для роботи як системну службу. У вікі є [сторінка з цього питання](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-Service).
## Локалізація
Бот може використовувати файли локалізації. Деякі з них встановлено за замовчуванням (англійська та українська), але ви також можете додавати свої власні.
Усі файли локалізації знаходяться у теці `locale`. Просто скопіюйте файл локалі за вашим вибором, назвіть його відповідно до [мовних кодів IETF](https://en.wikipedia.org/wiki/IETF_language_tag) (якщо ви хочете, щоб ваша локаль була сумісна з локалями Telegram) або дайте йому власну назву. Збережіть переклад у форматі json, і все буде готово. Якщо ви хочете змінити локаль за замовчуванням для повідомлень - відредагуйте параметр `"locale"` у файлі `config.json`.
Ми рекомендуємо вносити зміни лише у вашу власну локаль. Або, принаймні, завжди мати резервну копію, наприклад, `en.json` як запасний варіант.

View File

@@ -0,0 +1,8 @@
from enum import Enum
class SubmissionType(Enum):
DOCUMENT = "document"
VIDEO = "video"
# ANIMATION = "animation"
PHOTO = "photo"

63
classes/exceptions.py Normal file
View File

@@ -0,0 +1,63 @@
from typing import Any
class SubmissionUnavailableError(Exception):
pass
class SubmissionUploadError(Exception):
def __init__(self, file_path: str, status_code: int, content: Any) -> None:
self.status_code = status_code
self.content = content
super().__init__(
f"Could not upload photo '{file_path}' due to HTTP {self.status_code}: {self.content}"
)
class SubmissionDuplicatesError(Exception):
def __init__(self, file_path: str, duplicates: list) -> None:
self.duplicates = duplicates
super().__init__(
f"Found duplicates of a photo '{file_path}': {self.duplicates}"
)
class SubmissionUnsupportedError(Exception):
def __init__(self, file_path: str) -> None:
super().__init__(f"Type of file does not seem to be supported: '{file_path}'")
class UserCreationError(Exception):
def __init__(self, code: int, data: str) -> None:
self.code = code
self.data = data
super().__init__(
f"Could not create a new user. API returned HTTP {self.code} with content: {self.data}"
)
class UserCreationDuplicateError(Exception):
def __init__(self, username: str) -> None:
self.username = username
super().__init__(f"User '{self.username} already exists.'")
class AlbumCreationError(Exception):
def __init__(self, code: int, data: str) -> None:
self.code = code
self.data = data
super().__init__(
f"Could not create a new album. API returned HTTP {self.code} with content: {self.data}"
)
class AlbumCreationDuplicateError(Exception):
def __init__(self, name: str) -> None:
self.name = name
super().__init__(f"Album '{self.name} already exists.'")
class AlbumCreationNameError(Exception):
def __init__(self, data: dict) -> None:
self.data = data
super().__init__(data["detail"])

280
classes/pyroclient.py Normal file
View File

@@ -0,0 +1,280 @@
import contextlib
import logging
from datetime import datetime
from io import BytesIO
from os import makedirs, remove, sep
from pathlib import Path
from shutil import rmtree
from time import time
from traceback import format_exc
from typing import Dict, List, Tuple, Union
import aiofiles
from aiohttp import ClientSession
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from bson import ObjectId
from libbot import json_write
from libbot.i18n.sync import _
from libbot.pyrogram.classes import PyroClient
from photosapi_client.errors import UnexpectedStatus
from pyrogram.errors import bad_request_400
from pyrogram.types import Message, User
from pytimeparse.timeparse import timeparse
from ujson import dumps, loads
from classes.enums.submission_types import SubmissionType
from classes.exceptions import (
SubmissionDuplicatesError,
SubmissionUnavailableError,
SubmissionUnsupportedError,
)
from classes.pyrouser import PyroUser
from modules.api_client import (
BodyPhotoUpload,
BodyVideoUpload,
File,
Photo,
Video,
client,
photo_upload,
video_upload,
)
from modules.database import col_submitted, col_users
from modules.http_client import http_session
from modules.sender import send_content
logger = logging.getLogger(__name__)
class PyroClient(PyroClient):
def __init__(self, scheduler: AsyncIOScheduler):
super().__init__(locales_root=Path("locale"), scheduler=scheduler)
self.version: float = 0.3
self.owner: int = self.config["bot"]["owner"]
self.admins: List[int] = self.config["bot"]["admins"] + [
self.config["bot"]["owner"]
]
self.sender_session = ClientSession()
self.scopes_placeholders: Dict[str, int] = {
"owner": self.owner,
"comments": self.config["posting"]["comments"],
}
async def start(self):
await super().start()
if self.config["reports"]["update"]:
try:
async with ClientSession(
json_serialize=dumps,
) as http_session:
check_update = await http_session.get(
"https://git.end-play.xyz/api/v1/repos/profitroll/TelegramPoster/releases?page=1&limit=1"
)
response = await check_update.json()
if len(response) == 0:
raise ValueError("No bot releases on git found.")
if float(response[0]["tag_name"].replace("v", "")) > self.version:
logger.info(
"New version %s found (current %s)",
response[0]["tag_name"].replace("v", ""),
self.version,
)
await self.send_message(
self.owner,
self._(
"update_available",
"message",
).format(
response[0]["tag_name"],
response[0]["html_url"],
response[0]["body"],
),
)
else:
logger.info("No updates found, bot is up to date.")
except bad_request_400.PeerIdInvalid:
logger.warning(
"Could not send startup message to bot owner. Perhaps user has not started the bot yet."
)
except Exception as exp:
logger.exception("Update check failed due to %s: %s", exp, format_exc())
if self.config["mode"]["post"]:
if self.config["posting"]["use_interval"]:
self.scheduler.add_job(
send_content,
"interval",
seconds=timeparse(self.config["posting"]["interval"]),
args=[self, self.sender_session],
)
else:
for entry in self.config["posting"]["time"]:
dt_obj = datetime.strptime(entry, "%H:%M")
self.scheduler.add_job(
send_content,
"cron",
hour=dt_obj.hour,
minute=dt_obj.minute,
args=[self, self.sender_session],
)
async def stop(self):
makedirs(self.config["locations"]["cache"], exist_ok=True)
await json_write(
{"timestamp": time()},
Path(f"{self.config['locations']['cache']}/shutdown_time"),
)
await http_session.close()
await self.sender_session.close()
await super().stop()
async def submit_media(
self, id: str
) -> Tuple[Union[Message, None], Union[str, None]]:
db_entry = col_submitted.find_one({"_id": ObjectId(id)})
submission = None
if db_entry is None:
raise SubmissionUnavailableError()
if db_entry["temp"]["uuid"] is None:
try:
submission = await self.get_messages(
db_entry["user"], db_entry["telegram"]["msg_id"]
)
filepath = await self.download_media(
submission, file_name=self.config["locations"]["tmp"] + sep
)
except Exception as exp:
raise SubmissionUnavailableError() from exp
elif not Path(
f"{self.config['locations']['data']}/submissions/{db_entry['temp']['uuid']}/{db_entry['temp']['file']}",
).exists():
raise SubmissionUnavailableError()
else:
filepath = Path(
f"{self.config['locations']['data']}/submissions/{db_entry['temp']['uuid']}/{db_entry['temp']['file']}",
)
with contextlib.suppress(Exception):
submission = await self.get_messages(
db_entry["user"], db_entry["telegram"]["msg_id"]
)
async with aiofiles.open(str(filepath), "rb") as fh:
media_bytes = BytesIO(await fh.read())
try:
if db_entry["type"] == SubmissionType.PHOTO.value:
response = await photo_upload(
self.config["posting"]["api"]["album"],
client=client,
multipart_data=BodyPhotoUpload(
File(media_bytes, filepath.name, "image/jpeg")
),
ignore_duplicates=self.config["submission"]["allow_duplicates"],
compress=False,
caption="queue",
)
elif db_entry["type"] == SubmissionType.VIDEO.value:
response = await video_upload(
self.config["posting"]["api"]["album"],
client=client,
multipart_data=BodyVideoUpload(
File(media_bytes, filepath.name, "video/*")
),
caption="queue",
)
# elif db_entry["type"] == SubmissionType.ANIMATION.value:
# response = await video_upload(
# self.config["posting"]["api"]["album"],
# client=client,
# multipart_data=BodyVideoUpload(
# File(media_bytes, filepath.name, "video/*")
# ),
# caption="queue",
# )
except UnexpectedStatus as exp:
raise SubmissionUnsupportedError(str(filepath)) from exp
response_dict = (
{}
if not hasattr(response, "content")
else loads(response.content.decode("utf-8"))
)
if "duplicates" in response_dict and len(response_dict["duplicates"]) > 0:
duplicates = []
for index, duplicate in enumerate(response_dict["duplicates"]): # type: ignore
if response_dict["access_token"] is None:
duplicates.append(
f"`{duplicate['id']}`:\n{self.config['posting']['api']['address_external']}/photos/{duplicate['id']}"
)
else:
duplicates.append(
f"`{duplicate['id']}`:\n{self.config['posting']['api']['address_external']}/token/photo/{response_dict['access_token']}?id={index}"
)
raise SubmissionDuplicatesError(str(filepath), duplicates)
col_submitted.find_one_and_update(
{"_id": ObjectId(id)}, {"$set": {"done": True}}
)
try:
if db_entry["temp"]["uuid"] is not None:
rmtree(
Path(
f"{self.config['locations']['data']}/submissions/{db_entry['temp']['uuid']}",
),
ignore_errors=True,
)
else:
remove(str(filepath))
except (FileNotFoundError, NotADirectoryError):
logger.error("Could not delete '%s' on submission accepted", filepath)
return (
submission,
response.parsed.id if hasattr(response, "parsed") else response.id,
)
async def find_user(self, user: Union[int, User]) -> PyroUser:
"""Find User by it's ID or User object
### Args:
* user (`Union[int, User]`): ID or User object to extract ID from
### Returns:
* `PyroUser`: PyroUser object
"""
if (
col_users.find_one(
{"id": user.id if isinstance(user, User) else user}
) # type: ignore
is None
):
col_users.insert_one(
{
"id": user.id if isinstance(user, User) else user,
"locale": user.language_code if isinstance(user, User) else None,
"banned": False,
"cooldown": datetime(1970, 1, 1, 0, 0),
"subscription": {"expires": datetime(1970, 1, 1, 0, 0)},
}
) # type: ignore
db_record = col_users.find_one(
{"id": user.id if isinstance(user, User) else user}
) # type: ignore
return PyroUser(**db_record)

55
classes/pyrouser.py Normal file
View File

@@ -0,0 +1,55 @@
from dataclasses import dataclass
from datetime import datetime
from typing import Union
from bson import ObjectId
from libbot import config_get
from libbot.pyrogram.classes import PyroClient
from modules.database import col_users
@dataclass
class PyroUser:
"""Dataclass of DB entry of a user"""
_id: ObjectId
id: int
locale: Union[str, None]
banned: bool
cooldown: datetime
subscription: dict
async def update_locale(self, locale: str):
col_users.update_one({"_id": self._id}, {"$set": {"locale": locale}})
async def update_cooldown(self, time: datetime = datetime.now()):
col_users.update_one({"_id": self._id}, {"$set": {"cooldown": time}})
async def block(self) -> None:
"""Ban user from using command and submitting content."""
col_users.update_one({"_id": self._id}, {"$set": {"banned": True}})
async def unblock(self) -> None:
"""Allow user to use command and submit posts again."""
col_users.update_one({"_id": self._id}, {"$set": {"banned": False}})
async def is_limited(self, app: Union[PyroClient, None] = None) -> bool:
"""Check if user is on a cooldown after submitting something.
### Returns:
`bool`: Must be `True` if on the cooldown and `False` if not
"""
admins = (
app.admins
if app is not None
else (
await config_get("admins", "bot") + [await config_get("owner", "bot")]
)
)
return (datetime.now() - self.cooldown).total_seconds() < (
app.config["submission"]["timeout"]
if app is not None
else await config_get("timeout", "submission")
)

View File

@@ -1,55 +0,0 @@
{
"module": null,
"bot": {
"api_id": 0,
"api_hash": "",
"bot_token": ""
},
"reports": {
"admin": 0,
"sent": false,
"error": true,
"startup": true,
"shutdown": true
},
"locations": {
"data": "data",
"queue": "data/queue",
"sent": "data/sent",
"index": "data/index.json"
},
"posting": {
"channel": 0,
"silent": false,
"move_sent": false,
"extensions": {
"photo": [
"jpg",
"png",
"gif",
"jpeg"
],
"video": [
"mp4",
"avi",
"mkv",
"webm"
]
},
"time": [
"08:00",
"10:00",
"12:00",
"14:00",
"16:00",
"18:00",
"20:00",
"22:00"
]
},
"caption": {
"enabled": false,
"text": "sample text",
"link": null
}
}

204
config_example.json Normal file
View File

@@ -0,0 +1,204 @@
{
"locale": "en",
"bot": {
"owner": 0,
"admins": [],
"api_id": 0,
"api_hash": "",
"bot_token": "",
"max_concurrent_transmissions": 1,
"scoped_commands": true
},
"database": {
"user": null,
"password": null,
"host": "127.0.0.1",
"port": 27017,
"name": "tgposter"
},
"reports": {
"chat_id": "owner",
"sent": false,
"error": true,
"update": true,
"startup": true,
"shutdown": true
},
"mode": {
"post": true,
"submit": true
},
"logging": {
"size": 512,
"location": "logs"
},
"locations": {
"tmp": "tmp",
"data": "data",
"cache": "cache"
},
"disabled_plugins": [],
"posting": {
"channel": 0,
"comments": 0,
"silent": false,
"move_sent": false,
"use_interval": false,
"interval": "1h30m",
"submitted_caption": {
"enabled": true,
"ignore_admins": true,
"text": "#submitted"
},
"types": {
"photo": true,
"video": false
},
"extensions": {
"photo": [
"jpg",
"png",
"jpeg"
],
"video": [
"mp4",
"avi",
"mkv",
"webm",
"mov"
]
},
"time": [
"08:00",
"10:00",
"12:00",
"14:00",
"16:00",
"18:00",
"20:00",
"22:00"
],
"api": {
"address": "http://localhost:8054",
"address_external": "https://photos.domain.com",
"username": "",
"password": "",
"album": ""
}
},
"caption": {
"enabled": false,
"link": null,
"text": [
"sample text"
]
},
"submission": {
"timeout": 30,
"file_size": 15728640,
"tmp_size": 15728640,
"allow_duplicates": false,
"send_uploaded_id": false,
"require_confirmation": {
"users": true,
"admins": true
},
"mime_types": [
"image/png",
"image/jpeg",
"video/mp4",
"video/quicktime"
]
},
"commands": {
"start": {
"scopes": [
{
"name": "BotCommandScopeDefault"
},
{
"name": "BotCommandScopeChat",
"chat_id": "owner"
}
]
},
"rules": {
"scopes": [
{
"name": "BotCommandScopeDefault"
},
{
"name": "BotCommandScopeChat",
"chat_id": "owner"
}
]
},
"language": {
"scopes": [
{
"name": "BotCommandScopeDefault"
},
{
"name": "BotCommandScopeChat",
"chat_id": "owner"
}
]
},
"report": {
"scopes": [
{
"name": "BotCommandScopeChat",
"chat_id": "comments"
}
]
},
"forwards": {
"scopes": [
{
"name": "BotCommandScopeChat",
"chat_id": "owner"
}
]
},
"import": {
"scopes": [
{
"name": "BotCommandScopeChat",
"chat_id": "owner"
}
]
},
"export": {
"scopes": [
{
"name": "BotCommandScopeChat",
"chat_id": "owner"
}
]
},
"remove": {
"scopes": [
{
"name": "BotCommandScopeChat",
"chat_id": "owner"
}
]
},
"purge": {
"scopes": [
{
"name": "BotCommandScopeChat",
"chat_id": "owner"
}
]
},
"shutdown": {
"scopes": [
{
"name": "BotCommandScopeChat",
"chat_id": "owner"
}
]
}
}
}

View File

@@ -1,3 +0,0 @@
{
"sent": []
}

1
docs/config_api.md Normal file
View File

@@ -0,0 +1 @@
# Configuring API connection

1
docs/config_channel.md Normal file
View File

@@ -0,0 +1 @@
# Configuring channel and adding your bot

1
docs/config_posts.md Normal file
View File

@@ -0,0 +1 @@
# Configuring posts and duplicates checker

1
docs/config_systemd.md Normal file
View File

@@ -0,0 +1 @@
# Configuring as systemd service

1
docs/config_time.md Normal file
View File

@@ -0,0 +1 @@
# Configuring posting time

1
docs/updating.md Normal file
View File

@@ -0,0 +1 @@
# Updating your bot

105
locale/en.json Normal file
View File

@@ -0,0 +1,105 @@
{
"metadata": {
"flag": "🇬🇧",
"name": "English",
"codes": [
"en",
"en-US",
"en-GB"
]
},
"commands": {
"start": "Start using the bot",
"rules": "Photos submission rules",
"language": "Change bot's language",
"report": "Report this post",
"forwards": "Check post forwards",
"import": "Submit .zip archive with photos",
"export": "Get .zip archive with all photos",
"remove": "Delete photo by its ID",
"purge": "Completely purge bot's queue",
"shutdown": "Turn off the bot"
},
"message": {
"start": "Hi and welcome!\n\nYou can submit your pictures and videos here. We'll review and add them, if we like them. Make sure you send your stuff one at a time and have chosen media that corresponds to our rules.\n\nYou can also write something to us in the description field. We'll send it with the submission itself, if needed.\n\nAlso, make sure you follow the /rules of submission, otherwise your submission will be declined. In case of spam/abuse you may even be blocked.\n\nHave fun and happy submitting!",
"rules": "Photos submission rules:\n1. No porn, only erotics and aesthetics\n2. Nipples are semi-allowed, should be either veiled or barely visible\n3. Genitalia strictly prohibited, but labia prints on clothes or nice pubes/panties/butts - are fine\n4. Submitting russians is forbidden",
"shutdown": "Shutting down bot with pid `{0}`",
"startup": "Starting with pid `{0}`",
"startup_downtime_minutes": "Starting with pid `{0}` (was down for {1} m.)",
"startup_downtime_hours": "Starting with pid `{0}` (was down for {1} h.)",
"startup_downtime_days": "Starting with pid `{0}` (was down for {1} d.)",
"sub_yes": "✅ Submission approved and accepted",
"sub_yes_auto": "✅ Submission automatically accepted",
"sub_no": "❌ Submission reviewed and declined",
"sub_dup": "⚠️ Submission automatically declined because database already contains this photo",
"sub_blocked": "You were blocked and you can't submit media anymore.",
"sub_unblocked": "You were unblocked and you can now submit media.",
"sub_by": "\n\nSubmitted by:",
"sub_sent": "Media has been submitted.\nWe'll notify you whether it will be accepted or not soon.",
"sub_cooldown": "You can only submit 1 media per {0} seconds",
"sub_media_failed": "Could not upload submission to API. Please check logs for details.",
"sub_media_duplicates": "⚠️ Image duplicates found",
"sub_media_duplicates_list": "It seems like following image has duplicates in API's Db.\n\nNext files marked as similar:\n • {0}",
"document_too_large": "File you've sent is too large. Please submit files not bigger than {0} MB",
"mime_not_allowed": "File type not allowed. Please, consider using one of these: {0}",
"post_exception": "Could not send content due to `{0}`\n\nTraceback:\n```{1}```",
"post_invalid_pic": "⚠️ Error {0} while sending photo\n```python\n{1}\n```",
"api_queue_empty": "Could not send content: `Queue is empty or contains only unsupported files.`",
"api_queue_error": "Could not get photo from API's queue. Check the log above or API's errors to get more info.",
"post_low": "Low amount of content: `There are only {0} files left in the queue.`",
"api_creds_invalid": "Could not authorize API access. Please check whether provided in config file are valid and update them if they're not.",
"sub_wip": "Post submission is now WIP. It will be available again in a few days. Thank you for your patience.",
"sub_error": "⚠️ Could not upload this image due to bot error. Admins are advised.",
"sub_error_admin": "User {0} could not submit photo without additional confirmation due to:\n```\n{1}\n```",
"import_request": "Please send me a zip archive with your media to be imported. Use /cancel if you want to abort this operation.",
"import_ignored": "No response, aborting import.",
"import_abort": "Import aborted.",
"import_invalid_media": "File to import must be a zip archive. Aborting.",
"import_invalid_mime": "Provided file is not supported. Please send `application/zip`. Aborting.",
"import_too_big": "You archive is `{0} GiB` big, but system has only `{1} GiB` free. Unpacking may take even more space. Aborting.",
"import_downloading": "Downloading archive...",
"import_unpacking": "Unpacking archive...",
"import_unpack_error": "Could not unpack the archive\n\nException: {0}\n\nTraceback:\n```python\n{1}\n```",
"import_uploading": "Uploading archive contents...",
"import_upload_error_duplicate": "Could not upload `{0}` because there're duplicates on server.",
"import_upload_error_other": "Could not upload `{0}`. Probably disallowed filetype.",
"import_finished": "Import finished.",
"locale_choice": "Alright. Please choose the language using keyboard below.",
"remove_request": "Please send me an ID to delete. You might have it from upload dialog. Use /cancel if you want to abort this operation.",
"remove_ignored": "No response, aborting removal.",
"remove_abort": "Removal aborted.",
"remove_success": "Removed media with ID `{0}`.",
"remove_failure": "Could not remove media with ID `{0}`. Check if provided ID is correct and if it is - you can also check bot's log for details.",
"remove_kind": "Please choose the type of media to delete. Use /cancel if you want to abort this operation.",
"remove_unknown": "Unknown media type. It can only be \"{0}\" or \"{1}\".",
"update_available": "**New version found**\nThere's a newer version of a bot found. You can update your bot to [{0}]({1}) using command line of your host.\n\n**Release notes**\n{2}\n\nRead more about updating you bot on the [wiki page](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Updating-Instance).\n\nPlease not that you can also disable this notification by editing `reports.update` key of the config.",
"shutdown_confirm": "There are {0} unfinished users' contexts. If you turn off the bot, those will be lost. Please confirm shutdown using a button below.",
"report_sent": "We've notified admins about presumable violation. Thank you for cooperation.",
"report_received": "This message has been reported by **{0}** (@{1}, `{2}`)"
},
"button": {
"sub_yes": "✅ Accept",
"sub_yes_caption": "✅ Accept + 📝",
"sub_no": "❌ Deny",
"sub_block": "☠️ Block sender",
"sub_unblock": "🏳️ Unblock sender",
"post_view": "View in channel",
"accepted": "✅ Accepted",
"declined": "❌ Declined",
"shutdown": "Confirm shutdown",
"photo": "Photo",
"video": "Video"
},
"callback": {
"sub_yes": "✅ Submission approved",
"sub_no": "❌ Submission declined",
"sub_block": "User {0} has been blocked",
"sub_unblock": "User {0} has been unblocked",
"sub_msg_unavail": "Submission message no longer exist",
"sub_media_unavail": "Could not download submission",
"sub_done": "You've already decided what to do with submission",
"sub_duplicates_found": "There're duplicates in bot's database",
"locale_set": "Your language now is: {locale}",
"nothing": "🏁 This action is already finished"
}
}

104
locale/uk.json Normal file
View File

@@ -0,0 +1,104 @@
{
"metadata": {
"flag": "🇺🇦",
"name": "Українська",
"codes": [
"uk",
"uk-UA"
]
},
"commands": {
"start": "Почати користуватись ботом",
"rules": "Правила пропонування фото",
"language": "Змінити мову бота",
"report": "Поскаржитись на цей пост",
"forwards": "Переглянути репости",
"import": "Надати боту .zip архів з фотографіями",
"export": "Отримати .zip архів з усіма фотографіями",
"remove": "Видалити фото за його ID",
"purge": "Повністю видалити всю чергу бота",
"shutdown": "Вимкнути бота"
},
"message": {
"start": "Привіт і ласкаво просимо!\n\nТут можна пропонувати свої фотографії та відео. Ми переглянемо та додамо їх, якщо вони нам сподобаються. Переконайтеся, що ви надсилаєте свої матеріали по одному та вибираєте медіа, які відповідають нашим правилам.\n\nВи також можете написати нам щось у полі опису. За потреби ми надішлемо це разом із самим фото.\n\nКрім того, переконайтеся, що ви дотримуєтеся /rules (правил) подання, інакше вашу пропозицію буде відхилено. У разі спаму/зловживань вас можуть навіть заблокувати.\n\nГарного дня та щасливого надсилання!",
"rules": "Правила пропонування фото:\n1. Ніякого порно, тільки еротика та естетика\n2. Соски можна, але або завуальовані, або зовсім ледь помітні\n3. Геніталії суворо ні, а ось відбитки статевих губ на одязі або гарні лобочки/трусики/попки - без проблем\n4. Пропонувати русню заборонено",
"shutdown": "Вимкнення бота з підом `{0}`",
"startup": "Запуск бота з підом `{0}`",
"startup_downtime_minutes": "Запуск бота з підом `{0}` (лежав {1} хв.)",
"startup_downtime_hours": "Запуск бота з підом `{0}` (лежав {1} год.)",
"startup_downtime_days": "Запуск бота з підом `{0}` (лежав {1} дн.)",
"sub_yes": "✅ Подання схвалено та прийнято",
"sub_yes_auto": "✅ Подання автоматично прийнято",
"sub_no": "❌ Подання розглянуто та відхилено",
"sub_dup": "⚠️ Подання автоматично відхилено через наявність цього фото в базі даних",
"sub_blocked": "Вас заблокували, ви більше не можете надсилати медіафайли.",
"sub_unblocked": "Вас розблокували, тепер ви можете надсилати медіафайли.",
"sub_by": "\n\nПредставлено:",
"sub_sent": "Медіа-файл надіслано.\nСкоро ми повідомимо вас, чи буде його прийнято.",
"sub_cooldown": "Ви можете надсилати лише 1 медіафайл на {0} секунд",
"sub_media_failed": "Не вдалося завантажити подання на сервер. Перевірте логи для деталей.",
"sub_media_duplicates": "⚠️ Знайдено зображення-дублікати",
"sub_media_duplicates_list": "Здається, подане зображення має дублікати в базі даних.\n\nНаступні файли було відмічено як дуже схожі з поданням:\n • {0}",
"document_too_large": "Надісланий файл завеликий. Будь ласка, надсилайте файли не більше {0} Мб",
"mime_not_allowed": "Тип файлу не дозволений. Розгляньте можливість використання одного з цих: {0}",
"post_exception": "Не вдалося надіслати контент через `{0}`\n\nTraceback:\n```{1}```",
"post_invalid_pic": "⚠️ Помилка надсилання фото {0}\n```python\n{1}\n```",
"api_queue_empty": "Не вдалося надіслати контент: `Черга порожня або містить лише непідтримувані файли`.",
"api_queue_error": "Не вдалось отримати фото з черги API. Погляньте на логи вище а також на лог помилок API щоб дізнатись подробиці.",
"post_low": "Мала кількість контенту: `Залишилось всього {0} файлів в черзі.`",
"api_creds_invalid": "Не вдалося авторизувати запит до API. Будь ласка, перевірте чи дані авторизації в конфігураційному файлі вірні та оновіть їх, якщо це не так.",
"sub_wip": "Подання постів зараз знаходиться у розробці. Він буде знову доступний через кілька днів. Дякуємо за ваше терпіння.",
"sub_error": "⚠️ Не вдалось завантажити фото через помилку бота. Адміністрацію повідомлено.",
"sub_error_admin": "Користувач {0} не зміг надіслати фото без додаткової перевірки через помилку:\n```\n{1}\n```",
"import_request": "Будь ласка, надішліть zip-архів з медіа для імпортування. Використовуйте /cancel, якщо ви хочете перервати цю операцію.",
"import_ignored": "Немає відповіді, перериваємо імпорт.",
"import_abort": "Імпорт перервано.",
"import_invalid_media": "Файл для імпорту має бути zip-архівом. Перериваємо.",
"import_invalid_mime": "Наданий файл не підтримується. Будь ласка, надішліть `application/zip`. Перервано.",
"import_too_big": "Ваш архів має розмір `{0} GiB`, але система має лише `{1} GiB` вільних. Розпакування може зайняти значно більше місця. Перервано.",
"import_downloading": "Завантажуємо архів...",
"import_unpacking": "Розпаковуємо архів...",
"import_unpack_error": "Не вдалося розпакувати архів\n\nПомилка: {0}\n\nTraceback:\n```python\n{1}\n```",
"import_uploading": "Завантажуємо вміст архіву...",
"import_upload_error_duplicate": "Не вдалося завантажити `{0}`, оскільки на сервері є дублікати.",
"import_upload_error_other": "Не вдалося завантажити `{0}`. Ймовірно, заборонений тип файлу.",
"import_finished": "Імпорт завершено.",
"locale_choice": "Гаразд. Будь ласка, оберіть мову за допомогою клавіатури нижче.",
"remove_request": "Будь ласка, надішліть мені ID для видалення. Ви могли отримати його з діалогу завантаження. Використовуйте /cancel, якщо ви хочете перервати цю операцію.",
"remove_ignored": "Немає відповіді, перериваємо видалення.",
"remove_abort": "Видалення перервано.",
"remove_success": "Видалено медіа з ID `{0}`.",
"remove_failure": "Не вдалося видалити медіа з ID `{0}`. Перевірте, чи вказано правильний ID, і якщо він правильний, ви також можете переглянути логи бота для отримання більш детальної інформації.",
"remove_kind": "Будь ласка, оберіть тип контенту для видалення. Використовуйте /cancel, якщо ви хочете перервати цю операцію.",
"remove_unknown": "Невідомий тип контенту. Може бути тільки \"{0}\" або \"{1}\".",
"update_available": "**Знайдено нову версію**\nЗнайдено нову версію бота. Ви можете оновити бота до [{0}]({1}) за допомогою командного рядка вашого хосту.\n\n**Примітки до релізу**\n{2}\n\nДетальніше про оновлення бота можна знайти на [вікі-сторінці](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Updating-Instance).\n\nЗверніть увагу, що ви також можете вимкнути це сповіщення, відредагувавши ключ `reports.update` у конфігурації.",
"shutdown_confirm": "Існує {0} незавершених контекстів користувачів. Якщо ви вимкнете бота, вони будуть втрачені. Будь ласка, підтвердіть вимкнення за допомогою кнопки нижче.",
"report_sent": "Ми повідомили адміністрацію про потенційне порушення. Дякую за співпрацю.",
"report_received": "На це повідомлення було отримано скаргу від **{0}** (@{1}, `{2}`)"
},
"button": {
"sub_yes": "✅ Прийняти",
"sub_yes_caption": "✅ Прийняти + 📝",
"sub_no": "❌ Відхилити",
"sub_block": "☠️ Заблокувати відправника",
"sub_unblock": "🏳️ Розблокувати відправника",
"post_view": "Переглянути на каналі",
"accepted": "✅ Прийнято",
"declined": "❌ Відхилено",
"shutdown": "Підтвердити вимкнення",
"photo": "Фото",
"video": "Відео"
},
"callback": {
"sub_yes": "✅ Подання схвалено",
"sub_no": "❌ Подання відхилено",
"sub_block": "Користувача {0} заблоковано",
"sub_unblock": "Користувача {0} розблоковано",
"sub_msg_unavail": "Повідомлення більше не існує",
"sub_media_unavail": "Не вдалося завантажити подання",
"sub_done": "Ви вже обрали що зробити з цим поданням",
"sub_duplicates_found": "Знайдено дублікати в базі даних бота",
"locale_set": "Встановлено мову: {locale}",
"nothing": "🏁 Цю дію вже було завершено"
}
}

12
loop.bat Normal file
View File

@@ -0,0 +1,12 @@
@echo off
REM You can cd to your directory here, if you want
REM cd C:\Users\user\TelegramPoster
:start
python main.py
echo To completely stop TelegramPoster now, please press Ctrl+C during the countdown!
echo Restarting in 5 seconds...
Timeout /t 5
echo TelegramPoster has started!
goto start

17
loop.sh Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# You can cd to your directory here, if you want
# cd /home/user/TelegramPoster
while true
do
python main.py
echo "To completely stop TelegramPoster now, please press Ctrl+C during the countdown!"
echo "Restarting in:"
for i in 5 4 3 2 1
do
echo "$i..."
sleep 1
done
echo "TelegramPoster has started!"
done

200
main.py
View File

@@ -1,177 +1,43 @@
import os import contextlib
import random import logging
import shutil from os import getpid
import subprocess
import sys
from threading import Thread
import time
import traceback
import schedule
from modules.logging import logWrite from convopyro import Conversation
from modules.utils import configGet, jsonLoad, jsonSave
pid = os.getpid() # This import MUST be done earlier than PyroClient!
# Even if isort does not like it...
from modules.cli import *
if "--move-sent" in sys.argv: from classes.pyroclient import PyroClient
for entry in jsonLoad(configGet("index", "locations"))["sent"]: from modules.scheduler import scheduler
try:
shutil.move(configGet("queue", "locations")+os.sep+entry, configGet("sent", "locations")+os.sep+entry)
except FileNotFoundError:
logWrite(f"File '{entry}' is already moved or does not exist")
except Exception as exp:
logWrite(f"Could not move sent file '{entry}' to '{configGet('sent', 'locations')}' due to {exp}")
if "--cleanup" in sys.argv: logging.basicConfig(
for entry in jsonLoad(configGet("index", "locations"))["sent"]: level=logging.INFO,
try: format="%(name)s.%(funcName)s | %(levelname)s | %(message)s",
try: datefmt="[%X]",
os.remove(configGet("queue", "locations")+os.sep+entry) )
except FileNotFoundError:
pass
try:
os.remove(configGet("sent", "locations")+os.sep+entry)
except FileNotFoundError:
pass
except Exception as exp:
logWrite(f"Could not remove '{entry}' due to {exp}")
if "--norun" in sys.argv: logger = logging.getLogger(__name__)
logWrite("Argument --norun passed, not running the main script")
sys.exit() with contextlib.suppress(ImportError):
import uvloop
uvloop.install()
def main():
client = PyroClient(scheduler=scheduler)
Conversation(client)
try: try:
from pyrogram import Client, filters, idle # type: ignore client.run()
from pyrogram.types import ChatPermissions, ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton, BotCommand, BotCommandScopeChat # type: ignore
except ModuleNotFoundError:
print(f"Module pyrogram is not installed. Run 'pip3 install -r requirements.txt' and restart the program.", flush=True)
sys.exit()
app = Client("duptsiaposter", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))
def send_content():
try:
list_sent = jsonLoad(configGet("index", "locations"))
list_queue = os.listdir(configGet("queue", "locations"))
for file in list_queue:
if not file in list_sent["sent"]:
ext_match = False
for ext in configGet("photo", "posting", "extensions"):
if file.endswith(ext):
ext_match = True
ext_type = "photo"
break
for ext in configGet("video", "posting", "extensions"):
if file.endswith(ext):
ext_match = True
ext_type = "video"
break
if not ext_match:
list_queue.remove(file)
else:
list_queue.remove(file)
if len(list_queue) > 0:
candidate_file = random.choice(list_queue)
candidate = configGet("queue", "locations")+os.sep+candidate_file
else:
logWrite(f"Could not send content due to queue folder empty with allowed extensions")
if configGet("error", "reports"):
app.send_message(configGet("admin", "reports"), f"Could not send content: `Queue folder is empty or contains only unsupported or already sent files.`") # type: ignore
return
if ext_type == "photo": # type: ignore
if configGet("enabled", "caption"):
if configGet("link", "caption") != None:
sent = app.send_photo(configGet("channel", "posting"), candidate, caption=f"[{configGet('text', 'caption')}]({configGet('link', 'caption')})", disable_notification=configGet("silent", "posting")) # type: ignore
else:
sent = app.send_photo(configGet("channel", "posting"), candidate, caption=configGet('text', 'caption'), disable_notification=configGet("silent", "posting")) # type: ignore
else:
sent = app.send_photo(configGet("channel", "posting"), candidate, disable_notification=configGet("silent", "posting")) # type: ignore
elif ext_type == "video": # type: ignore
if configGet("enabled", "caption"):
if configGet("link", "caption") != None:
sent = app.send_video(configGet("channel", "posting"), candidate, caption=f"[{configGet('text', 'caption')}]({configGet('link', 'caption')})", disable_notification=configGet("silent", "posting")) # type: ignore
else:
sent = app.send_video(configGet("channel", "posting"), candidate, caption=configGet('text', 'caption'), disable_notification=configGet("silent", "posting")) # type: ignore
else:
sent = app.send_video(configGet("channel", "posting"), candidate, disable_notification=configGet("silent", "posting")) # type: ignore
list_sent["sent"].append(candidate_file)
jsonSave(list_sent, configGet("index", "locations"))
if configGet("move_sent", "posting"):
shutil.move(candidate, configGet("sent", "locations")+os.sep+candidate_file)
if configGet("sent", "reports"):
app.send_message(configGet("admin", "reports"), f"Posted `{candidate_file}`", disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("View in channel", url=sent.link)] # type: ignore
])) # type: ignore
except Exception as exp:
logWrite(f"Could not send content due to {exp}")
if configGet("error", "reports"):
app.send_message(configGet("admin", "reports"), f"Could not send content due to `{exp}`\n\nTraceback:\n```{traceback.format_exc()}```") # type: ignore
@app.on_message(~ filters.scheduled & filters.command(["kill", "die", "reboot"], prefixes=["", "/"]))
def kill(app, msg):
if msg.from_user.id == configGet("admin", "reports"):
msg.reply_text(f"Shutting down bot with pid `{pid}`")
os.system('kill -9 '+str(pid))
for entry in configGet("time", "posting"):
schedule.every().day.at(entry).do(send_content)
def background_task():
try:
while True:
try:
schedule.run_pending()
time.sleep(1)
except:
pass
except Exception as exp:
logWrite(f"Exception {exp} happened on task execution")
except KeyboardInterrupt: except KeyboardInterrupt:
logWrite('\nShutting down...') logger.warning("Forcefully shutting down with PID %s...", getpid())
app.send_message(configGet("admin", "reports"), f"Shutting down with PID `{pid}`") # type: ignore finally:
os.system('kill -9 '+str(pid)) if client.scheduler is not None:
client.scheduler.shutdown()
exit()
if __name__ == "__main__": if __name__ == "__main__":
main()
logWrite(f'Starting with PID {pid}')
app.start() # type: ignore
app.send_message(configGet("admin", "reports"), f"Starting with pid `{pid}`") # type: ignore
t = Thread(target=background_task)
t.start()
app.set_bot_commands([ # type: ignore
BotCommand("reboot", "Reboot the bot"),
],
scope=BotCommandScopeChat(chat_id=configGet("admin", "reports")))
idle()
app.send_message(configGet("admin", "reports"), f"Shutting down with pid `{pid}`") # type: ignore
logWrite(f'Shutting down with PID {pid}')
subprocess.call(f'kill -9 {pid}', shell=True) # type: ignore

153
modules/api_client.py Normal file
View File

@@ -0,0 +1,153 @@
import asyncio
import logging
from base64 import b64decode, b64encode
from os import makedirs, path, sep
from pathlib import Path
from typing import Union
import aiofiles
from aiohttp import ClientSession
from libbot import config_get, i18n, sync
from photosapi_client import AuthenticatedClient, Client
from photosapi_client.api.default.album_create_albums_post import (
asyncio as album_create,
)
from photosapi_client.api.default.album_delete_album_id_delete import (
asyncio as album_delete,
)
from photosapi_client.api.default.album_find_albums_get import asyncio as album_find
from photosapi_client.api.default.login_for_access_token_token_post import sync as login
from photosapi_client.api.default.photo_delete_photos_id_delete import (
asyncio as photo_delete,
)
from photosapi_client.api.default.photo_find_albums_album_photos_get import (
asyncio as photo_find,
)
from photosapi_client.api.default.photo_get_photos_id_get import asyncio as photo_get
from photosapi_client.api.default.photo_patch_photos_id_patch import (
asyncio as photo_patch,
)
from photosapi_client.api.default.photo_random_albums_album_photos_random_get import (
asyncio as photo_random,
)
from photosapi_client.api.default.photo_upload_albums_album_photos_post import (
asyncio_detailed as photo_upload,
)
from photosapi_client.api.default.user_create_users_post import asyncio as user_create
from photosapi_client.api.default.user_me_users_me_get import sync as user_me
from photosapi_client.api.default.video_delete_videos_id_delete import (
asyncio as video_delete,
)
from photosapi_client.api.default.video_find_albums_album_videos_get import (
asyncio as video_find,
)
from photosapi_client.api.default.video_get_videos_id_get import asyncio as video_get
from photosapi_client.api.default.video_patch_videos_id_patch import (
asyncio as video_patch,
)
from photosapi_client.api.default.video_random_albums_album_videos_random_get import (
asyncio as video_random,
)
from photosapi_client.api.default.video_upload_albums_album_videos_post import (
asyncio as video_upload,
)
from photosapi_client.models.body_login_for_access_token_token_post import (
BodyLoginForAccessTokenTokenPost,
)
from photosapi_client.models.body_photo_upload_albums_album_photos_post import (
BodyPhotoUploadAlbumsAlbumPhotosPost as BodyPhotoUpload,
)
from photosapi_client.models.body_video_upload_albums_album_videos_post import (
BodyVideoUploadAlbumsAlbumVideosPost as BodyVideoUpload,
)
from photosapi_client.models.http_validation_error import HTTPValidationError
from photosapi_client.models.photo import Photo
from photosapi_client.models.photo_search import PhotoSearch
from photosapi_client.models.token import Token
from photosapi_client.models.video import Video
from photosapi_client.models.video_search import VideoSearch
from photosapi_client.types import File
from modules.http_client import http_session
logger = logging.getLogger(__name__)
async def authorize(custom_session: Union[ClientSession, None] = None) -> str:
makedirs(await config_get("cache", "locations"), exist_ok=True)
session = http_session if custom_session is None else custom_session
if path.exists(await config_get("cache", "locations") + sep + "api_access") is True:
async with aiofiles.open(
await config_get("cache", "locations") + sep + "api_access", "rb"
) as file:
token = b64decode(await file.read()).decode("utf-8")
if (
await session.get(
await config_get("address", "posting", "api") + "/users/me/",
headers={"Authorization": f"Bearer {token}"},
)
).status == 200:
return token
payload = {
"grant_type": "password",
"scope": "me albums.list albums.read albums.write photos.list photos.read photos.write videos.list videos.read videos.write",
"username": await config_get("username", "posting", "api"),
"password": await config_get("password", "posting", "api"),
}
response = await session.post(
await config_get("address", "posting", "api") + "/token", data=payload
)
if not response.ok:
logger.warning(
"Incorrect API credentials! Could not login into '%s' using login '%s': HTTP %s",
await config_get("address", "posting", "api"),
await config_get("username", "posting", "api"),
response.status,
)
raise ValueError
async with aiofiles.open(
str(Path(f"{await config_get('cache', 'locations')}/api_access")),
"wb",
) as file:
await file.write(
b64encode((await response.json())["access_token"].encode("utf-8"))
)
return (await response.json())["access_token"]
unauthorized_client = Client(
base_url=sync.config_get("address", "posting", "api"),
timeout=5.0,
verify_ssl=True,
raise_on_unexpected_status=True,
follow_redirects=False,
)
login_token = login(
client=unauthorized_client,
form_data=BodyLoginForAccessTokenTokenPost(
grant_type="password",
scope="me albums.list albums.read albums.write photos.list photos.read photos.write videos.list videos.read videos.write",
username=sync.config_get("username", "posting", "api"),
password=sync.config_get("password", "posting", "api"),
),
)
if not isinstance(login_token, Token):
logger.warning(
"Could not initialize connection due to invalid token: %s", login_token
)
exit()
client = AuthenticatedClient(
base_url=sync.config_get("address", "posting", "api"),
timeout=5.0,
verify_ssl=True,
raise_on_unexpected_status=True,
token=login_token.access_token,
follow_redirects=False,
)
if __name__ == "__main__":
print(asyncio.run(authorize()))

118
modules/cli.py Normal file
View File

@@ -0,0 +1,118 @@
import asyncio
from argparse import ArgumentParser
from sys import exit
from traceback import print_exc
from libbot import config_get, config_set, sync
from photosapi_client.api.default.album_create_albums_post import (
asyncio as album_create,
)
from photosapi_client.api.default.login_for_access_token_token_post import (
asyncio as login,
)
from photosapi_client.api.default.user_create_users_post import asyncio as user_create
from photosapi_client.client import AuthenticatedClient, Client
from photosapi_client.models.body_login_for_access_token_token_post import (
BodyLoginForAccessTokenTokenPost,
)
from photosapi_client.models.body_user_create_users_post import BodyUserCreateUsersPost
parser = ArgumentParser(
prog="Telegram Poster",
description="Bot for posting some of your stuff and also receiving submissions.",
)
parser.add_argument("--create-user", action="store_true")
parser.add_argument("--create-album", action="store_true")
args = parser.parse_args()
if args.create_user or args.create_album:
unauthorized_client = Client(
base_url=sync.config_get("address", "posting", "api"),
timeout=5.0,
verify_ssl=True,
raise_on_unexpected_status=True,
follow_redirects=False,
)
async def cli_create_user() -> None:
print(
"To set up Photos API connection you need to create a new user.\nIf you have email confirmation enabled in your Photos API config - you need to use a real email that will get a confirmation code afterwards.",
flush=True,
)
username = input("Choose username for new Photos API user: ").strip()
email = input(f"Choose email for user '{username}': ").strip()
password = input(f"Choose password for user '{username}': ").strip()
try:
result_1 = await user_create(
client=unauthorized_client,
form_data=BodyUserCreateUsersPost(
user=username, email=email, password=password
),
)
# asyncio.run(create_user(username, email, password))
await config_set("username", username, "posting", "api")
await config_set("password", password, "posting", "api")
none = input(
"Alright. If you have email confirmation enabled - please confirm registration by using the link in your email. After that press Enter. Otherwise just press Enter."
)
except Exception as exp:
print(f"Could not create a user due to {exp}", flush=True)
print_exc()
exit()
if not args.create_album:
print("You're done!", flush=True)
exit()
return None
async def cli_create_album() -> None:
print(
"To use Photos API your user needs to have an album to store its data.\nThis wizard will help you to create a new album with its name and title.",
flush=True,
)
name = input("Choose a name for your album: ").strip()
title = input(f"Choose a title for album '{name}': ").strip()
try:
login_token = await login(
client=unauthorized_client,
form_data=BodyLoginForAccessTokenTokenPost(
grant_type="password",
scope="me albums.list albums.read albums.write photos.list photos.read photos.write videos.list videos.read videos.write",
username=await config_get("username", "posting", "api"),
password=await config_get("password", "posting", "api"),
),
)
client = AuthenticatedClient(
base_url=await config_get("address", "posting", "api"),
timeout=5.0,
verify_ssl=True,
raise_on_unexpected_status=True,
token=login_token.access_token,
follow_redirects=False,
)
result_2 = await album_create(client=client, name=name, title=title)
# asyncio.run(create_album(name, title))
await config_set("album", name, "posting", "api")
except Exception as exp:
print(f"Could not create an album due to {exp}", flush=True)
print_exc()
exit()
print("You're done!", flush=True)
exit()
if args.create_user or args.create_album:
loop = asyncio.get_event_loop()
tasks = []
if args.create_user:
loop.run_until_complete(asyncio.wait([loop.create_task(cli_create_user())]))
if args.create_album:
loop.run_until_complete(asyncio.wait([loop.create_task(cli_create_album())]))
loop.close()

View File

@@ -1,22 +0,0 @@
RESET = '\u001b[0m'
BLACK = '\u001b[30m'
RED = '\u001b[31m'
GREEN = '\u001b[32m'
YELLOW = '\u001b[33m'
BLUE = '\u001b[34m'
MAGENTA = '\u001b[35m'
CYAN = '\u001b[36m'
WHITE = '\u001b[37m'
BBLACK = '\u001b[30;1m'
BRED = '\u001b[31;1m'
BGREEN = '\u001b[32;1m'
BYELLOW = '\u001b[33;1m'
BBLUE = '\u001b[34;1m'
BMAGENTA = '\u001b[35;1m'
BCYAN = '\u001b[36;1m'
BWHITE = '\u001b[37;1m'
ULINE = '\u001b[4m'
REVERSE = '\u001b[7m'

34
modules/database.py Normal file
View File

@@ -0,0 +1,34 @@
"""Module that provides all database columns"""
from pymongo import MongoClient
from ujson import loads
with open("config.json", "r", encoding="utf-8") as f:
db_config = loads(f.read())["database"]
f.close()
if db_config["user"] is not None and db_config["password"] is not None:
con_string = "mongodb://{0}:{1}@{2}:{3}/{4}".format(
db_config["user"],
db_config["password"],
db_config["host"],
db_config["port"],
db_config["name"],
)
else:
con_string = "mongodb://{0}:{1}/{2}".format(
db_config["host"], db_config["port"], db_config["name"]
)
db_client = MongoClient(con_string)
db = db_client.get_database(name=db_config["name"])
collections = db.list_collection_names()
for collection in ["sent", "users", "submitted"]:
if collection not in collections:
db.create_collection(collection)
col_sent = db.get_collection("sent")
col_users = db.get_collection("users")
col_submitted = db.get_collection("submitted")

6
modules/http_client.py Normal file
View File

@@ -0,0 +1,6 @@
from aiohttp import ClientSession
from ujson import dumps
http_session = ClientSession(
json_serialize=dumps,
)

View File

@@ -1,4 +0,0 @@
def logWrite(message):
# save to log file and rotation is to be done
# logAppend(f"[{nowtime()}] {message}", flush=True)
print(f"{message}", flush=True)

3
modules/scheduler.py Normal file
View File

@@ -0,0 +1,3 @@
from apscheduler.schedulers.asyncio import AsyncIOScheduler
scheduler = AsyncIOScheduler()

270
modules/sender.py Normal file
View File

@@ -0,0 +1,270 @@
import logging
from datetime import datetime
from os import makedirs, path
from random import choice, sample
from shutil import rmtree
from traceback import format_exc, print_exc
from typing import Union
from uuid import uuid4
import aiofiles
from aiohttp import ClientSession
from libbot.pyrogram.classes import PyroClient
from photosapi_client.errors import UnexpectedStatus
from PIL import Image
from modules.api_client import (
File,
PhotoSearch,
VideoSearch,
authorize,
client,
photo_get,
photo_patch,
photo_random,
video_get,
video_patch,
video_random,
)
from modules.database import col_sent, col_submitted
logger = logging.getLogger(__name__)
async def send_content(app: PyroClient, http_session: ClientSession) -> None:
try:
try:
token = await authorize(http_session)
except ValueError:
await app.send_message(
app.owner,
app._("api_creds_invalid", "message"),
)
return
try:
funcs = []
if app.config["posting"]["types"]["photo"]:
funcs.append((photo_random, photo_get, app.send_photo, photo_patch))
if app.config["posting"]["types"]["video"]:
funcs.append((video_random, video_get, app.send_video, video_patch))
if not funcs:
raise KeyError(
"No media source provided: all seem to be disabled in config"
)
if len(funcs) > 1:
found = False
for func_iter in sample(funcs, len(funcs)):
func = func_iter
random_results = (
await func_iter[0](
album=app.config["posting"]["api"]["album"],
caption="queue",
client=client,
limit=1,
)
).results
if not random_results:
continue
media: Union[PhotoSearch, VideoSearch] = random_results[0]
try:
response: File = await func_iter[1](id=media.id, client=client)
except Exception as exp:
print_exc()
logger.error("Media is invalid: %s", exp)
if app.config["reports"]["error"]:
await app.send_message(
app.owner, f"Media is invalid: {exp}"
)
return
found = True
break
if not found:
raise KeyError("No media found")
else:
func = funcs[0]
media: Union[PhotoSearch, VideoSearch] = (
await func[0](
album=app.config["posting"]["api"]["album"],
caption="queue",
client=client,
limit=1,
)
).results[0]
try:
response: File = await func[1](id=media.id, client=client)
except Exception as exp:
print_exc()
logger.error("Media is invalid: %s", exp)
if app.config["reports"]["error"]:
await app.send_message(app.owner, f"Media is invalid: {exp}")
return
except (KeyError, AttributeError, TypeError, IndexError):
logger.info(
"Could not send content due to queue empty or contains only forbidden extensions"
)
if app.config["reports"]["error"]:
await app.send_message(
app.owner,
app._("api_queue_empty", "message"),
)
return
except (ValueError, UnexpectedStatus):
if app.config["reports"]["error"]:
await app.send_message(
app.owner,
app._("api_queue_error", "message"),
)
return
tmp_dir = str(uuid4())
makedirs(path.join(app.config["locations"]["tmp"], tmp_dir), exist_ok=True)
tmp_path = path.join(tmp_dir, media.filename)
async with aiofiles.open(
path.join(app.config["locations"]["tmp"], tmp_path), "wb"
) as out_file:
await out_file.write(response.payload.read())
logger.info(
"Candidate %s (%s) is %s bytes big",
media.filename,
media.id,
path.getsize(path.join(app.config["locations"]["tmp"], tmp_path)),
)
if (
path.getsize(path.join(app.config["locations"]["tmp"], tmp_path)) > 5242880
) and func[0] is photo_random:
image = Image.open(path.join(app.config["locations"]["tmp"], tmp_path))
width, height = image.size
image = image.resize((int(width / 2), int(height / 2)), Image.ANTIALIAS)
if tmp_path.lower().endswith(".jpeg") or tmp_path.lower().endswith(".jpg"):
image.save(
path.join(app.config["locations"]["tmp"], tmp_path),
"JPEG",
optimize=True,
quality=50,
)
elif tmp_path.lower().endswith(".png"):
image.save(
path.join(app.config["locations"]["tmp"], tmp_path),
"PNG",
optimize=True,
compress_level=8,
)
image.close()
if (
path.getsize(path.join(app.config["locations"]["tmp"], tmp_path)) > 5242880
) and func[0] is photo_random:
rmtree(
path.join(app.config["locations"]["tmp"], tmp_dir), ignore_errors=True
)
raise BytesWarning
del response
submitted = col_submitted.find_one({"temp.file": media.filename})
if submitted is not None and submitted["caption"] is not None:
caption = submitted["caption"].strip()
else:
caption = ""
if (
submitted is not None
and app.config["posting"]["submitted_caption"]["enabled"]
and (
(submitted["user"] not in app.admins)
or (
app.config["posting"]["submitted_caption"]["ignore_admins"] is False
)
)
):
caption = (
f"{caption}\n\n{app.config['posting']['submitted_caption']['text']}\n"
)
else:
caption = f"{caption}\n\n"
if app.config["caption"]["enabled"]:
if app.config["caption"]["link"] is not None:
caption = f"{caption}[{choice(app.config['caption']['text'])}]({app.config['caption']['link']})"
else:
caption = f"{caption}{choice(app.config['caption']['text'])}"
else:
caption = caption
try:
sent = await func[2](
app.config["posting"]["channel"],
path.join(app.config["locations"]["tmp"], tmp_path),
caption=caption,
disable_notification=app.config["posting"]["silent"],
)
except Exception as exp:
logger.error(
"Could not send media %s (%s) due to %s", media.filename, media.id, exp
)
if app.config["reports"]["error"]:
await app.send_message(
app.owner,
app._("post_exception", "message").format(exp, format_exc()),
)
# rmtree(path.join(app.config['locations']['tmp'], tmp_dir), ignore_errors=True)
return
col_sent.insert_one(
{
"date": datetime.now(),
"image": media.id,
"filename": media.filename,
"channel": app.config["posting"]["channel"],
"caption": None
if (submitted is None or submitted["caption"] is None)
else submitted["caption"].strip(),
}
)
await func[3](id=media.id, client=client, caption="sent")
rmtree(path.join(app.config["locations"]["tmp"], tmp_dir), ignore_errors=True)
logger.info(
"Sent %s to %s with caption %s and silently %s",
media.id,
str(app.config["posting"]["channel"]),
caption.replace("\n", "%n"),
str(app.config["posting"]["silent"]),
)
except Exception as exp:
logger.error(
"Could not send content due to %s. Traceback: %s", exp, format_exc()
)
if app.config["reports"]["error"]:
await app.send_message(
app.owner,
app._("post_exception", "message").format(exp, format_exc()),
)
try:
rmtree(
path.join(app.config["locations"]["tmp"], tmp_dir), ignore_errors=True
)
except:
pass

View File

@@ -1,54 +1,33 @@
import logging
from os import makedirs, path
from pathlib import Path
from typing import List, Union
from zipfile import ZipFile
import aiofiles
logger = logging.getLogger(__name__)
USERS_WITH_CONTEXT: List[int] = []
async def extract_and_save(handle: ZipFile, filename: str, destpath: Union[str, Path]):
"""Extract and save file from archive
### Args:
* handle (`ZipFile`): ZipFile handler
* filename (`str`): File base name
* path (`Union[str, Path]`): Path where to store
"""
data = handle.read(filename)
filepath = path.join(str(destpath), filename)
try: try:
import ujson as json makedirs(path.dirname(filepath), exist_ok=True)
except ModuleNotFoundError: async with aiofiles.open(filepath, "wb") as fd:
import json await fd.write(data)
logger.debug("Unzipped %s", filename)
except IsADirectoryError:
makedirs(filepath, exist_ok=True)
def jsonLoad(filename): except FileNotFoundError:
"""Loads arg1 as json and returns its contents""" pass
with open(filename, "r", encoding='utf8') as file:
output = json.loads(file.read())
file.close()
return output
def jsonSave(contents, filename):
"""Dumps dict/list arg1 to file arg2"""
with open(filename, "w", encoding='utf8') as file:
file.write(json.dumps(contents, ensure_ascii=False, indent=4))
file.close()
return return
def configSet(key: str, value, *args: str):
"""Set key to a value
Args:
* key (str): The last key of the keys path.
* value (str/int/float/list/dict/None): Some needed value.
* *args (str): Path to key like: dict[args][key].
"""
this_dict = jsonLoad("config.json")
string = "this_dict"
for arg in args:
string += f'["{arg}"]'
if type(value) in [str]:
string += f'["{key}"] = "{value}"'
else:
string += f'["{key}"] = {value}'
exec(string)
jsonSave(this_dict, "config.json")
return
def configGet(key: str, *args: str):
"""Get value of the config key
Args:
* key (str): The last key of the keys path.
* *args (str): Path to key like: dict[args][key].
Returns:
* any: Value of provided key
"""
this_dict = jsonLoad("config.json")
this_key = this_dict
for dict_key in args:
this_key = this_key[dict_key]
return this_key[key]

View File

@@ -0,0 +1,12 @@
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import CallbackQuery
from classes.pyroclient import PyroClient
@Client.on_callback_query(filters.regex("nothing"))
async def callback_query_nothing(app: PyroClient, clb: CallbackQuery):
user = await app.find_user(clb.from_user)
await clb.answer(text=app._("nothing", "callback", locale=user.locale))

View File

@@ -0,0 +1,25 @@
from os import makedirs, path
from time import time
from libbot import config_get, json_write
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import CallbackQuery
from classes.pyroclient import PyroClient
@Client.on_callback_query(filters.regex("shutdown"))
async def callback_query_nothing(app: PyroClient, clb: CallbackQuery):
if clb.from_user.id not in app.admins:
return
await clb.answer()
makedirs(await config_get("cache", "locations"), exist_ok=True)
await json_write(
{"timestamp": time()},
path.join(await config_get("cache", "locations"), "shutdown_time"),
)
exit()

View File

@@ -0,0 +1,266 @@
import logging
from os import path
from pathlib import Path
from shutil import rmtree
from bson import ObjectId
from libbot import config_get
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup
from classes.exceptions import (
SubmissionDuplicatesError,
SubmissionUnavailableError,
SubmissionUnsupportedError,
)
from classes.pyroclient import PyroClient
from modules.database import col_submitted
logger = logging.getLogger(__name__)
@Client.on_callback_query(filters.regex("sub_yes_[\s\S]*"))
async def callback_query_yes(app: PyroClient, clb: CallbackQuery):
user = await app.find_user(clb.from_user)
fullclb = str(clb.data).split("_")
db_entry = col_submitted.find_one({"_id": ObjectId(fullclb[2])})
try:
submission = await app.submit_media(fullclb[2])
except SubmissionUnavailableError:
await clb.answer(
text=app._("sub_msg_unavail", "callback", locale=user.locale),
show_alert=True,
)
return
except SubmissionUnsupportedError:
await clb.answer(
text=app._("mime_not_allowed", "message", locale=user.locale).format(
", ".join(app.config["submission"]["mime_types"]), quote=True
),
show_alert=True,
)
return
except SubmissionDuplicatesError as exp:
await clb.answer(
text=app._("sub_duplicates_found", "callback", locale=user.locale),
show_alert=True,
)
await clb.message.reply_text(
app._("sub_media_duplicates_list", "message", locale=user.locale).format(
"\n".join(exp.duplicates)
),
quote=True,
)
logger.info(
"Submission with ID '%s' could not be accepted because of the duplicates: %s",
fullclb[2],
str(exp.duplicates),
)
return
if submission[0] is not None:
await submission[0].reply_text(
app._(
"sub_yes",
"message",
locale=(await app.find_user(submission[0].from_user)).locale,
),
quote=True,
)
elif db_entry is not None:
await app.send_message(
db_entry["user"],
app._(
"sub_yes",
"message",
locale=(await app.find_user(db_entry["user"])).locale,
),
)
await clb.answer(
text=app._("sub_yes", "callback", locale=user.locale).format(fullclb[2]),
show_alert=True,
)
edited_markup = (
[
[
InlineKeyboardButton(
text=str(app._("accepted", "button", locale=user.locale)),
callback_data="nothing",
)
],
clb.message.reply_markup.inline_keyboard[1],
]
if len(clb.message.reply_markup.inline_keyboard) > 1
else [
[
InlineKeyboardButton(
text=str(app._("accepted", "button", locale=user.locale)),
callback_data="nothing",
)
]
]
)
if await config_get("send_uploaded_id", "submission"):
await clb.message.edit_caption(
f"{clb.message.caption}\n\nID: `{submission[1]}`"
)
await clb.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)
logger.info(
"Submission with ID '%s' accepted and uploaded with ID '%s'",
fullclb[2],
submission[1],
)
@Client.on_callback_query(filters.regex("sub_no_[\s\S]*"))
async def callback_query_no(app: PyroClient, clb: CallbackQuery):
user = await app.find_user(clb.from_user)
fullclb = str(clb.data).split("_")
db_entry = col_submitted.find_one_and_delete({"_id": ObjectId(fullclb[2])})
if (
db_entry["temp"]["uuid"] is not None
and Path(
f"{app.config['locations']['data']}/submissions/{db_entry['temp']['uuid']}"
).exists()
):
rmtree(
Path(
f"{app.config['locations']['data']}/submissions/{db_entry['temp']['uuid']}"
),
ignore_errors=True,
)
try:
submission = await app.get_messages(
db_entry["user"], db_entry["telegram"]["msg_id"]
)
except Exception as exp:
await clb.answer(
text=app._("sub_msg_unavail", "message", locale=user.locale),
show_alert=True,
)
return
await submission.reply_text(
app._(
"sub_no",
"message",
locale=(await app.find_user(submission.from_user)).locale,
),
quote=True,
)
await clb.answer(
text=app._("sub_no", "callback", locale=user.locale).format(fullclb[2]),
show_alert=True,
)
edited_markup = (
[
[
InlineKeyboardButton(
text=str(app._("declined", "button", locale=user.locale)),
callback_data="nothing",
)
],
clb.message.reply_markup.inline_keyboard[1],
]
if len(clb.message.reply_markup.inline_keyboard) > 1
else [
[
InlineKeyboardButton(
text=str(app._("declined", "button", locale=user.locale)),
callback_data="nothing",
)
]
]
)
await clb.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)
logger.info(
"Submission with ID '%s' rejected",
fullclb[2],
)
@Client.on_callback_query(filters.regex("sub_block_[\s\S]*"))
async def callback_query_block(app: PyroClient, clb: CallbackQuery):
user = await app.find_user(clb.from_user)
fullclb = str(clb.data).split("_")
await app.send_message(
int(fullclb[2]),
app._(
"sub_blocked",
"message",
locale=(await app.find_user(int(fullclb[2]))).locale,
),
)
await user.block()
await clb.answer(
text=app._("sub_block", "callback", locale=user.locale).format(fullclb[2]),
show_alert=True,
)
edited_markup = [
clb.message.reply_markup.inline_keyboard[0],
[
InlineKeyboardButton(
text=str(app._("sub_unblock", "button", locale=user.locale)),
callback_data=f"sub_unblock_{fullclb[2]}",
)
],
]
await clb.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)
logger.info("User %s has been blocked", fullclb[2])
@Client.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
async def callback_query_unblock(app: PyroClient, clb: CallbackQuery):
user = await app.find_user(clb.from_user)
fullclb = str(clb.data).split("_")
await app.send_message(
int(fullclb[2]),
app._(
"sub_unblocked",
"message",
locale=(await app.find_user(int(fullclb[2]))).locale,
),
)
await user.unblock()
await clb.answer(
text=app._("sub_unblock", "callback", locale=user.locale).format(fullclb[2]),
show_alert=True,
)
edited_markup = [
clb.message.reply_markup.inline_keyboard[0],
[
InlineKeyboardButton(
text=str(app._("sub_block", "button", locale=user.locale)),
callback_data=f"sub_block_{fullclb[2]}",
)
],
]
await clb.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)
logger.info("User %s has been unblocked", fullclb[2])

View File

@@ -0,0 +1,48 @@
import asyncio
from os import makedirs
from pathlib import Path
from time import time
from libbot import json_write
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
from classes.pyroclient import PyroClient
from modules.utils import USERS_WITH_CONTEXT
@Client.on_message(
~filters.scheduled & filters.command(["shutdown"], prefixes=["", "/"])
)
async def cmd_kill(app: PyroClient, msg: Message):
if msg.from_user.id not in app.admins:
return
user = await app.find_user(msg.from_user)
if len(USERS_WITH_CONTEXT) > 0:
await msg.reply_text(
app._("shutdown_confirm", "message", locale=user.locale).format(
len(USERS_WITH_CONTEXT)
),
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
app._("shutdown", "button", locale=user.locale),
callback_data="shutdown",
)
]
]
),
)
return
makedirs(app.config["locations"]["cache"], exist_ok=True)
await json_write(
{"timestamp": time()},
Path(f"{app.config['locations']['cache']}/shutdown_time"),
)
asyncio.get_event_loop().create_task(app.stop())

View File

@@ -0,0 +1,27 @@
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import Message
from classes.pyroclient import PyroClient
@Client.on_message(~filters.scheduled & filters.command(["start"], prefixes="/"))
async def cmd_start(app: PyroClient, msg: Message):
user = await app.find_user(msg.from_user)
if user.banned:
return
await msg.reply_text(app._("start", "message", locale=user.locale))
@Client.on_message(
~filters.scheduled & filters.command(["rules", "help"], prefixes="/")
)
async def cmd_rules(app: PyroClient, msg: Message):
user = await app.find_user(msg.from_user)
if user.banned:
return
await msg.reply_text(app._("rules", "message", locale=user.locale))

356
plugins/commands/photos.py Normal file
View File

@@ -0,0 +1,356 @@
import asyncio
import logging
from glob import iglob
from io import BytesIO
from os import getcwd, makedirs, path, remove
from pathlib import Path
from shutil import disk_usage, rmtree
from traceback import format_exc
from uuid import uuid4
from zipfile import ZipFile
from convopyro import listen_message
from photosapi_client.errors import UnexpectedStatus
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import (
KeyboardButton,
Message,
ReplyKeyboardMarkup,
ReplyKeyboardRemove,
)
from ujson import loads
from classes.pyroclient import PyroClient
from modules.api_client import (
BodyPhotoUpload,
File,
client,
photo_delete,
photo_upload,
video_delete,
video_upload,
)
from modules.utils import USERS_WITH_CONTEXT, extract_and_save
logger = logging.getLogger(__name__)
@Client.on_message(~filters.scheduled & filters.command(["import"], prefixes=["", "/"]))
async def cmd_import(app: PyroClient, msg: Message):
if msg.from_user.id not in app.admins:
return
global USERS_WITH_CONTEXT
if msg.from_user.id not in USERS_WITH_CONTEXT:
USERS_WITH_CONTEXT.append(msg.from_user.id)
else:
return
user = await app.find_user(msg.from_user)
await msg.reply_text(app._("import_request", "message", locale=user.locale))
answer = await listen_message(app, msg.chat.id, timeout=600)
USERS_WITH_CONTEXT.remove(msg.from_user.id)
if answer is None:
await msg.reply_text(
app._("import_ignored", "message", locale=user.locale),
quote=True,
)
return
if answer.text == "/cancel":
await answer.reply_text(app._("import_abort", "message", locale=user.locale))
return
if answer.document is None:
await answer.reply_text(
app._(
"import_invalid_media",
"message",
locale=user.locale,
),
quote=True,
)
return
if answer.document.mime_type != "application/zip":
await answer.reply_text(
app._("import_invalid_mime", "message", locale=user.locale),
quote=True,
)
return
if disk_usage(getcwd())[2] < (answer.document.file_size) * 3:
await msg.reply_text(
app._("import_too_big", "message", locale=user.locale).format(
answer.document.file_size // (2**30),
disk_usage(getcwd())[2] // (2**30),
)
)
return
tmp_dir = str(uuid4())
logging.info(
"Importing '%s' file %s bytes big (TMP ID %s)",
answer.document.file_name,
answer.document.file_size,
tmp_dir,
)
makedirs(Path(f"{app.config['locations']['tmp']}/{tmp_dir}"), exist_ok=True)
tmp_path = Path(f"{app.config['locations']['tmp']}/{answer.document.file_id}")
downloading = await answer.reply_text(
app._("import_downloading", "message", locale=user.locale),
quote=True,
)
await app.download_media(answer, file_name=str(tmp_path))
await downloading.edit(app._("import_unpacking", "message", locale=user.locale))
try:
with ZipFile(tmp_path, "r") as handle:
tasks = [
extract_and_save(
handle, name, Path(f"{app.config['locations']['tmp']}/{tmp_dir}")
)
for name in handle.namelist()
]
_ = await asyncio.gather(*tasks)
except Exception as exp:
logger.error(
"Could not import '%s' due to %s: %s",
answer.document.file_name,
exp,
format_exc(),
)
await answer.reply_text(
app._("import_unpack_error", "message", locale=user.locale).format(
exp, format_exc()
)
)
return
logger.info("Downloaded '%s' - awaiting upload", answer.document.file_name)
await downloading.edit(app._("import_uploading", "message", locale=user.locale))
remove(tmp_path)
for filename in iglob(
str(Path(f"{app.config['locations']['tmp']}/{tmp_dir}")) + "**/**",
recursive=True,
):
if not path.isfile(filename):
continue
with open(str(filename), "rb") as fh:
photo_bytes = BytesIO(fh.read())
try:
# VIDEO SUPPORT IS PLANNED HERE TOO
uploaded = await photo_upload(
app.config["posting"]["api"]["album"],
client=client,
multipart_data=BodyPhotoUpload(
File(photo_bytes, Path(filename).name, "image/jpeg")
),
ignore_duplicates=app.config["submission"]["allow_duplicates"],
compress=False,
caption="queue",
)
except UnexpectedStatus as exp:
logger.error(
"Could not upload '%s' from '%s': %s",
filename,
Path(f"{app.config['locations']['tmp']}/{tmp_dir}"),
exp,
)
await msg.reply_text(
app._(
"import_upload_error_other",
"message",
locale=user.locale,
).format(path.basename(filename)),
disable_notification=True,
)
continue
uploaded_dict = loads(uploaded.content.decode("utf-8"))
if "duplicates" in uploaded_dict:
logger.warning(
"Could not upload '%s' from '%s'. Duplicates: %s",
filename,
Path(f"{app.config['locations']['tmp']}/{tmp_dir}"),
str(uploaded_dict["duplicates"]),
)
if len(uploaded_dict["duplicates"]) > 0:
await msg.reply_text(
app._(
"import_upload_error_duplicate",
"message",
locale=user.locale,
).format(path.basename(filename)),
disable_notification=True,
)
else:
await msg.reply_text(
app._(
"import_upload_error_other",
"message",
locale=user.locale,
).format(path.basename(filename)),
disable_notification=True,
)
else:
logger.info(
"Uploaded '%s' from '%s' and got ID %s",
filename,
Path(f"{app.config['locations']['tmp']}/{tmp_dir}"),
uploaded.parsed.id,
)
await downloading.delete()
logger.info(
"Removing '%s' after uploading",
Path(f"{app.config['locations']['tmp']}/{tmp_dir}"),
)
rmtree(Path(f"{app.config['locations']['tmp']}/{tmp_dir}"), ignore_errors=True)
await answer.reply_text(
app._("import_finished", "message", locale=user.locale),
quote=True,
)
return
@Client.on_message(~filters.scheduled & filters.command(["export"], prefixes=["", "/"]))
async def cmd_export(app: PyroClient, msg: Message):
if msg.from_user.id not in app.admins:
return
@Client.on_message(~filters.scheduled & filters.command(["remove"], prefixes=["", "/"]))
async def cmd_remove(app: PyroClient, msg: Message):
if msg.from_user.id not in app.admins:
return
global USERS_WITH_CONTEXT
if msg.from_user.id not in USERS_WITH_CONTEXT:
USERS_WITH_CONTEXT.append(msg.from_user.id)
else:
return
user = await app.find_user(msg.from_user)
await msg.reply_text(app._("remove_request", "message", locale=user.locale))
answer_id = await listen_message(app, msg.chat.id, timeout=600)
USERS_WITH_CONTEXT.remove(msg.from_user.id)
if answer_id is None:
await msg.reply_text(
app._("remove_ignored", "message", locale=user.locale),
quote=True,
)
return
if answer_id.text == "/cancel":
await answer_id.reply_text(app._("remove_abort", "message", locale=user.locale))
return
await msg.reply_text(
app._("remove_kind", "message", locale=user.locale),
reply_markup=ReplyKeyboardMarkup(
[
[
KeyboardButton(app._("photo", "button", locale=user.locale)),
KeyboardButton(app._("video", "button", locale=user.locale)),
]
],
resize_keyboard=True,
one_time_keyboard=True,
),
)
USERS_WITH_CONTEXT.append(msg.from_user.id)
answer_kind = await listen_message(app, msg.chat.id, timeout=600)
USERS_WITH_CONTEXT.remove(msg.from_user.id)
if answer_kind is None:
await msg.reply_text(
app._("remove_ignored", "message", locale=user.locale),
quote=True,
reply_markup=ReplyKeyboardRemove(),
)
return
if answer_kind.text == "/cancel":
await answer_kind.reply_text(
app._("remove_abort", "message", locale=user.locale),
reply_markup=ReplyKeyboardRemove(),
)
return
if answer_kind.text in app.in_all_locales("photo", "button"):
func = photo_delete
elif answer_kind.text in app.in_all_locales("video", "button"):
func = video_delete
else:
await answer_kind.reply_text(
app._("remove_unknown", "message", locale=user.locale).format(
app._("photo", "button", locale=user.locale),
app._("video", "button", locale=user.locale),
),
reply_markup=ReplyKeyboardRemove(),
)
return
response = await func(id=answer_id.text, client=client)
if response is None:
logger.info(
"Removed %s '%s' by request of user %s",
answer_kind.text,
answer_id.text,
answer_id.from_user.id,
)
await answer_kind.reply_text(
app._("remove_success", "message", locale=user.locale).format(
answer_id.text
),
reply_markup=ReplyKeyboardRemove(),
)
else:
logger.warning(
"Could not remove %s '%s' by request of user %s",
answer_kind.text,
answer_id.text,
answer_id.from_user.id,
)
await answer_kind.reply_text(
app._("remove_failure", "message", locale=user.locale).format(
answer_id.text
),
reply_markup=ReplyKeyboardRemove(),
)
@Client.on_message(~filters.scheduled & filters.command(["purge"], prefixes=["", "/"]))
async def cmd_purge(app: PyroClient, msg: Message):
if msg.from_user.id not in app.admins:
return

View File

@@ -0,0 +1,41 @@
from libbot import sync
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import Message, User
from classes.pyroclient import PyroClient
@Client.on_message(
~filters.scheduled
& filters.chat(sync.config_get("comments", "posting"))
& filters.reply
& filters.command(["report"], prefixes=["", "/"])
)
async def command_report(app: PyroClient, msg: Message):
if msg.reply_to_message.forward_from_chat.id != app.config["posting"]["channel"]:
return
user = await app.find_user(msg.from_user)
await msg.reply_text(
app._(
"report_sent",
"message",
locale=user.locale if msg.from_user is not None else None,
)
)
print(msg)
report_sent = await msg.reply_to_message.forward(app.owner)
sender = msg.from_user if msg.from_user is not None else msg.sender_chat
sender_name = sender.first_name if isinstance(sender, User) else sender.title
await report_sent.reply_text(
app._("report_received", "message", locale=user.locale).format(
sender_name, sender.username, sender.id
),
quote=True,
)

View File

@@ -0,0 +1,312 @@
import logging
from datetime import datetime
from os import makedirs, path, sep
from pathlib import Path
from traceback import format_exc
from uuid import uuid4
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.enums.chat_action import ChatAction
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
from classes.enums.submission_types import SubmissionType
from classes.exceptions import SubmissionDuplicatesError, SubmissionUnsupportedError
from classes.pyroclient import PyroClient
from modules.database import col_submitted
from modules.utils import USERS_WITH_CONTEXT
logger = logging.getLogger(__name__)
@Client.on_message(
~filters.scheduled & filters.private & filters.photo
| filters.video
# | filters.animation
| filters.document
)
async def get_submission(app: PyroClient, msg: Message):
global USERS_WITH_CONTEXT
if not hasattr(msg.from_user, "id"):
return
if msg.from_user.id in USERS_WITH_CONTEXT:
return
user = await app.find_user(msg.from_user)
user_owner = await app.find_user(app.owner)
try:
if user.banned:
return
await app.send_chat_action(msg.chat.id, ChatAction.TYPING)
save_tmp = True
contents = None
if await user.is_limited():
await msg.reply_text(
app._("sub_cooldown", "message", locale=user.locale).format(
app.config["submission"]["timeout"]
)
)
return
if msg.document is not None:
logger.info(
"User %s is trying to submit a file of type '%s' with name '%s' and size of %s MB",
msg.from_user.id,
msg.document.mime_type,
msg.document.file_name,
msg.document.file_size / 1024 / 1024,
)
if msg.document.mime_type not in app.config["submission"]["mime_types"]:
await msg.reply_text(
app._("mime_not_allowed", "message", locale=user.locale).format(
", ".join(app.config["submission"]["mime_types"])
),
quote=True,
)
return
if msg.document.file_size > app.config["submission"]["file_size"]:
await msg.reply_text(
app._("document_too_large", "message", locale=user.locale).format(
app.config["submission"]["file_size"] / 1024 / 1024
),
quote=True,
)
return
if msg.document.file_size > app.config["submission"]["tmp_size"]:
save_tmp = False
contents = (
msg.document.file_id,
SubmissionType.DOCUMENT,
) # , msg.document.file_name
if msg.video is not None:
logger.info(
"User %s is trying to submit a video with name '%s' and size of %s MB",
msg.from_user.id,
msg.video.file_name,
msg.video.file_size / 1024 / 1024,
)
if msg.video.file_size > app.config["submission"]["file_size"]:
await msg.reply_text(
app._("document_too_large", "message", locale=user.locale).format(
app.config["submission"]["file_size"] / 1024 / 1024
),
quote=True,
)
return
if msg.video.file_size > app.config["submission"]["tmp_size"]:
save_tmp = False
contents = msg.video.file_id, SubmissionType.VIDEO # , msg.video.file_name
# if msg.animation is not None:
# logger.info(
# "User %s is trying to submit an animation with name '%s' and size of %s MB",
# msg.from_user.id,
# msg.animation.file_name,
# msg.animation.file_size / 1024 / 1024,
# )
# if msg.animation.file_size > app.config["submission"]["file_size"]:
# await msg.reply_text(
# app._("document_too_large", "message", locale=user.locale).format(
# str(app.config["submission"]["file_size"] / 1024 / 1024)
# ),
# quote=True,
# )
# return
# if msg.animation.file_size > app.config["submission"]["tmp_size"]:
# save_tmp = False
# contents = (
# msg.animation.file_id,
# SubmissionType.ANIMATION,
# ) # , msg.animation.file_name
if msg.photo is not None:
logger.info(
"User %s is trying to submit a photo with ID '%s' and size of %s MB",
msg.from_user.id,
msg.photo.file_id,
msg.photo.file_size / 1024 / 1024,
)
contents = msg.photo.file_id, SubmissionType.PHOTO # , "please_generate"
if contents is None:
return
if save_tmp is not None:
tmp_id = str(uuid4())
# filename = tmp_id if contents[1] == "please_generate" else contents[1]
makedirs(
Path(f"{app.config['locations']['data']}/submissions/{tmp_id}"),
exist_ok=True,
)
downloaded = await app.download_media(
msg,
str(Path(f"{app.config['locations']['data']}/submissions/{tmp_id}"))
+ sep,
)
inserted = col_submitted.insert_one(
{
"user": msg.from_user.id,
"date": datetime.now(),
"done": False,
"type": contents[1].value,
"temp": {"uuid": tmp_id, "file": path.basename(str(downloaded))},
"telegram": {"msg_id": msg.id, "file_id": contents[0]},
"caption": str(msg.caption) if msg.caption is not None else None,
}
)
else:
inserted = col_submitted.insert_one(
{
"user": msg.from_user.id,
"date": datetime.now(),
"done": False,
"type": contents[1].value,
"temp": {"uuid": None, "file": None},
"telegram": {"msg_id": msg.id, "file_id": contents[0]},
"caption": str(msg.caption) if msg.caption is not None else None,
}
)
buttons = [
[
InlineKeyboardButton(
text=app._("sub_yes", "button", locale=user_owner.locale),
callback_data=f"sub_yes_{str(inserted.inserted_id)}",
)
]
]
if msg.caption is not None:
caption = str(msg.caption)
buttons[0].append(
InlineKeyboardButton(
text=app._("sub_yes_caption", "button", locale=user_owner.locale),
callback_data=f"sub_yes_{str(inserted.inserted_id)}_caption",
)
)
else:
caption = ""
buttons[0].append(
InlineKeyboardButton(
text=app._("sub_no", "button", locale=user_owner.locale),
callback_data=f"sub_no_{str(inserted.inserted_id)}",
)
)
caption += app._("sub_by", "message", locale=user_owner.locale)
if msg.from_user.first_name is not None:
caption += f" {msg.from_user.first_name}"
if msg.from_user.last_name is not None:
caption += f" {msg.from_user.last_name}"
if msg.from_user.username is not None:
caption += f" (@{msg.from_user.username})"
if msg.from_user.phone_number is not None:
caption += f" ({msg.from_user.phone_number})"
if (
msg.from_user.id in app.admins
and app.config["submission"]["require_confirmation"]["admins"] is False
):
try:
submitted = await app.submit_media(str(inserted.inserted_id))
await msg.reply_text(
app._("sub_yes_auto", "message", locale=user.locale),
disable_notification=True,
quote=True,
)
if app.config["submission"]["send_uploaded_id"]:
caption += f"\n\nID: `{submitted[1]}`"
await msg.copy(app.owner, caption=caption, disable_notification=True)
return
except SubmissionUnsupportedError:
await msg.reply_text(
app._("mime_not_allowed", "message", locale=user.locale).format(
", ".join(app.config["submission"]["mime_types"]), quote=True
),
quote=True,
)
return
except SubmissionDuplicatesError as exp:
await msg.reply_text(
app._(
"sub_media_duplicates_list", "message", locale=user.locale
).format("\n".join(exp.duplicates)),
quote=True,
)
return
except Exception as exp:
await msg.reply_text(format_exc(), quote=True)
return
elif (
msg.from_user.id not in app.admins
and app.config["submission"]["require_confirmation"]["users"] is False
):
try:
submitted = await app.submit_photo(str(inserted.inserted_id))
await msg.reply_text(
app._("sub_yes_auto", "message", locale=user.locale),
disable_notification=True,
quote=True,
)
if app.config["submission"]["send_uploaded_id"]:
caption += f"\n\nID: `{submitted[1]}`"
await msg.copy(app.owner, caption=caption)
return
except SubmissionUnsupportedError:
await msg.reply_text(
app._("mime_not_allowed", "message", locale=user.locale).format(
", ".join(app.config["submission"]["mime_types"]), quote=True
)
)
return
except SubmissionDuplicatesError as exp:
await msg.reply_text(
app._("sub_dup", "message", locale=user.locale), quote=True
)
return
except Exception as exp:
await app.send_message(
app.owner,
app._(
"sub_error_admin", "message", locale=user_owner.locale
).format(msg.from_user.id, format_exc()),
)
await msg.reply_text("sub_error", quote=True)
return
if msg.from_user.id not in app.admins:
buttons += [
[
InlineKeyboardButton(
text=app._("sub_block", "button", locale=user_owner.locale),
callback_data=f"sub_block_{msg.from_user.id}",
)
]
]
await user.update_cooldown()
if msg.from_user.id != app.owner:
await msg.reply_text(
app._("sub_sent", "message", locale=user.locale),
disable_notification=True,
quote=True,
)
await msg.copy(
app.owner, caption=caption, reply_markup=InlineKeyboardMarkup(buttons)
)
except AttributeError:
logger.error("'from_user' does not seem to contain 'id'")

42
plugins/language.py Normal file
View File

@@ -0,0 +1,42 @@
from pykeyboard import InlineButton, InlineKeyboard
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import CallbackQuery, Message
from classes.pyroclient import PyroClient
@Client.on_message(
~filters.scheduled & filters.private & filters.command(["language"], prefixes=["/"]) # type: ignore
)
async def command_language(app: PyroClient, message: Message):
user = await app.find_user(message.from_user)
keyboard = InlineKeyboard(row_width=2)
buttons = []
for locale, data in app.in_every_locale("metadata").items():
buttons.append(
InlineButton(f"{data['flag']} {data['name']}", f"language:{locale}")
)
keyboard.add(*buttons)
await message.reply_text(
app._("locale_choice", "message", locale=user.locale),
reply_markup=keyboard,
)
@Client.on_callback_query(filters.regex(r"language:[\s\S]*")) # type: ignore
async def callback_language(app: PyroClient, callback: CallbackQuery):
user = await app.find_user(callback.from_user)
language = str(callback.data).split(":")[1]
await user.update_locale(language)
await callback.answer(
app._("locale_set", "callback", locale=language).format(
locale=app._("name", "metadata", locale=language)
),
show_alert=True,
)

View File

@@ -0,0 +1,13 @@
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import Message
from classes.pyroclient import PyroClient
@Client.on_message(
~filters.scheduled & filters.private & filters.command(["remove_commands"], prefixes=["/"]) # type: ignore
)
async def command_remove_commands(app: PyroClient, msg: Message):
await msg.reply_text("Okay.")
await app.remove_commands(command_sets=await app.collect_commands())

View File

@@ -1 +0,0 @@
ujson

View File

@@ -1,2 +1,15 @@
schedule aiohttp~=3.8.4
pyrogram>=2.0.0 black~=23.3.0
convopyro==0.5
pillow~=10.0.0
psutil~=5.9.4
pykeyboard==0.1.5
pymongo~=4.4.0
pyrogram==2.0.106
python_dateutil==2.8.2
pytimeparse~=1.1.8
tgcrypto==1.2.5
uvloop==0.17.0
--extra-index-url https://git.end-play.xyz/api/packages/profitroll/pypi/simple
libbot[speed,pyrogram]==1.8
photosapi_client==0.5.0

6
start.bat Normal file
View File

@@ -0,0 +1,6 @@
@echo off
REM You can cd to your directory here, if you want
REM cd C:\Users\user\TelegramPoster
python main.py

6
start.sh Normal file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
# You can cd to your directory here, if you want
# cd /home/user/TelegramPoster
python main.py