Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
32e6c4e96f | |||
8c27fb7c37 |
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(
|
||||||
@@ -107,8 +104,8 @@ class PyroClient(PyroClient):
|
|||||||
logger.warning(
|
logger.warning(
|
||||||
"Could not send startup message to bot owner. Perhaps user has not started the bot yet."
|
"Could not send startup message to bot owner. Perhaps user has not started the bot yet."
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exp:
|
||||||
logger.exception("Update check failed due to %s: %s", exc, format_exc())
|
logger.exception("Update check failed due to %s: %s", exp, format_exc())
|
||||||
|
|
||||||
if self.config["mode"]["post"]:
|
if self.config["mode"]["post"]:
|
||||||
if self.config["posting"]["use_interval"]:
|
if self.config["posting"]["use_interval"]:
|
||||||
@@ -137,16 +134,14 @@ class PyroClient(PyroClient):
|
|||||||
)
|
)
|
||||||
|
|
||||||
await http_session.close()
|
await http_session.close()
|
||||||
|
await self.sender_session.close()
|
||||||
if self.sender_session is not None:
|
|
||||||
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 = col_submitted.find_one({"_id": ObjectId(id)})
|
||||||
submission = None
|
submission = None
|
||||||
|
|
||||||
if db_entry is None:
|
if db_entry is None:
|
||||||
@@ -160,8 +155,8 @@ class PyroClient(PyroClient):
|
|||||||
filepath = await self.download_media(
|
filepath = await self.download_media(
|
||||||
submission, file_name=self.config["locations"]["tmp"] + sep
|
submission, file_name=self.config["locations"]["tmp"] + sep
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exp:
|
||||||
raise SubmissionUnavailableError() from exc
|
raise SubmissionUnavailableError() from exp
|
||||||
|
|
||||||
elif not Path(
|
elif not Path(
|
||||||
f"{self.config['locations']['data']}/submissions/{db_entry['temp']['uuid']}/{db_entry['temp']['file']}",
|
f"{self.config['locations']['data']}/submissions/{db_entry['temp']['uuid']}/{db_entry['temp']['file']}",
|
||||||
@@ -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,20 +190,22 @@ 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",
|
||||||
# )
|
# )
|
||||||
except UnexpectedStatus as exc:
|
except UnexpectedStatus as exp:
|
||||||
raise SubmissionUnsupportedError(str(filepath)) from exc
|
raise SubmissionUnsupportedError(str(filepath)) from exp
|
||||||
|
|
||||||
response_dict = (
|
response_dict = (
|
||||||
{}
|
{}
|
||||||
@@ -229,14 +226,10 @@ class PyroClient(PyroClient):
|
|||||||
)
|
)
|
||||||
raise SubmissionDuplicatesError(str(filepath), duplicates)
|
raise SubmissionDuplicatesError(str(filepath), duplicates)
|
||||||
|
|
||||||
db_update = (
|
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(
|
||||||
@@ -265,12 +258,12 @@ class PyroClient(PyroClient):
|
|||||||
* `PyroUser`: PyroUser object
|
* `PyroUser`: PyroUser object
|
||||||
"""
|
"""
|
||||||
if (
|
if (
|
||||||
await col_users.find_one(
|
col_users.find_one(
|
||||||
{"id": user.id if isinstance(user, User) else user}
|
{"id": user.id if isinstance(user, User) else user}
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
is None
|
is None
|
||||||
):
|
):
|
||||||
await col_users.insert_one(
|
col_users.insert_one(
|
||||||
{
|
{
|
||||||
"id": user.id if isinstance(user, User) else user,
|
"id": user.id if isinstance(user, User) else user,
|
||||||
"locale": user.language_code if isinstance(user, User) else None,
|
"locale": user.language_code if isinstance(user, User) else None,
|
||||||
@@ -280,7 +273,7 @@ class PyroClient(PyroClient):
|
|||||||
}
|
}
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
|
||||||
db_record = await col_users.find_one(
|
db_record = col_users.find_one(
|
||||||
{"id": user.id if isinstance(user, User) else user}
|
{"id": user.id if isinstance(user, User) else user}
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
|
||||||
|
@@ -20,19 +20,19 @@ class PyroUser:
|
|||||||
cooldown: datetime
|
cooldown: datetime
|
||||||
subscription: dict
|
subscription: dict
|
||||||
|
|
||||||
async def update_locale(self, locale: str) -> None:
|
async def update_locale(self, locale: str):
|
||||||
await col_users.update_one({"_id": self._id}, {"$set": {"locale": locale}})
|
col_users.update_one({"_id": self._id}, {"$set": {"locale": locale}})
|
||||||
|
|
||||||
async def update_cooldown(self, time: datetime = datetime.now()) -> None:
|
async def update_cooldown(self, time: datetime = datetime.now()):
|
||||||
await col_users.update_one({"_id": self._id}, {"$set": {"cooldown": time}})
|
col_users.update_one({"_id": self._id}, {"$set": {"cooldown": time}})
|
||||||
|
|
||||||
async def block(self) -> None:
|
async def block(self) -> None:
|
||||||
"""Ban user from using command and submitting content."""
|
"""Ban user from using command and submitting content."""
|
||||||
await col_users.update_one({"_id": self._id}, {"$set": {"banned": True}})
|
col_users.update_one({"_id": self._id}, {"$set": {"banned": True}})
|
||||||
|
|
||||||
async def unblock(self) -> None:
|
async def unblock(self) -> None:
|
||||||
"""Allow user to use command and submit posts again."""
|
"""Allow user to use command and submit posts again."""
|
||||||
await col_users.update_one({"_id": self._id}, {"$set": {"banned": False}})
|
col_users.update_one({"_id": self._id}, {"$set": {"banned": False}})
|
||||||
|
|
||||||
async def is_limited(self, app: Union[PyroClient, None] = None) -> bool:
|
async def is_limited(self, app: Union[PyroClient, None] = None) -> bool:
|
||||||
"""Check if user is on a cooldown after submitting something.
|
"""Check if user is on a cooldown after submitting something.
|
||||||
@@ -41,9 +41,11 @@ class PyroUser:
|
|||||||
`bool`: Must be `True` if on the cooldown and `False` if not
|
`bool`: Must be `True` if on the cooldown and `False` if not
|
||||||
"""
|
"""
|
||||||
admins = (
|
admins = (
|
||||||
await config_get("admins", "bot") + [await config_get("owner", "bot")]
|
app.admins
|
||||||
if app is None
|
if app is not None
|
||||||
else app.admins
|
else (
|
||||||
|
await config_get("admins", "bot") + [await config_get("owner", "bot")]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return (datetime.now() - self.cooldown).total_seconds() < (
|
return (datetime.now() - self.cooldown).total_seconds() < (
|
||||||
|
@@ -83,8 +83,7 @@
|
|||||||
"address_external": "https://photos.domain.com",
|
"address_external": "https://photos.domain.com",
|
||||||
"username": "",
|
"username": "",
|
||||||
"password": "",
|
"password": "",
|
||||||
"album": "",
|
"album": ""
|
||||||
"timeout": 15.0
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"caption": {
|
"caption": {
|
||||||
|
@@ -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"),
|
||||||
|
timeout=5.0,
|
||||||
|
verify_ssl=True,
|
||||||
raise_on_unexpected_status=True,
|
raise_on_unexpected_status=True,
|
||||||
timeout=sync.config_get("timeout", "posting", "api"),
|
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,
|
timeout=5.0,
|
||||||
|
verify_ssl=True,
|
||||||
raise_on_unexpected_status=True,
|
raise_on_unexpected_status=True,
|
||||||
timeout=sync.config_get("timeout", "posting", "api"),
|
token=login_token.access_token,
|
||||||
|
follow_redirects=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@@ -58,8 +58,8 @@ async def cli_create_user() -> None:
|
|||||||
none = input(
|
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."
|
"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 exc:
|
except Exception as exp:
|
||||||
print(f"Could not create a user due to {exc}", flush=True)
|
print(f"Could not create a user due to {exp}", flush=True)
|
||||||
print_exc()
|
print_exc()
|
||||||
exit()
|
exit()
|
||||||
if not args.create_album:
|
if not args.create_album:
|
||||||
@@ -97,8 +97,8 @@ async def cli_create_album() -> None:
|
|||||||
result_2 = await album_create(client=client, name=name, title=title)
|
result_2 = await album_create(client=client, name=name, title=title)
|
||||||
# asyncio.run(create_album(name, title))
|
# asyncio.run(create_album(name, title))
|
||||||
await config_set("album", name, "posting", "api")
|
await config_set("album", name, "posting", "api")
|
||||||
except Exception as exc:
|
except Exception as exp:
|
||||||
print(f"Could not create an album due to {exc}", flush=True)
|
print(f"Could not create an album due to {exp}", flush=True)
|
||||||
print_exc()
|
print_exc()
|
||||||
exit()
|
exit()
|
||||||
print("You're done!", flush=True)
|
print("You're done!", flush=True)
|
||||||
|
@@ -1,18 +0,0 @@
|
|||||||
"""Custom message filters"""
|
|
||||||
|
|
||||||
from pyrogram import filters
|
|
||||||
from pyrogram.types import Message
|
|
||||||
|
|
||||||
from classes.pyroclient import PyroClient
|
|
||||||
|
|
||||||
|
|
||||||
async def _mode_post_func(_, __: PyroClient, message: Message):
|
|
||||||
return __.config["mode"]["post"]
|
|
||||||
|
|
||||||
|
|
||||||
async def _mode_submit_func(_, __: PyroClient, message: Message):
|
|
||||||
return __.config["mode"]["submit"]
|
|
||||||
|
|
||||||
|
|
||||||
mode_post = filters.create(_mode_post_func)
|
|
||||||
mode_submit = filters.create(_mode_submit_func)
|
|
@@ -1,9 +1,11 @@
|
|||||||
"""Module that provides all database columns"""
|
"""Module that provides all database columns"""
|
||||||
|
|
||||||
from async_pymongo import AsyncClient
|
from pymongo import MongoClient
|
||||||
from libbot import sync
|
from ujson import loads
|
||||||
|
|
||||||
db_config = sync.config_get("database")
|
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:
|
if db_config["user"] is not None and db_config["password"] is not None:
|
||||||
con_string = "mongodb://{0}:{1}@{2}:{3}/{4}".format(
|
con_string = "mongodb://{0}:{1}@{2}:{3}/{4}".format(
|
||||||
@@ -18,9 +20,15 @@ else:
|
|||||||
db_config["host"], db_config["port"], db_config["name"]
|
db_config["host"], db_config["port"], db_config["name"]
|
||||||
)
|
)
|
||||||
|
|
||||||
db_client = AsyncClient(con_string)
|
db_client = MongoClient(con_string)
|
||||||
db = db_client.get_database(name=db_config["name"])
|
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_sent = db.get_collection("sent")
|
||||||
col_users = db.get_collection("users")
|
col_users = db.get_collection("users")
|
||||||
col_submitted = db.get_collection("submitted")
|
col_submitted = db.get_collection("submitted")
|
||||||
|
@@ -77,12 +77,12 @@ async def send_content(app: PyroClient, http_session: ClientSession) -> None:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
response: File = await func_iter[1](id=media.id, client=client)
|
response: File = await func_iter[1](id=media.id, client=client)
|
||||||
except Exception as exc:
|
except Exception as exp:
|
||||||
print_exc()
|
print_exc()
|
||||||
logger.error("Media is invalid: %s", exc)
|
logger.error("Media is invalid: %s", exp)
|
||||||
if app.config["reports"]["error"]:
|
if app.config["reports"]["error"]:
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
app.owner, f"Media is invalid: {exc}"
|
app.owner, f"Media is invalid: {exp}"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -103,11 +103,11 @@ async def send_content(app: PyroClient, http_session: ClientSession) -> None:
|
|||||||
).results[0]
|
).results[0]
|
||||||
try:
|
try:
|
||||||
response: File = await func[1](id=media.id, client=client)
|
response: File = await func[1](id=media.id, client=client)
|
||||||
except Exception as exc:
|
except Exception as exp:
|
||||||
print_exc()
|
print_exc()
|
||||||
logger.error("Media is invalid: %s", exc)
|
logger.error("Media is invalid: %s", exp)
|
||||||
if app.config["reports"]["error"]:
|
if app.config["reports"]["error"]:
|
||||||
await app.send_message(app.owner, f"Media is invalid: {exc}")
|
await app.send_message(app.owner, f"Media is invalid: {exp}")
|
||||||
return
|
return
|
||||||
|
|
||||||
except (KeyError, AttributeError, TypeError, IndexError):
|
except (KeyError, AttributeError, TypeError, IndexError):
|
||||||
@@ -152,7 +152,7 @@ async def send_content(app: PyroClient, http_session: ClientSession) -> None:
|
|||||||
) and func[0] is photo_random:
|
) and func[0] is photo_random:
|
||||||
image = Image.open(path.join(app.config["locations"]["tmp"], tmp_path))
|
image = Image.open(path.join(app.config["locations"]["tmp"], tmp_path))
|
||||||
width, height = image.size
|
width, height = image.size
|
||||||
image = image.resize((int(width / 2), int(height / 2)), Image.LANCZOS)
|
image = image.resize((int(width / 2), int(height / 2)), Image.ANTIALIAS)
|
||||||
if tmp_path.lower().endswith(".jpeg") or tmp_path.lower().endswith(".jpg"):
|
if tmp_path.lower().endswith(".jpeg") or tmp_path.lower().endswith(".jpg"):
|
||||||
image.save(
|
image.save(
|
||||||
path.join(app.config["locations"]["tmp"], tmp_path),
|
path.join(app.config["locations"]["tmp"], tmp_path),
|
||||||
@@ -179,7 +179,7 @@ async def send_content(app: PyroClient, http_session: ClientSession) -> None:
|
|||||||
|
|
||||||
del response
|
del response
|
||||||
|
|
||||||
submitted = await col_submitted.find_one({"temp.file": media.filename})
|
submitted = col_submitted.find_one({"temp.file": media.filename})
|
||||||
|
|
||||||
if submitted is not None and submitted["caption"] is not None:
|
if submitted is not None and submitted["caption"] is not None:
|
||||||
caption = submitted["caption"].strip()
|
caption = submitted["caption"].strip()
|
||||||
@@ -217,19 +217,19 @@ async def send_content(app: PyroClient, http_session: ClientSession) -> None:
|
|||||||
caption=caption,
|
caption=caption,
|
||||||
disable_notification=app.config["posting"]["silent"],
|
disable_notification=app.config["posting"]["silent"],
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exp:
|
||||||
logger.error(
|
logger.error(
|
||||||
"Could not send media %s (%s) due to %s", media.filename, media.id, exc
|
"Could not send media %s (%s) due to %s", media.filename, media.id, exp
|
||||||
)
|
)
|
||||||
if app.config["reports"]["error"]:
|
if app.config["reports"]["error"]:
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
app.owner,
|
app.owner,
|
||||||
app._("post_exception", "message").format(exc, format_exc()),
|
app._("post_exception", "message").format(exp, format_exc()),
|
||||||
)
|
)
|
||||||
# rmtree(path.join(app.config['locations']['tmp'], tmp_dir), ignore_errors=True)
|
# rmtree(path.join(app.config['locations']['tmp'], tmp_dir), ignore_errors=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
await col_sent.insert_one(
|
col_sent.insert_one(
|
||||||
{
|
{
|
||||||
"date": datetime.now(),
|
"date": datetime.now(),
|
||||||
"image": media.id,
|
"image": media.id,
|
||||||
@@ -253,14 +253,14 @@ async def send_content(app: PyroClient, http_session: ClientSession) -> None:
|
|||||||
str(app.config["posting"]["silent"]),
|
str(app.config["posting"]["silent"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exp:
|
||||||
logger.error(
|
logger.error(
|
||||||
"Could not send content due to %s. Traceback: %s", exc, format_exc()
|
"Could not send content due to %s. Traceback: %s", exp, format_exc()
|
||||||
)
|
)
|
||||||
if app.config["reports"]["error"]:
|
if app.config["reports"]["error"]:
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
app.owner,
|
app.owner,
|
||||||
app._("post_exception", "message").format(exc, format_exc()),
|
app._("post_exception", "message").format(exp, format_exc()),
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
rmtree(
|
rmtree(
|
||||||
|
@@ -6,7 +6,7 @@ from classes.pyroclient import PyroClient
|
|||||||
|
|
||||||
|
|
||||||
@Client.on_callback_query(filters.regex("nothing"))
|
@Client.on_callback_query(filters.regex("nothing"))
|
||||||
async def callback_query_nothing(app: PyroClient, callback: CallbackQuery):
|
async def callback_query_nothing(app: PyroClient, clb: CallbackQuery):
|
||||||
user = await app.find_user(callback.from_user)
|
user = await app.find_user(clb.from_user)
|
||||||
|
|
||||||
await callback.answer(text=app._("nothing", "callback", locale=user.locale))
|
await clb.answer(text=app._("nothing", "callback", locale=user.locale))
|
||||||
|
@@ -10,11 +10,11 @@ from classes.pyroclient import PyroClient
|
|||||||
|
|
||||||
|
|
||||||
@Client.on_callback_query(filters.regex("shutdown"))
|
@Client.on_callback_query(filters.regex("shutdown"))
|
||||||
async def callback_query_nothing(app: PyroClient, callback: CallbackQuery):
|
async def callback_query_nothing(app: PyroClient, clb: CallbackQuery):
|
||||||
if callback.from_user.id not in app.admins:
|
if clb.from_user.id not in app.admins:
|
||||||
return
|
return
|
||||||
|
|
||||||
await callback.answer()
|
await clb.answer()
|
||||||
|
|
||||||
makedirs(await config_get("cache", "locations"), exist_ok=True)
|
makedirs(await config_get("cache", "locations"), exist_ok=True)
|
||||||
await json_write(
|
await json_write(
|
||||||
|
@@ -21,46 +21,43 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@Client.on_callback_query(filters.regex("sub_yes_[\s\S]*"))
|
@Client.on_callback_query(filters.regex("sub_yes_[\s\S]*"))
|
||||||
async def callback_query_yes(app: PyroClient, callback: CallbackQuery):
|
async def callback_query_yes(app: PyroClient, clb: CallbackQuery):
|
||||||
user = await app.find_user(callback.from_user)
|
user = await app.find_user(clb.from_user)
|
||||||
fullcallback = str(callback.data).split("_")
|
fullclb = str(clb.data).split("_")
|
||||||
|
|
||||||
db_entry = await col_submitted.find_one({"_id": ObjectId(fullcallback[2])})
|
db_entry = col_submitted.find_one({"_id": ObjectId(fullclb[2])})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
submission = await app.submit_media(
|
submission = await app.submit_media(fullclb[2])
|
||||||
fullcallback[2],
|
|
||||||
purge_caption=("caption" not in fullcallback),
|
|
||||||
)
|
|
||||||
except SubmissionUnavailableError:
|
except SubmissionUnavailableError:
|
||||||
await callback.answer(
|
await clb.answer(
|
||||||
text=app._("sub_msg_unavail", "callback", locale=user.locale),
|
text=app._("sub_msg_unavail", "callback", locale=user.locale),
|
||||||
show_alert=True,
|
show_alert=True,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
except SubmissionUnsupportedError:
|
except SubmissionUnsupportedError:
|
||||||
await callback.answer(
|
await clb.answer(
|
||||||
text=app._("mime_not_allowed", "message", locale=user.locale).format(
|
text=app._("mime_not_allowed", "message", locale=user.locale).format(
|
||||||
", ".join(app.config["submission"]["mime_types"]), quote=True
|
", ".join(app.config["submission"]["mime_types"]), quote=True
|
||||||
),
|
),
|
||||||
show_alert=True,
|
show_alert=True,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
except SubmissionDuplicatesError as exc:
|
except SubmissionDuplicatesError as exp:
|
||||||
await callback.answer(
|
await clb.answer(
|
||||||
text=app._("sub_duplicates_found", "callback", locale=user.locale),
|
text=app._("sub_duplicates_found", "callback", locale=user.locale),
|
||||||
show_alert=True,
|
show_alert=True,
|
||||||
)
|
)
|
||||||
await callback.message.reply_text(
|
await clb.message.reply_text(
|
||||||
app._("sub_media_duplicates_list", "message", locale=user.locale).format(
|
app._("sub_media_duplicates_list", "message", locale=user.locale).format(
|
||||||
"\n • ".join(exc.duplicates)
|
"\n • ".join(exp.duplicates)
|
||||||
),
|
),
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
"Submission with ID '%s' could not be accepted because of the duplicates: %s",
|
"Submission with ID '%s' could not be accepted because of the duplicates: %s",
|
||||||
fullcallback[2],
|
fullclb[2],
|
||||||
str(exc.duplicates),
|
str(exp.duplicates),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -83,8 +80,8 @@ async def callback_query_yes(app: PyroClient, callback: CallbackQuery):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
await callback.answer(
|
await clb.answer(
|
||||||
text=app._("sub_yes", "callback", locale=user.locale).format(fullcallback[2]),
|
text=app._("sub_yes", "callback", locale=user.locale).format(fullclb[2]),
|
||||||
show_alert=True,
|
show_alert=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -96,9 +93,9 @@ async def callback_query_yes(app: PyroClient, callback: CallbackQuery):
|
|||||||
callback_data="nothing",
|
callback_data="nothing",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
callback.message.reply_markup.inline_keyboard[1],
|
clb.message.reply_markup.inline_keyboard[1],
|
||||||
]
|
]
|
||||||
if len(callback.message.reply_markup.inline_keyboard) > 1
|
if len(clb.message.reply_markup.inline_keyboard) > 1
|
||||||
else [
|
else [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
@@ -110,44 +107,30 @@ async def callback_query_yes(app: PyroClient, callback: CallbackQuery):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if await config_get("send_uploaded_id", "submission"):
|
if await config_get("send_uploaded_id", "submission"):
|
||||||
await callback.message.edit_caption(
|
await clb.message.edit_caption(
|
||||||
f"{callback.message.caption}\n\nID: `{submission[1]}`"
|
f"{clb.message.caption}\n\nID: `{submission[1]}`"
|
||||||
)
|
)
|
||||||
|
|
||||||
await callback.message.edit_reply_markup(
|
await clb.message.edit_reply_markup(
|
||||||
reply_markup=InlineKeyboardMarkup(edited_markup)
|
reply_markup=InlineKeyboardMarkup(edited_markup)
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Submission with ID '%s' accepted and uploaded with ID '%s'",
|
"Submission with ID '%s' accepted and uploaded with ID '%s'",
|
||||||
fullcallback[2],
|
fullclb[2],
|
||||||
submission[1],
|
|
||||||
)
|
|
||||||
logger.info(
|
|
||||||
"Submission with ID '%s' accepted and uploaded with ID '%s'",
|
|
||||||
fullcallback[2],
|
|
||||||
submission[1],
|
submission[1],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@Client.on_callback_query(filters.regex("sub_no_[\s\S]*"))
|
@Client.on_callback_query(filters.regex("sub_no_[\s\S]*"))
|
||||||
async def callback_query_no(app: PyroClient, callback: CallbackQuery):
|
async def callback_query_no(app: PyroClient, clb: CallbackQuery):
|
||||||
user = await app.find_user(callback.from_user)
|
user = await app.find_user(clb.from_user)
|
||||||
fullcallback = str(callback.data).split("_")
|
fullclb = str(clb.data).split("_")
|
||||||
|
|
||||||
db_entry = await col_submitted.delete_one({"_id": ObjectId(fullcallback[2])})
|
db_entry = col_submitted.find_one_and_delete({"_id": ObjectId(fullclb[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()
|
||||||
@@ -163,8 +146,8 @@ async def callback_query_no(app: PyroClient, callback: CallbackQuery):
|
|||||||
submission = await app.get_messages(
|
submission = await app.get_messages(
|
||||||
db_entry["user"], db_entry["telegram"]["msg_id"]
|
db_entry["user"], db_entry["telegram"]["msg_id"]
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exp:
|
||||||
await callback.answer(
|
await clb.answer(
|
||||||
text=app._("sub_msg_unavail", "message", locale=user.locale),
|
text=app._("sub_msg_unavail", "message", locale=user.locale),
|
||||||
show_alert=True,
|
show_alert=True,
|
||||||
)
|
)
|
||||||
@@ -178,8 +161,8 @@ async def callback_query_no(app: PyroClient, callback: CallbackQuery):
|
|||||||
),
|
),
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
await callback.answer(
|
await clb.answer(
|
||||||
text=app._("sub_no", "callback", locale=user.locale).format(fullcallback[2]),
|
text=app._("sub_no", "callback", locale=user.locale).format(fullclb[2]),
|
||||||
show_alert=True,
|
show_alert=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -191,9 +174,9 @@ async def callback_query_no(app: PyroClient, callback: CallbackQuery):
|
|||||||
callback_data="nothing",
|
callback_data="nothing",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
callback.message.reply_markup.inline_keyboard[1],
|
clb.message.reply_markup.inline_keyboard[1],
|
||||||
]
|
]
|
||||||
if len(callback.message.reply_markup.inline_keyboard) > 1
|
if len(clb.message.reply_markup.inline_keyboard) > 1
|
||||||
else [
|
else [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
@@ -203,83 +186,81 @@ async def callback_query_no(app: PyroClient, callback: CallbackQuery):
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
await callback.message.edit_reply_markup(
|
await clb.message.edit_reply_markup(
|
||||||
reply_markup=InlineKeyboardMarkup(edited_markup)
|
reply_markup=InlineKeyboardMarkup(edited_markup)
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
"Submission with ID '%s' rejected",
|
"Submission with ID '%s' rejected",
|
||||||
fullcallback[2],
|
fullclb[2],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@Client.on_callback_query(filters.regex("sub_block_[\s\S]*"))
|
@Client.on_callback_query(filters.regex("sub_block_[\s\S]*"))
|
||||||
async def callback_query_block(app: PyroClient, callback: CallbackQuery):
|
async def callback_query_block(app: PyroClient, clb: CallbackQuery):
|
||||||
user = await app.find_user(callback.from_user)
|
user = await app.find_user(clb.from_user)
|
||||||
fullcallback = str(callback.data).split("_")
|
fullclb = str(clb.data).split("_")
|
||||||
|
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
int(fullcallback[2]),
|
int(fullclb[2]),
|
||||||
app._(
|
app._(
|
||||||
"sub_blocked",
|
"sub_blocked",
|
||||||
"message",
|
"message",
|
||||||
locale=(await app.find_user(int(fullcallback[2]))).locale,
|
locale=(await app.find_user(int(fullclb[2]))).locale,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
await user.block()
|
await user.block()
|
||||||
|
|
||||||
await callback.answer(
|
await clb.answer(
|
||||||
text=app._("sub_block", "callback", locale=user.locale).format(fullcallback[2]),
|
text=app._("sub_block", "callback", locale=user.locale).format(fullclb[2]),
|
||||||
show_alert=True,
|
show_alert=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
edited_markup = [
|
edited_markup = [
|
||||||
callback.message.reply_markup.inline_keyboard[0],
|
clb.message.reply_markup.inline_keyboard[0],
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
text=str(app._("sub_unblock", "button", locale=user.locale)),
|
text=str(app._("sub_unblock", "button", locale=user.locale)),
|
||||||
callback_data=f"sub_unblock_{fullcallback[2]}",
|
callback_data=f"sub_unblock_{fullclb[2]}",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
await callback.message.edit_reply_markup(
|
await clb.message.edit_reply_markup(
|
||||||
reply_markup=InlineKeyboardMarkup(edited_markup)
|
reply_markup=InlineKeyboardMarkup(edited_markup)
|
||||||
)
|
)
|
||||||
logger.info("User %s has been blocked", fullcallback[2])
|
logger.info("User %s has been blocked", fullclb[2])
|
||||||
|
|
||||||
|
|
||||||
@Client.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
|
@Client.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
|
||||||
async def callback_query_unblock(app: PyroClient, callback: CallbackQuery):
|
async def callback_query_unblock(app: PyroClient, clb: CallbackQuery):
|
||||||
user = await app.find_user(callback.from_user)
|
user = await app.find_user(clb.from_user)
|
||||||
fullcallback = str(callback.data).split("_")
|
fullclb = str(clb.data).split("_")
|
||||||
|
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
int(fullcallback[2]),
|
int(fullclb[2]),
|
||||||
app._(
|
app._(
|
||||||
"sub_unblocked",
|
"sub_unblocked",
|
||||||
"message",
|
"message",
|
||||||
locale=(await app.find_user(int(fullcallback[2]))).locale,
|
locale=(await app.find_user(int(fullclb[2]))).locale,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
await user.unblock()
|
await user.unblock()
|
||||||
|
|
||||||
await callback.answer(
|
await clb.answer(
|
||||||
text=app._("sub_unblock", "callback", locale=user.locale).format(
|
text=app._("sub_unblock", "callback", locale=user.locale).format(fullclb[2]),
|
||||||
fullcallback[2]
|
|
||||||
),
|
|
||||||
show_alert=True,
|
show_alert=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
edited_markup = [
|
edited_markup = [
|
||||||
callback.message.reply_markup.inline_keyboard[0],
|
clb.message.reply_markup.inline_keyboard[0],
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
text=str(app._("sub_block", "button", locale=user.locale)),
|
text=str(app._("sub_block", "button", locale=user.locale)),
|
||||||
callback_data=f"sub_block_{fullcallback[2]}",
|
callback_data=f"sub_block_{fullclb[2]}",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
await callback.message.edit_reply_markup(
|
await clb.message.edit_reply_markup(
|
||||||
reply_markup=InlineKeyboardMarkup(edited_markup)
|
reply_markup=InlineKeyboardMarkup(edited_markup)
|
||||||
)
|
)
|
||||||
logger.info("User %s has been unblocked", fullcallback[2])
|
logger.info("User %s has been unblocked", fullclb[2])
|
||||||
|
@@ -15,14 +15,14 @@ from modules.utils import USERS_WITH_CONTEXT
|
|||||||
@Client.on_message(
|
@Client.on_message(
|
||||||
~filters.scheduled & filters.command(["shutdown"], prefixes=["", "/"])
|
~filters.scheduled & filters.command(["shutdown"], prefixes=["", "/"])
|
||||||
)
|
)
|
||||||
async def cmd_kill(app: PyroClient, message: Message):
|
async def cmd_kill(app: PyroClient, msg: Message):
|
||||||
if message.from_user.id not in app.admins:
|
if msg.from_user.id not in app.admins:
|
||||||
return
|
return
|
||||||
|
|
||||||
user = await app.find_user(message.from_user)
|
user = await app.find_user(msg.from_user)
|
||||||
|
|
||||||
if len(USERS_WITH_CONTEXT) > 0:
|
if len(USERS_WITH_CONTEXT) > 0:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("shutdown_confirm", "message", locale=user.locale).format(
|
app._("shutdown_confirm", "message", locale=user.locale).format(
|
||||||
len(USERS_WITH_CONTEXT)
|
len(USERS_WITH_CONTEXT)
|
||||||
),
|
),
|
||||||
|
@@ -3,32 +3,25 @@ from pyrogram.client import Client
|
|||||||
from pyrogram.types import Message
|
from pyrogram.types import Message
|
||||||
|
|
||||||
from classes.pyroclient import PyroClient
|
from classes.pyroclient import PyroClient
|
||||||
from modules import custom_filters
|
|
||||||
|
|
||||||
|
|
||||||
@Client.on_message(
|
@Client.on_message(~filters.scheduled & filters.command(["start"], prefixes="/"))
|
||||||
custom_filters.mode_submit
|
async def cmd_start(app: PyroClient, msg: Message):
|
||||||
& ~filters.scheduled
|
user = await app.find_user(msg.from_user)
|
||||||
& filters.command(["start"], prefixes="/")
|
|
||||||
)
|
|
||||||
async def cmd_start(app: PyroClient, message: Message):
|
|
||||||
user = await app.find_user(message.from_user)
|
|
||||||
|
|
||||||
if user.banned:
|
if user.banned:
|
||||||
return
|
return
|
||||||
|
|
||||||
await message.reply_text(app._("start", "message", locale=user.locale))
|
await msg.reply_text(app._("start", "message", locale=user.locale))
|
||||||
|
|
||||||
|
|
||||||
@Client.on_message(
|
@Client.on_message(
|
||||||
custom_filters.mode_submit
|
~filters.scheduled & filters.command(["rules", "help"], prefixes="/")
|
||||||
& ~filters.scheduled
|
|
||||||
& filters.command(["rules", "help"], prefixes="/")
|
|
||||||
)
|
)
|
||||||
async def cmd_rules(app: PyroClient, message: Message):
|
async def cmd_rules(app: PyroClient, msg: Message):
|
||||||
user = await app.find_user(message.from_user)
|
user = await app.find_user(msg.from_user)
|
||||||
|
|
||||||
if user.banned:
|
if user.banned:
|
||||||
return
|
return
|
||||||
|
|
||||||
await message.reply_text(app._("rules", "message", locale=user.locale))
|
await msg.reply_text(app._("rules", "message", locale=user.locale))
|
||||||
|
@@ -37,27 +37,27 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@Client.on_message(~filters.scheduled & filters.command(["import"], prefixes=["", "/"]))
|
@Client.on_message(~filters.scheduled & filters.command(["import"], prefixes=["", "/"]))
|
||||||
async def cmd_import(app: PyroClient, message: Message):
|
async def cmd_import(app: PyroClient, msg: Message):
|
||||||
if message.from_user.id not in app.admins:
|
if msg.from_user.id not in app.admins:
|
||||||
return
|
return
|
||||||
|
|
||||||
global USERS_WITH_CONTEXT
|
global USERS_WITH_CONTEXT
|
||||||
|
|
||||||
if message.from_user.id not in USERS_WITH_CONTEXT:
|
if msg.from_user.id not in USERS_WITH_CONTEXT:
|
||||||
USERS_WITH_CONTEXT.append(message.from_user.id)
|
USERS_WITH_CONTEXT.append(msg.from_user.id)
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
user = await app.find_user(message.from_user)
|
user = await app.find_user(msg.from_user)
|
||||||
|
|
||||||
await message.reply_text(app._("import_request", "message", locale=user.locale))
|
await msg.reply_text(app._("import_request", "message", locale=user.locale))
|
||||||
|
|
||||||
answer = await listen_message(app, message.chat.id, timeout=600)
|
answer = await listen_message(app, msg.chat.id, timeout=600)
|
||||||
|
|
||||||
USERS_WITH_CONTEXT.remove(message.from_user.id)
|
USERS_WITH_CONTEXT.remove(msg.from_user.id)
|
||||||
|
|
||||||
if answer is None:
|
if answer is None:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("import_ignored", "message", locale=user.locale),
|
app._("import_ignored", "message", locale=user.locale),
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
@@ -86,7 +86,7 @@ async def cmd_import(app: PyroClient, message: Message):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if disk_usage(getcwd())[2] < (answer.document.file_size) * 3:
|
if disk_usage(getcwd())[2] < (answer.document.file_size) * 3:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("import_too_big", "message", locale=user.locale).format(
|
app._("import_too_big", "message", locale=user.locale).format(
|
||||||
answer.document.file_size // (2**30),
|
answer.document.file_size // (2**30),
|
||||||
disk_usage(getcwd())[2] // (2**30),
|
disk_usage(getcwd())[2] // (2**30),
|
||||||
@@ -123,16 +123,16 @@ async def cmd_import(app: PyroClient, message: Message):
|
|||||||
for name in handle.namelist()
|
for name in handle.namelist()
|
||||||
]
|
]
|
||||||
_ = await asyncio.gather(*tasks)
|
_ = await asyncio.gather(*tasks)
|
||||||
except Exception as exc:
|
except Exception as exp:
|
||||||
logger.error(
|
logger.error(
|
||||||
"Could not import '%s' due to %s: %s",
|
"Could not import '%s' due to %s: %s",
|
||||||
answer.document.file_name,
|
answer.document.file_name,
|
||||||
exc,
|
exp,
|
||||||
format_exc(),
|
format_exc(),
|
||||||
)
|
)
|
||||||
await answer.reply_text(
|
await answer.reply_text(
|
||||||
app._("import_unpack_error", "message", locale=user.locale).format(
|
app._("import_unpack_error", "message", locale=user.locale).format(
|
||||||
exc, format_exc()
|
exp, format_exc()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@@ -158,21 +158,21 @@ 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"],
|
||||||
compress=False,
|
compress=False,
|
||||||
caption="queue",
|
caption="queue",
|
||||||
)
|
)
|
||||||
except UnexpectedStatus as exc:
|
except UnexpectedStatus as exp:
|
||||||
logger.error(
|
logger.error(
|
||||||
"Could not upload '%s' from '%s': %s",
|
"Could not upload '%s' from '%s': %s",
|
||||||
filename,
|
filename,
|
||||||
Path(f"{app.config['locations']['tmp']}/{tmp_dir}"),
|
Path(f"{app.config['locations']['tmp']}/{tmp_dir}"),
|
||||||
exc,
|
exp,
|
||||||
)
|
)
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._(
|
app._(
|
||||||
"import_upload_error_other",
|
"import_upload_error_other",
|
||||||
"message",
|
"message",
|
||||||
@@ -193,7 +193,7 @@ async def cmd_import(app: PyroClient, message: Message):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if len(uploaded_dict["duplicates"]) > 0:
|
if len(uploaded_dict["duplicates"]) > 0:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._(
|
app._(
|
||||||
"import_upload_error_duplicate",
|
"import_upload_error_duplicate",
|
||||||
"message",
|
"message",
|
||||||
@@ -202,7 +202,7 @@ async def cmd_import(app: PyroClient, message: Message):
|
|||||||
disable_notification=True,
|
disable_notification=True,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._(
|
app._(
|
||||||
"import_upload_error_other",
|
"import_upload_error_other",
|
||||||
"message",
|
"message",
|
||||||
@@ -235,35 +235,33 @@ async def cmd_import(app: PyroClient, message: Message):
|
|||||||
|
|
||||||
|
|
||||||
@Client.on_message(~filters.scheduled & filters.command(["export"], prefixes=["", "/"]))
|
@Client.on_message(~filters.scheduled & filters.command(["export"], prefixes=["", "/"]))
|
||||||
async def cmd_export(app: PyroClient, message: Message):
|
async def cmd_export(app: PyroClient, msg: Message):
|
||||||
if message.from_user.id not in app.admins:
|
if msg.from_user.id not in app.admins:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@Client.on_message(~filters.scheduled & filters.command(["remove"], prefixes=["", "/"]))
|
@Client.on_message(~filters.scheduled & filters.command(["remove"], prefixes=["", "/"]))
|
||||||
async def cmd_remove(app: PyroClient, message: Message):
|
async def cmd_remove(app: PyroClient, msg: Message):
|
||||||
if message.from_user.id not in app.admins:
|
if msg.from_user.id not in app.admins:
|
||||||
return
|
return
|
||||||
|
|
||||||
global USERS_WITH_CONTEXT
|
global USERS_WITH_CONTEXT
|
||||||
|
|
||||||
if message.from_user.id not in USERS_WITH_CONTEXT:
|
if msg.from_user.id not in USERS_WITH_CONTEXT:
|
||||||
USERS_WITH_CONTEXT.append(message.from_user.id)
|
USERS_WITH_CONTEXT.append(msg.from_user.id)
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
user = await app.find_user(message.from_user)
|
user = await app.find_user(msg.from_user)
|
||||||
|
|
||||||
await message.reply_text(app._("remove_request", "message", locale=user.locale))
|
await msg.reply_text(app._("remove_request", "message", locale=user.locale))
|
||||||
|
|
||||||
answer_id = await app.listen.Message(
|
answer_id = await listen_message(app, msg.chat.id, timeout=600)
|
||||||
filters.text & ~filters.me, id=filters.user(message.from_user.id), timeout=600
|
|
||||||
)
|
|
||||||
|
|
||||||
USERS_WITH_CONTEXT.remove(message.from_user.id)
|
USERS_WITH_CONTEXT.remove(msg.from_user.id)
|
||||||
|
|
||||||
if answer_id is None:
|
if answer_id is None:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("remove_ignored", "message", locale=user.locale),
|
app._("remove_ignored", "message", locale=user.locale),
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
@@ -273,7 +271,7 @@ async def cmd_remove(app: PyroClient, message: Message):
|
|||||||
await answer_id.reply_text(app._("remove_abort", "message", locale=user.locale))
|
await answer_id.reply_text(app._("remove_abort", "message", locale=user.locale))
|
||||||
return
|
return
|
||||||
|
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("remove_kind", "message", locale=user.locale),
|
app._("remove_kind", "message", locale=user.locale),
|
||||||
reply_markup=ReplyKeyboardMarkup(
|
reply_markup=ReplyKeyboardMarkup(
|
||||||
[
|
[
|
||||||
@@ -287,16 +285,14 @@ async def cmd_remove(app: PyroClient, message: Message):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
USERS_WITH_CONTEXT.append(message.from_user.id)
|
USERS_WITH_CONTEXT.append(msg.from_user.id)
|
||||||
|
|
||||||
answer_kind = await app.listen.Message(
|
answer_kind = await listen_message(app, msg.chat.id, timeout=600)
|
||||||
filters.text & ~filters.me, id=filters.user(message.from_user.id), timeout=600
|
|
||||||
)
|
|
||||||
|
|
||||||
USERS_WITH_CONTEXT.remove(message.from_user.id)
|
USERS_WITH_CONTEXT.remove(msg.from_user.id)
|
||||||
|
|
||||||
if answer_kind is None:
|
if answer_kind is None:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("remove_ignored", "message", locale=user.locale),
|
app._("remove_ignored", "message", locale=user.locale),
|
||||||
quote=True,
|
quote=True,
|
||||||
reply_markup=ReplyKeyboardRemove(),
|
reply_markup=ReplyKeyboardRemove(),
|
||||||
@@ -355,6 +351,6 @@ async def cmd_remove(app: PyroClient, message: Message):
|
|||||||
|
|
||||||
|
|
||||||
@Client.on_message(~filters.scheduled & filters.command(["purge"], prefixes=["", "/"]))
|
@Client.on_message(~filters.scheduled & filters.command(["purge"], prefixes=["", "/"]))
|
||||||
async def cmd_purge(app: PyroClient, message: Message):
|
async def cmd_purge(app: PyroClient, msg: Message):
|
||||||
if message.from_user.id not in app.admins:
|
if msg.from_user.id not in app.admins:
|
||||||
return
|
return
|
||||||
|
@@ -4,35 +4,32 @@ from pyrogram.client import Client
|
|||||||
from pyrogram.types import Message, User
|
from pyrogram.types import Message, User
|
||||||
|
|
||||||
from classes.pyroclient import PyroClient
|
from classes.pyroclient import PyroClient
|
||||||
from modules import custom_filters
|
|
||||||
|
|
||||||
|
|
||||||
@Client.on_message(
|
@Client.on_message(
|
||||||
custom_filters.mode_post
|
~filters.scheduled
|
||||||
& ~filters.scheduled
|
|
||||||
& filters.chat(sync.config_get("comments", "posting"))
|
& filters.chat(sync.config_get("comments", "posting"))
|
||||||
& filters.reply
|
& filters.reply
|
||||||
& filters.command(["report"], prefixes=["", "/"])
|
& filters.command(["report"], prefixes=["", "/"])
|
||||||
)
|
)
|
||||||
async def command_report(app: PyroClient, message: Message):
|
async def command_report(app: PyroClient, msg: Message):
|
||||||
if (
|
if msg.reply_to_message.forward_from_chat.id != app.config["posting"]["channel"]:
|
||||||
message.reply_to_message.forward_from_chat.id
|
|
||||||
!= app.config["posting"]["channel"]
|
|
||||||
):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
user = await app.find_user(message.from_user)
|
user = await app.find_user(msg.from_user)
|
||||||
|
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._(
|
app._(
|
||||||
"report_sent",
|
"report_sent",
|
||||||
"message",
|
"message",
|
||||||
locale=user.locale if message.from_user is not None else None,
|
locale=user.locale if msg.from_user is not None else None,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
report_sent = await message.reply_to_message.forward(app.owner)
|
print(msg)
|
||||||
sender = message.from_user if message.from_user is not None else message.sender_chat
|
|
||||||
|
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
|
sender_name = sender.first_name if isinstance(sender, User) else sender.title
|
||||||
|
|
||||||
|
@@ -13,7 +13,6 @@ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
|
|||||||
from classes.enums.submission_types import SubmissionType
|
from classes.enums.submission_types import SubmissionType
|
||||||
from classes.exceptions import SubmissionDuplicatesError, SubmissionUnsupportedError
|
from classes.exceptions import SubmissionDuplicatesError, SubmissionUnsupportedError
|
||||||
from classes.pyroclient import PyroClient
|
from classes.pyroclient import PyroClient
|
||||||
from modules import custom_filters
|
|
||||||
from modules.database import col_submitted
|
from modules.database import col_submitted
|
||||||
from modules.utils import USERS_WITH_CONTEXT
|
from modules.utils import USERS_WITH_CONTEXT
|
||||||
|
|
||||||
@@ -21,126 +20,120 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@Client.on_message(
|
@Client.on_message(
|
||||||
custom_filters.mode_submit & ~filters.scheduled & filters.private & filters.photo
|
~filters.scheduled & filters.private & filters.photo
|
||||||
| filters.video
|
| filters.video
|
||||||
# | filters.animation
|
# | filters.animation
|
||||||
| filters.document
|
| filters.document
|
||||||
)
|
)
|
||||||
async def get_submission(app: PyroClient, message: Message):
|
async def get_submission(app: PyroClient, msg: Message):
|
||||||
global USERS_WITH_CONTEXT
|
global USERS_WITH_CONTEXT
|
||||||
|
|
||||||
if not hasattr(message.from_user, "id"):
|
if not hasattr(msg.from_user, "id"):
|
||||||
return
|
return
|
||||||
|
|
||||||
if message.from_user.id in USERS_WITH_CONTEXT:
|
if msg.from_user.id in USERS_WITH_CONTEXT:
|
||||||
return
|
return
|
||||||
|
|
||||||
user = await app.find_user(message.from_user)
|
user = await app.find_user(msg.from_user)
|
||||||
user_owner = await app.find_user(app.owner)
|
user_owner = await app.find_user(app.owner)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if user.banned:
|
if user.banned:
|
||||||
return
|
return
|
||||||
|
|
||||||
await app.send_chat_action(message.chat.id, ChatAction.TYPING)
|
await app.send_chat_action(msg.chat.id, ChatAction.TYPING)
|
||||||
|
|
||||||
save_tmp = True
|
save_tmp = True
|
||||||
contents = None
|
contents = None
|
||||||
|
|
||||||
if await user.is_limited():
|
if await user.is_limited():
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("sub_cooldown", "message", locale=user.locale).format(
|
app._("sub_cooldown", "message", locale=user.locale).format(
|
||||||
app.config["submission"]["timeout"]
|
app.config["submission"]["timeout"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if message.document is not None:
|
if msg.document is not None:
|
||||||
logger.info(
|
logger.info(
|
||||||
"User %s is trying to submit a file of type '%s' with name '%s' and size of %s MB",
|
"User %s is trying to submit a file of type '%s' with name '%s' and size of %s MB",
|
||||||
message.from_user.id,
|
msg.from_user.id,
|
||||||
message.document.mime_type,
|
msg.document.mime_type,
|
||||||
message.document.file_name,
|
msg.document.file_name,
|
||||||
message.document.file_size / 1024 / 1024,
|
msg.document.file_size / 1024 / 1024,
|
||||||
)
|
)
|
||||||
if message.document.mime_type not in app.config["submission"]["mime_types"]:
|
if msg.document.mime_type not in app.config["submission"]["mime_types"]:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("mime_not_allowed", "message", locale=user.locale).format(
|
app._("mime_not_allowed", "message", locale=user.locale).format(
|
||||||
", ".join(app.config["submission"]["mime_types"])
|
", ".join(app.config["submission"]["mime_types"])
|
||||||
),
|
),
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if message.document.file_size > app.config["submission"]["file_size"]:
|
if msg.document.file_size > app.config["submission"]["file_size"]:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("document_too_large", "message", locale=user.locale).format(
|
app._("document_too_large", "message", locale=user.locale).format(
|
||||||
app.config["submission"]["file_size"] / 1024 / 1024
|
app.config["submission"]["file_size"] / 1024 / 1024
|
||||||
),
|
),
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if message.document.file_size > app.config["submission"]["tmp_size"]:
|
if msg.document.file_size > app.config["submission"]["tmp_size"]:
|
||||||
save_tmp = False
|
save_tmp = False
|
||||||
contents = (
|
contents = (
|
||||||
message.document.file_id,
|
msg.document.file_id,
|
||||||
SubmissionType.DOCUMENT,
|
SubmissionType.DOCUMENT,
|
||||||
) # , message.document.file_name
|
) # , msg.document.file_name
|
||||||
|
|
||||||
if message.video is not None:
|
if msg.video is not None:
|
||||||
logger.info(
|
logger.info(
|
||||||
"User %s is trying to submit a video with name '%s' and size of %s MB",
|
"User %s is trying to submit a video with name '%s' and size of %s MB",
|
||||||
message.from_user.id,
|
msg.from_user.id,
|
||||||
message.video.file_name,
|
msg.video.file_name,
|
||||||
message.video.file_size / 1024 / 1024,
|
msg.video.file_size / 1024 / 1024,
|
||||||
)
|
)
|
||||||
if message.video.file_size > app.config["submission"]["file_size"]:
|
if msg.video.file_size > app.config["submission"]["file_size"]:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("document_too_large", "message", locale=user.locale).format(
|
app._("document_too_large", "message", locale=user.locale).format(
|
||||||
app.config["submission"]["file_size"] / 1024 / 1024
|
app.config["submission"]["file_size"] / 1024 / 1024
|
||||||
),
|
),
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if message.video.file_size > app.config["submission"]["tmp_size"]:
|
if msg.video.file_size > app.config["submission"]["tmp_size"]:
|
||||||
save_tmp = False
|
save_tmp = False
|
||||||
contents = (
|
contents = msg.video.file_id, SubmissionType.VIDEO # , msg.video.file_name
|
||||||
message.video.file_id,
|
|
||||||
SubmissionType.VIDEO,
|
|
||||||
) # , message.video.file_name
|
|
||||||
|
|
||||||
# if message.animation is not None:
|
# if msg.animation is not None:
|
||||||
# logger.info(
|
# logger.info(
|
||||||
# "User %s is trying to submit an animation with name '%s' and size of %s MB",
|
# "User %s is trying to submit an animation with name '%s' and size of %s MB",
|
||||||
# message.from_user.id,
|
# msg.from_user.id,
|
||||||
# message.animation.file_name,
|
# msg.animation.file_name,
|
||||||
# message.animation.file_size / 1024 / 1024,
|
# msg.animation.file_size / 1024 / 1024,
|
||||||
# )
|
# )
|
||||||
# if message.animation.file_size > app.config["submission"]["file_size"]:
|
# if msg.animation.file_size > app.config["submission"]["file_size"]:
|
||||||
# await message.reply_text(
|
# await msg.reply_text(
|
||||||
# app._("document_too_large", "message", locale=user.locale).format(
|
# app._("document_too_large", "message", locale=user.locale).format(
|
||||||
# str(app.config["submission"]["file_size"] / 1024 / 1024)
|
# str(app.config["submission"]["file_size"] / 1024 / 1024)
|
||||||
# ),
|
# ),
|
||||||
# quote=True,
|
# quote=True,
|
||||||
# )
|
# )
|
||||||
# return
|
# return
|
||||||
# if message.animation.file_size > app.config["submission"]["tmp_size"]:
|
# if msg.animation.file_size > app.config["submission"]["tmp_size"]:
|
||||||
# save_tmp = False
|
# save_tmp = False
|
||||||
# contents = (
|
# contents = (
|
||||||
# message.animation.file_id,
|
# msg.animation.file_id,
|
||||||
# SubmissionType.ANIMATION,
|
# SubmissionType.ANIMATION,
|
||||||
# ) # , message.animation.file_name
|
# ) # , msg.animation.file_name
|
||||||
|
|
||||||
if message.photo is not None:
|
if msg.photo is not None:
|
||||||
logger.info(
|
logger.info(
|
||||||
"User %s is trying to submit a photo with ID '%s' and size of %s MB",
|
"User %s is trying to submit a photo with ID '%s' and size of %s MB",
|
||||||
message.from_user.id,
|
msg.from_user.id,
|
||||||
message.photo.file_id,
|
msg.photo.file_id,
|
||||||
message.photo.file_size / 1024 / 1024,
|
msg.photo.file_size / 1024 / 1024,
|
||||||
)
|
)
|
||||||
contents = (
|
contents = msg.photo.file_id, SubmissionType.PHOTO # , "please_generate"
|
||||||
message.photo.file_id,
|
|
||||||
SubmissionType.PHOTO,
|
|
||||||
) # , "please_generate"
|
|
||||||
|
|
||||||
if contents is None:
|
if contents is None:
|
||||||
return
|
return
|
||||||
@@ -154,37 +147,33 @@ async def get_submission(app: PyroClient, message: Message):
|
|||||||
exist_ok=True,
|
exist_ok=True,
|
||||||
)
|
)
|
||||||
downloaded = await app.download_media(
|
downloaded = await app.download_media(
|
||||||
message,
|
msg,
|
||||||
str(Path(f"{app.config['locations']['data']}/submissions/{tmp_id}"))
|
str(Path(f"{app.config['locations']['data']}/submissions/{tmp_id}"))
|
||||||
+ sep,
|
+ sep,
|
||||||
)
|
)
|
||||||
|
|
||||||
inserted = await col_submitted.insert_one(
|
inserted = col_submitted.insert_one(
|
||||||
{
|
{
|
||||||
"user": message.from_user.id,
|
"user": msg.from_user.id,
|
||||||
"date": datetime.now(),
|
"date": datetime.now(),
|
||||||
"done": False,
|
"done": False,
|
||||||
"type": contents[1].value,
|
"type": contents[1].value,
|
||||||
"temp": {"uuid": tmp_id, "file": path.basename(str(downloaded))},
|
"temp": {"uuid": tmp_id, "file": path.basename(str(downloaded))},
|
||||||
"telegram": {"msg_id": message.id, "file_id": contents[0]},
|
"telegram": {"msg_id": msg.id, "file_id": contents[0]},
|
||||||
"caption": str(message.caption)
|
"caption": str(msg.caption) if msg.caption is not None else None,
|
||||||
if message.caption is not None
|
|
||||||
else None,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
inserted = await col_submitted.insert_one(
|
inserted = col_submitted.insert_one(
|
||||||
{
|
{
|
||||||
"user": message.from_user.id,
|
"user": msg.from_user.id,
|
||||||
"date": datetime.now(),
|
"date": datetime.now(),
|
||||||
"done": False,
|
"done": False,
|
||||||
"type": contents[1].value,
|
"type": contents[1].value,
|
||||||
"temp": {"uuid": None, "file": None},
|
"temp": {"uuid": None, "file": None},
|
||||||
"telegram": {"msg_id": message.id, "file_id": contents[0]},
|
"telegram": {"msg_id": msg.id, "file_id": contents[0]},
|
||||||
"caption": str(message.caption)
|
"caption": str(msg.caption) if msg.caption is not None else None,
|
||||||
if message.caption is not None
|
|
||||||
else None,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -197,8 +186,8 @@ async def get_submission(app: PyroClient, message: Message):
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
if message.caption is not None:
|
if msg.caption is not None:
|
||||||
caption = str(message.caption)
|
caption = str(msg.caption)
|
||||||
buttons[0].append(
|
buttons[0].append(
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
text=app._("sub_yes_caption", "button", locale=user_owner.locale),
|
text=app._("sub_yes_caption", "button", locale=user_owner.locale),
|
||||||
@@ -216,108 +205,106 @@ async def get_submission(app: PyroClient, message: Message):
|
|||||||
)
|
)
|
||||||
caption += app._("sub_by", "message", locale=user_owner.locale)
|
caption += app._("sub_by", "message", locale=user_owner.locale)
|
||||||
|
|
||||||
if message.from_user.first_name is not None:
|
if msg.from_user.first_name is not None:
|
||||||
caption += f" {message.from_user.first_name}"
|
caption += f" {msg.from_user.first_name}"
|
||||||
if message.from_user.last_name is not None:
|
if msg.from_user.last_name is not None:
|
||||||
caption += f" {message.from_user.last_name}"
|
caption += f" {msg.from_user.last_name}"
|
||||||
if message.from_user.username is not None:
|
if msg.from_user.username is not None:
|
||||||
caption += f" (@{message.from_user.username})"
|
caption += f" (@{msg.from_user.username})"
|
||||||
if message.from_user.phone_number is not None:
|
if msg.from_user.phone_number is not None:
|
||||||
caption += f" ({message.from_user.phone_number})"
|
caption += f" ({msg.from_user.phone_number})"
|
||||||
|
|
||||||
if (
|
if (
|
||||||
message.from_user.id in app.admins
|
msg.from_user.id in app.admins
|
||||||
and app.config["submission"]["require_confirmation"]["admins"] is False
|
and app.config["submission"]["require_confirmation"]["admins"] is False
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
submitted = await app.submit_media(str(inserted.inserted_id))
|
submitted = await app.submit_media(str(inserted.inserted_id))
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("sub_yes_auto", "message", locale=user.locale),
|
app._("sub_yes_auto", "message", locale=user.locale),
|
||||||
disable_notification=True,
|
disable_notification=True,
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
if app.config["submission"]["send_uploaded_id"]:
|
if app.config["submission"]["send_uploaded_id"]:
|
||||||
caption += f"\n\nID: `{submitted[1]}`"
|
caption += f"\n\nID: `{submitted[1]}`"
|
||||||
await message.copy(
|
await msg.copy(app.owner, caption=caption, disable_notification=True)
|
||||||
app.owner, caption=caption, disable_notification=True
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
except SubmissionUnsupportedError:
|
except SubmissionUnsupportedError:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("mime_not_allowed", "message", locale=user.locale).format(
|
app._("mime_not_allowed", "message", locale=user.locale).format(
|
||||||
", ".join(app.config["submission"]["mime_types"]), quote=True
|
", ".join(app.config["submission"]["mime_types"]), quote=True
|
||||||
),
|
),
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
except SubmissionDuplicatesError as exc:
|
except SubmissionDuplicatesError as exp:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._(
|
app._(
|
||||||
"sub_media_duplicates_list", "message", locale=user.locale
|
"sub_media_duplicates_list", "message", locale=user.locale
|
||||||
).format("\n • ".join(exc.duplicates)),
|
).format("\n • ".join(exp.duplicates)),
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
except Exception as exc:
|
except Exception as exp:
|
||||||
await message.reply_text(exc, quote=True)
|
await msg.reply_text(format_exc(), quote=True)
|
||||||
return
|
return
|
||||||
elif (
|
elif (
|
||||||
message.from_user.id not in app.admins
|
msg.from_user.id not in app.admins
|
||||||
and app.config["submission"]["require_confirmation"]["users"] is False
|
and app.config["submission"]["require_confirmation"]["users"] is False
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
submitted = await app.submit_photo(str(inserted.inserted_id))
|
submitted = await app.submit_photo(str(inserted.inserted_id))
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("sub_yes_auto", "message", locale=user.locale),
|
app._("sub_yes_auto", "message", locale=user.locale),
|
||||||
disable_notification=True,
|
disable_notification=True,
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
if app.config["submission"]["send_uploaded_id"]:
|
if app.config["submission"]["send_uploaded_id"]:
|
||||||
caption += f"\n\nID: `{submitted[1]}`"
|
caption += f"\n\nID: `{submitted[1]}`"
|
||||||
await message.copy(app.owner, caption=caption)
|
await msg.copy(app.owner, caption=caption)
|
||||||
return
|
return
|
||||||
except SubmissionUnsupportedError:
|
except SubmissionUnsupportedError:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("mime_not_allowed", "message", locale=user.locale).format(
|
app._("mime_not_allowed", "message", locale=user.locale).format(
|
||||||
", ".join(app.config["submission"]["mime_types"]), quote=True
|
", ".join(app.config["submission"]["mime_types"]), quote=True
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
except SubmissionDuplicatesError as exc:
|
except SubmissionDuplicatesError as exp:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("sub_dup", "message", locale=user.locale), quote=True
|
app._("sub_dup", "message", locale=user.locale), quote=True
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
except Exception as exc:
|
except Exception as exp:
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
app.owner,
|
app.owner,
|
||||||
app._(
|
app._(
|
||||||
"sub_error_admin", "message", locale=user_owner.locale
|
"sub_error_admin", "message", locale=user_owner.locale
|
||||||
).format(message.from_user.id, format_exc()),
|
).format(msg.from_user.id, format_exc()),
|
||||||
)
|
)
|
||||||
await message.reply_text("sub_error", quote=True)
|
await msg.reply_text("sub_error", quote=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
if message.from_user.id not in app.admins:
|
if msg.from_user.id not in app.admins:
|
||||||
buttons += [
|
buttons += [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
text=app._("sub_block", "button", locale=user_owner.locale),
|
text=app._("sub_block", "button", locale=user_owner.locale),
|
||||||
callback_data=f"sub_block_{message.from_user.id}",
|
callback_data=f"sub_block_{msg.from_user.id}",
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
await user.update_cooldown()
|
await user.update_cooldown()
|
||||||
|
|
||||||
if message.from_user.id != app.owner:
|
if msg.from_user.id != app.owner:
|
||||||
await message.reply_text(
|
await msg.reply_text(
|
||||||
app._("sub_sent", "message", locale=user.locale),
|
app._("sub_sent", "message", locale=user.locale),
|
||||||
disable_notification=True,
|
disable_notification=True,
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
await message.copy(
|
await msg.copy(
|
||||||
app.owner, caption=caption, reply_markup=InlineKeyboardMarkup(buttons)
|
app.owner, caption=caption, reply_markup=InlineKeyboardMarkup(buttons)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -8,6 +8,6 @@ from classes.pyroclient import PyroClient
|
|||||||
@Client.on_message(
|
@Client.on_message(
|
||||||
~filters.scheduled & filters.private & filters.command(["remove_commands"], prefixes=["/"]) # type: ignore
|
~filters.scheduled & filters.private & filters.command(["remove_commands"], prefixes=["/"]) # type: ignore
|
||||||
)
|
)
|
||||||
async def command_remove_commands(app: PyroClient, message: Message):
|
async def command_remove_commands(app: PyroClient, msg: Message):
|
||||||
await message.reply_text("Okay.")
|
await msg.reply_text("Okay.")
|
||||||
await app.remove_commands(command_sets=await app.collect_commands())
|
await app.remove_commands(command_sets=await app.collect_commands())
|
||||||
|
@@ -1,11 +1,15 @@
|
|||||||
aiohttp~=3.10.2
|
aiohttp~=3.8.4
|
||||||
async_pymongo==0.1.6
|
black~=23.3.0
|
||||||
convopyro==0.5
|
convopyro==0.5
|
||||||
pillow~=10.4.0
|
pillow~=10.0.0
|
||||||
pykeyboard==0.1.7
|
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
|
pytimeparse~=1.1.8
|
||||||
tgcrypto==1.2.5
|
tgcrypto==1.2.5
|
||||||
#uvloop==0.19.0
|
uvloop==0.17.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
|
libbot[speed,pyrogram]==1.8
|
||||||
photosapi_client==0.6.0
|
photosapi_client==0.5.0
|
Reference in New Issue
Block a user