Compare commits
1 Commits
dev
...
15e5fa3742
Author | SHA1 | Date | |
---|---|---|---|
15e5fa3742 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -153,12 +153,8 @@ cython_debug/
|
|||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
# Custom
|
# Custom
|
||||||
cache/
|
|
||||||
config.json
|
config.json
|
||||||
|
|
||||||
*.session
|
*.session
|
||||||
*.session-wal
|
|
||||||
*.session-shm
|
|
||||||
*.session-journal
|
*.session-journal
|
||||||
|
|
||||||
venv
|
venv
|
||||||
|
@@ -57,7 +57,7 @@ class PyroClient(PyroClient):
|
|||||||
self.config["bot"]["owner"]
|
self.config["bot"]["owner"]
|
||||||
]
|
]
|
||||||
|
|
||||||
self.sender_session: Union[ClientSession, None] = None
|
self.sender_session = ClientSession()
|
||||||
|
|
||||||
self.scopes_placeholders: Dict[str, int] = {
|
self.scopes_placeholders: Dict[str, int] = {
|
||||||
"owner": self.owner,
|
"owner": self.owner,
|
||||||
@@ -67,9 +67,6 @@ class PyroClient(PyroClient):
|
|||||||
async def start(self):
|
async def start(self):
|
||||||
await super().start()
|
await super().start()
|
||||||
|
|
||||||
if self.sender_session is None:
|
|
||||||
self.sender_session = ClientSession()
|
|
||||||
|
|
||||||
if self.config["reports"]["update"]:
|
if self.config["reports"]["update"]:
|
||||||
try:
|
try:
|
||||||
async with ClientSession(
|
async with ClientSession(
|
||||||
@@ -137,14 +134,12 @@ class PyroClient(PyroClient):
|
|||||||
)
|
)
|
||||||
|
|
||||||
await http_session.close()
|
await http_session.close()
|
||||||
|
|
||||||
if self.sender_session is not None:
|
|
||||||
await self.sender_session.close()
|
await self.sender_session.close()
|
||||||
|
|
||||||
await super().stop()
|
await super().stop()
|
||||||
|
|
||||||
async def submit_media(
|
async def submit_media(
|
||||||
self, id: str, purge_caption: bool = False
|
self, id: str
|
||||||
) -> Tuple[Union[Message, None], Union[str, None]]:
|
) -> Tuple[Union[Message, None], Union[str, None]]:
|
||||||
db_entry = await col_submitted.find_one({"_id": ObjectId(id)})
|
db_entry = await col_submitted.find_one({"_id": ObjectId(id)})
|
||||||
submission = None
|
submission = None
|
||||||
@@ -184,7 +179,7 @@ class PyroClient(PyroClient):
|
|||||||
response = await photo_upload(
|
response = await photo_upload(
|
||||||
self.config["posting"]["api"]["album"],
|
self.config["posting"]["api"]["album"],
|
||||||
client=client,
|
client=client,
|
||||||
body=BodyPhotoUpload(
|
multipart_data=BodyPhotoUpload(
|
||||||
File(media_bytes, filepath.name, "image/jpeg")
|
File(media_bytes, filepath.name, "image/jpeg")
|
||||||
),
|
),
|
||||||
ignore_duplicates=self.config["submission"]["allow_duplicates"],
|
ignore_duplicates=self.config["submission"]["allow_duplicates"],
|
||||||
@@ -195,14 +190,16 @@ class PyroClient(PyroClient):
|
|||||||
response = await video_upload(
|
response = await video_upload(
|
||||||
self.config["posting"]["api"]["album"],
|
self.config["posting"]["api"]["album"],
|
||||||
client=client,
|
client=client,
|
||||||
body=BodyVideoUpload(File(media_bytes, filepath.name, "video/*")),
|
multipart_data=BodyVideoUpload(
|
||||||
|
File(media_bytes, filepath.name, "video/*")
|
||||||
|
),
|
||||||
caption="queue",
|
caption="queue",
|
||||||
)
|
)
|
||||||
# elif db_entry["type"] == SubmissionType.ANIMATION.value:
|
# elif db_entry["type"] == SubmissionType.ANIMATION.value:
|
||||||
# response = await video_upload(
|
# response = await video_upload(
|
||||||
# self.config["posting"]["api"]["album"],
|
# self.config["posting"]["api"]["album"],
|
||||||
# client=client,
|
# client=client,
|
||||||
# body=BodyVideoUpload(
|
# multipart_data=BodyVideoUpload(
|
||||||
# File(media_bytes, filepath.name, "video/*")
|
# File(media_bytes, filepath.name, "video/*")
|
||||||
# ),
|
# ),
|
||||||
# caption="queue",
|
# caption="queue",
|
||||||
@@ -229,14 +226,10 @@ class PyroClient(PyroClient):
|
|||||||
)
|
)
|
||||||
raise SubmissionDuplicatesError(str(filepath), duplicates)
|
raise SubmissionDuplicatesError(str(filepath), duplicates)
|
||||||
|
|
||||||
db_update = (
|
await col_submitted.find_one_and_update(
|
||||||
{"$set": {"done": True, "caption": None}}
|
{"_id": ObjectId(id)}, {"$set": {"done": True}}
|
||||||
if purge_caption
|
|
||||||
else {"$set": {"done": True}}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
await col_submitted.update_one({"_id": ObjectId(id)}, db_update)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if db_entry["temp"]["uuid"] is not None:
|
if db_entry["temp"]["uuid"] is not None:
|
||||||
rmtree(
|
rmtree(
|
||||||
|
@@ -32,7 +32,6 @@
|
|||||||
"sub_yes_auto": "✅ Submission automatically accepted",
|
"sub_yes_auto": "✅ Submission automatically accepted",
|
||||||
"sub_no": "❌ Submission reviewed and declined",
|
"sub_no": "❌ Submission reviewed and declined",
|
||||||
"sub_dup": "⚠️ Submission automatically declined because database already contains this photo",
|
"sub_dup": "⚠️ Submission automatically declined because database already contains this photo",
|
||||||
"sub_deleted": "⚠️ Submission's database record ({0}) is not available.",
|
|
||||||
"sub_blocked": "You were blocked and you can't submit media anymore.",
|
"sub_blocked": "You were blocked and you can't submit media anymore.",
|
||||||
"sub_unblocked": "You were unblocked and you can now submit media.",
|
"sub_unblocked": "You were unblocked and you can now submit media.",
|
||||||
"sub_by": "\n\nSubmitted by:",
|
"sub_by": "\n\nSubmitted by:",
|
||||||
|
@@ -31,7 +31,6 @@
|
|||||||
"sub_yes_auto": "✅ Подання автоматично прийнято",
|
"sub_yes_auto": "✅ Подання автоматично прийнято",
|
||||||
"sub_no": "❌ Подання розглянуто та відхилено",
|
"sub_no": "❌ Подання розглянуто та відхилено",
|
||||||
"sub_dup": "⚠️ Подання автоматично відхилено через наявність цього фото в базі даних",
|
"sub_dup": "⚠️ Подання автоматично відхилено через наявність цього фото в базі даних",
|
||||||
"sub_deleted": "⚠️ Запис подання у базі даних ({0}) недоступний.",
|
|
||||||
"sub_blocked": "Вас заблокували, ви більше не можете надсилати медіафайли.",
|
"sub_blocked": "Вас заблокували, ви більше не можете надсилати медіафайли.",
|
||||||
"sub_unblocked": "Вас розблокували, тепер ви можете надсилати медіафайли.",
|
"sub_unblocked": "Вас розблокували, тепер ви можете надсилати медіафайли.",
|
||||||
"sub_by": "\n\nПредставлено:",
|
"sub_by": "\n\nПредставлено:",
|
||||||
|
@@ -117,14 +117,16 @@ async def authorize(custom_session: Union[ClientSession, None] = None) -> str:
|
|||||||
|
|
||||||
|
|
||||||
unauthorized_client = Client(
|
unauthorized_client = Client(
|
||||||
sync.config_get("address", "posting", "api"),
|
base_url=sync.config_get("address", "posting", "api"),
|
||||||
raise_on_unexpected_status=True,
|
|
||||||
timeout=sync.config_get("timeout", "posting", "api"),
|
timeout=sync.config_get("timeout", "posting", "api"),
|
||||||
|
verify_ssl=True,
|
||||||
|
raise_on_unexpected_status=True,
|
||||||
|
follow_redirects=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
login_token = login(
|
login_token = login(
|
||||||
client=unauthorized_client,
|
client=unauthorized_client,
|
||||||
body=BodyLoginForAccessTokenTokenPost(
|
form_data=BodyLoginForAccessTokenTokenPost(
|
||||||
grant_type="password",
|
grant_type="password",
|
||||||
scope="me albums.list albums.read albums.write photos.list photos.read photos.write videos.list videos.read videos.write",
|
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"),
|
username=sync.config_get("username", "posting", "api"),
|
||||||
@@ -139,10 +141,12 @@ if not isinstance(login_token, Token):
|
|||||||
exit()
|
exit()
|
||||||
|
|
||||||
client = AuthenticatedClient(
|
client = AuthenticatedClient(
|
||||||
sync.config_get("address", "posting", "api"),
|
base_url=sync.config_get("address", "posting", "api"),
|
||||||
token=login_token.access_token,
|
|
||||||
raise_on_unexpected_status=True,
|
|
||||||
timeout=sync.config_get("timeout", "posting", "api"),
|
timeout=sync.config_get("timeout", "posting", "api"),
|
||||||
|
verify_ssl=True,
|
||||||
|
raise_on_unexpected_status=True,
|
||||||
|
token=login_token.access_token,
|
||||||
|
follow_redirects=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@@ -28,10 +28,7 @@ async def callback_query_yes(app: PyroClient, callback: CallbackQuery):
|
|||||||
db_entry = await col_submitted.find_one({"_id": ObjectId(fullcallback[2])})
|
db_entry = await col_submitted.find_one({"_id": ObjectId(fullcallback[2])})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
submission = await app.submit_media(
|
submission = await app.submit_media(fullcallback[2])
|
||||||
fullcallback[2],
|
|
||||||
purge_caption=("caption" not in fullcallback),
|
|
||||||
)
|
|
||||||
except SubmissionUnavailableError:
|
except SubmissionUnavailableError:
|
||||||
await callback.answer(
|
await callback.answer(
|
||||||
text=app._("sub_msg_unavail", "callback", locale=user.locale),
|
text=app._("sub_msg_unavail", "callback", locale=user.locale),
|
||||||
@@ -123,11 +120,6 @@ async def callback_query_yes(app: PyroClient, callback: CallbackQuery):
|
|||||||
fullcallback[2],
|
fullcallback[2],
|
||||||
submission[1],
|
submission[1],
|
||||||
)
|
)
|
||||||
logger.info(
|
|
||||||
"Submission with ID '%s' accepted and uploaded with ID '%s'",
|
|
||||||
fullcallback[2],
|
|
||||||
submission[1],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@Client.on_callback_query(filters.regex("sub_no_[\s\S]*"))
|
@Client.on_callback_query(filters.regex("sub_no_[\s\S]*"))
|
||||||
@@ -135,19 +127,12 @@ async def callback_query_no(app: PyroClient, callback: CallbackQuery):
|
|||||||
user = await app.find_user(callback.from_user)
|
user = await app.find_user(callback.from_user)
|
||||||
fullcallback = str(callback.data).split("_")
|
fullcallback = str(callback.data).split("_")
|
||||||
|
|
||||||
db_entry = await col_submitted.delete_one({"_id": ObjectId(fullcallback[2])})
|
db_entry = await col_submitted.find_one_and_delete(
|
||||||
|
{"_id": ObjectId(fullcallback[2])}
|
||||||
if db_entry.deleted_count == 0:
|
|
||||||
await callback.answer(
|
|
||||||
text=app._("sub_deleted", "callback", locale=user.locale).format(
|
|
||||||
fullcallback[2]
|
|
||||||
),
|
|
||||||
show_alert=True,
|
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
db_entry.raw_result["temp"]["uuid"] is not None
|
db_entry["temp"]["uuid"] is not None
|
||||||
and Path(
|
and Path(
|
||||||
f"{app.config['locations']['data']}/submissions/{db_entry['temp']['uuid']}"
|
f"{app.config['locations']['data']}/submissions/{db_entry['temp']['uuid']}"
|
||||||
).exists()
|
).exists()
|
||||||
|
@@ -158,7 +158,7 @@ async def cmd_import(app: PyroClient, message: Message):
|
|||||||
uploaded = await photo_upload(
|
uploaded = await photo_upload(
|
||||||
app.config["posting"]["api"]["album"],
|
app.config["posting"]["api"]["album"],
|
||||||
client=client,
|
client=client,
|
||||||
body=BodyPhotoUpload(
|
multipart_data=BodyPhotoUpload(
|
||||||
File(photo_bytes, Path(filename).name, "image/jpeg")
|
File(photo_bytes, Path(filename).name, "image/jpeg")
|
||||||
),
|
),
|
||||||
ignore_duplicates=app.config["submission"]["allow_duplicates"],
|
ignore_duplicates=app.config["submission"]["allow_duplicates"],
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
aiohttp~=3.10.2
|
aiohttp~=3.9.1
|
||||||
async_pymongo==0.1.6
|
|
||||||
convopyro==0.5
|
convopyro==0.5
|
||||||
pillow~=10.4.0
|
pillow~=10.1.0
|
||||||
pykeyboard==0.1.7
|
pykeyboard==0.1.5
|
||||||
pytimeparse~=1.1.8
|
pytimeparse~=1.1.8
|
||||||
tgcrypto==1.2.5
|
tgcrypto==1.2.5
|
||||||
#uvloop==0.19.0
|
uvloop==0.19.0
|
||||||
--extra-index-url https://git.end-play.xyz/api/packages/profitroll/pypi/simple
|
--extra-index-url https://git.end-play.xyz/api/packages/profitroll/pypi/simple
|
||||||
libbot[speed,pyrogram]==3.2.3
|
async_pymongo==0.1.4
|
||||||
photosapi_client==0.6.0
|
libbot[speed,pyrogram]==2.0.1
|
||||||
|
photosapi_client==0.5.0
|
Reference in New Issue
Block a user