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