Compare commits
3 Commits
03b6bbe039
...
1684c5177c
Author | SHA1 | Date | |
---|---|---|---|
1684c5177c | |||
fba52bcfc4 | |||
20666fc0f8 |
@@ -86,7 +86,7 @@ To make this bot run at first you need to have a Python interpreter, Photos API,
|
||||
|
||||
Make sure MongoDB and Photos API are running and use `python poster.py` to start it.
|
||||
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 `/reboot` command.
|
||||
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.
|
||||
|
||||
|
@@ -116,6 +116,6 @@
|
||||
"commands_admin": [
|
||||
"import",
|
||||
"export",
|
||||
"reboot"
|
||||
"shutdown"
|
||||
]
|
||||
}
|
@@ -9,13 +9,16 @@
|
||||
"export": "Get .zip archive with all photos",
|
||||
"remove": "Delete photo by its ID",
|
||||
"purge": "Completely purge bot's queue",
|
||||
"reboot": "Restart the bot"
|
||||
"shutdown": "Restart 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",
|
||||
|
@@ -9,13 +9,16 @@
|
||||
"export": "Отримати .zip архів з усіма фотографіями",
|
||||
"remove": "Видалити фото за його ID",
|
||||
"purge": "Повністю видалити всю чергу бота",
|
||||
"reboot": "Перезапустити бота"
|
||||
"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": "❌ Подання розглянуто та відхилено",
|
||||
|
@@ -88,7 +88,7 @@ default_config = {
|
||||
],
|
||||
},
|
||||
"commands": ["start", "rules"],
|
||||
"commands_admin": ["import", "export", "reboot"],
|
||||
"commands_admin": ["import", "export", "shutdown"],
|
||||
}
|
||||
|
||||
|
||||
|
29
plugins/callbacks/shutdown.py
Normal file
29
plugins/callbacks/shutdown.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from os import getpid, makedirs, path
|
||||
from time import time
|
||||
from modules.app import app
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import CallbackQuery
|
||||
from classes.poster_client import PosterClient
|
||||
from modules.scheduler import scheduler
|
||||
from modules.logger import logWrite
|
||||
from modules.utils import configGet, jsonSave, locale
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("shutdown"))
|
||||
async def callback_query_nothing(app: PosterClient, clb: CallbackQuery):
|
||||
if clb.from_user.id in app.admins:
|
||||
pid = getpid()
|
||||
logWrite(f"Shutting down bot with pid {pid}")
|
||||
await clb.answer()
|
||||
await clb.message.reply_text(
|
||||
locale("shutdown", "message", locale=clb.from_user.language_code).format(
|
||||
pid
|
||||
),
|
||||
)
|
||||
scheduler.shutdown()
|
||||
makedirs(configGet("cache", "locations"), exist_ok=True)
|
||||
jsonSave(
|
||||
{"timestamp": time()},
|
||||
path.join(configGet("cache", "locations"), "shutdown_time"),
|
||||
)
|
||||
exit()
|
@@ -1,24 +1,45 @@
|
||||
from os import getpid
|
||||
from os import getpid, makedirs, path
|
||||
from time import time
|
||||
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
|
||||
from classes.poster_client import PosterClient
|
||||
from pyrogram.types import Message
|
||||
|
||||
from modules.app import app
|
||||
from modules.app import app, users_with_context
|
||||
from modules.logger import logWrite
|
||||
from modules.utils import configGet, killProc, locale
|
||||
from modules.scheduler import scheduler
|
||||
from modules.utils import configGet, jsonSave, locale
|
||||
|
||||
|
||||
@app.on_message(
|
||||
~filters.scheduled & filters.command(["kill", "die", "reboot"], prefixes=["", "/"])
|
||||
)
|
||||
@app.on_message(~filters.scheduled & filters.command(["shutdown"], prefixes=["", "/"]))
|
||||
async def cmd_kill(app: PosterClient, msg: Message):
|
||||
if msg.from_user.id in app.admins:
|
||||
global users_with_context
|
||||
if len(users_with_context) > 0:
|
||||
await msg.reply_text(
|
||||
f"There're {len(users_with_context)} unfinished users' contexts. If you turn off the bot, those will be lost. Please confirm shutdown using a button below.",
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
"Confirm shutdown", callback_data="shutdown"
|
||||
)
|
||||
]
|
||||
]
|
||||
),
|
||||
)
|
||||
return
|
||||
pid = getpid()
|
||||
logWrite(
|
||||
locale("shutdown", "console", locale=configGet("locale")).format(str(pid))
|
||||
)
|
||||
logWrite(f"Shutting down bot with pid {pid}")
|
||||
await msg.reply_text(
|
||||
locale("shutdown", "message", locale=configGet("locale")).format(str(pid))
|
||||
locale("shutdown", "message", locale=msg.from_user.language_code).format(
|
||||
pid
|
||||
),
|
||||
)
|
||||
killProc(pid)
|
||||
scheduler.shutdown()
|
||||
makedirs(configGet("cache", "locations"), exist_ok=True)
|
||||
jsonSave(
|
||||
{"timestamp": time()},
|
||||
path.join(configGet("cache", "locations"), "shutdown_time"),
|
||||
)
|
||||
exit()
|
||||
|
81
poster.py
81
poster.py
@@ -1,14 +1,18 @@
|
||||
from os import getpid
|
||||
from os import getpid, path
|
||||
from datetime import datetime
|
||||
from sys import exit
|
||||
from time import time
|
||||
|
||||
from modules.cli import *
|
||||
from modules.logger import logWrite
|
||||
from modules.scheduler import scheduler
|
||||
from modules.utils import configGet, killProc, locale
|
||||
from modules.utils import configGet, jsonLoad, jsonSave, killProc, locale
|
||||
|
||||
# Import ===================================================================================================================================
|
||||
try:
|
||||
from pyrogram.sync import idle
|
||||
from pyrogram.errors import bad_request_400
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from modules.app import app
|
||||
except ModuleNotFoundError:
|
||||
@@ -57,6 +61,7 @@ pid = getpid()
|
||||
|
||||
# Imports ==================================================================================================================================
|
||||
from plugins.commands.general import *
|
||||
from plugins.callbacks.shutdown import *
|
||||
|
||||
if configGet("submit", "mode"):
|
||||
from plugins.callbacks.nothing import *
|
||||
@@ -112,15 +117,55 @@ if configGet("post", "mode"):
|
||||
# asyncio.run(main())
|
||||
|
||||
if __name__ == "__main__":
|
||||
logWrite(locale("startup", "console", locale=configGet("locale")).format(str(pid)))
|
||||
logWrite(locale("startup", "console").format(str(pid)))
|
||||
|
||||
app.start()
|
||||
|
||||
if configGet("startup", "reports"):
|
||||
app.send_message(
|
||||
app.owner,
|
||||
locale("startup", "message", locale=configGet("locale")).format(str(pid)),
|
||||
)
|
||||
try:
|
||||
if path.exists(path.join(configGet("cache", "locations"), "shutdown_time")):
|
||||
downtime = relativedelta(
|
||||
datetime.now(),
|
||||
datetime.fromtimestamp(
|
||||
jsonLoad(
|
||||
path.join(configGet("cache", "locations"), "shutdown_time")
|
||||
)["timestamp"]
|
||||
),
|
||||
)
|
||||
if downtime.days >= 1:
|
||||
app.send_message(
|
||||
configGet("owner"),
|
||||
locale(
|
||||
"startup_downtime_days",
|
||||
"message",
|
||||
).format(pid, downtime.days),
|
||||
)
|
||||
elif downtime.hours >= 1:
|
||||
app.send_message(
|
||||
configGet("owner"),
|
||||
locale(
|
||||
"startup_downtime_hours",
|
||||
"message",
|
||||
).format(pid, downtime.hours),
|
||||
)
|
||||
else:
|
||||
app.send_message(
|
||||
configGet("owner"),
|
||||
locale(
|
||||
"startup_downtime_minutes",
|
||||
"message",
|
||||
locale=configGet("locale"),
|
||||
).format(pid, downtime.minutes),
|
||||
)
|
||||
else:
|
||||
app.send_message(
|
||||
configGet("owner"),
|
||||
locale("startup", "message").format(pid),
|
||||
)
|
||||
except bad_request_400.PeerIdInvalid:
|
||||
logWrite(
|
||||
f"Could not send startup message to bot owner. Perhaps user has not started the bot yet."
|
||||
)
|
||||
|
||||
if configGet("post", "mode"):
|
||||
scheduler.start()
|
||||
@@ -132,10 +177,24 @@ if __name__ == "__main__":
|
||||
|
||||
idle()
|
||||
|
||||
app.send_message(
|
||||
app.owner,
|
||||
locale("shutdown", "message", locale=configGet("locale")).format(str(pid)),
|
||||
try:
|
||||
app.send_message(
|
||||
configGet("owner"),
|
||||
locale("shutdown", "message").format(pid),
|
||||
)
|
||||
except bad_request_400.PeerIdInvalid:
|
||||
logWrite(
|
||||
f"Could not send shutdown message to bot owner. Perhaps user has not started the bot yet."
|
||||
)
|
||||
|
||||
makedirs(configGet("cache", "locations"), exist_ok=True)
|
||||
jsonSave(
|
||||
{"timestamp": time()},
|
||||
path.join(configGet("cache", "locations"), "shutdown_time"),
|
||||
)
|
||||
logWrite(locale("shutdown", "console", locale=configGet("locale")).format(str(pid)))
|
||||
|
||||
logWrite(locale("shutdown", "console").format(str(pid)))
|
||||
|
||||
scheduler.shutdown()
|
||||
|
||||
killProc(pid)
|
||||
|
@@ -1,3 +1,4 @@
|
||||
python_dateutil==2.8.2
|
||||
apscheduler~=3.10.1
|
||||
pytimeparse~=1.1.8
|
||||
convopyro==0.5
|
||||
|
Reference in New Issue
Block a user