Changed bot "mode" behavior

This commit is contained in:
Profitroll 2022-08-30 14:10:05 +02:00
parent 5848bca40a
commit 6e1de38da0
4 changed files with 16 additions and 11 deletions

View File

@ -27,7 +27,8 @@ To make this bot run at first you need to have a Python interpreter and git. Goo
4. Configure your bot with a favorite text editor:
`nano config.json`
You can edit with vim, nano, on Windows it's Notepad or Notepad++. Whatever.
If you don't know where to find bot_token and your id - here you can find some hints: [get bot token](https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token), [get your id](https://www.alphr.com/telegram-find-user-id/), [get api_hash and api_id](https://core.telegram.org/api/obtaining_api_id).
If you don't know where to find bot_token and your id - here you can find some hints: [get bot token](https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token), [get your id](https://www.alphr.com/telegram-find-user-id/), [get api_hash and api_id](https://core.telegram.org/api/obtaining_api_id).
Also don't forget to change bot's working mode. Dict key `"mode"` contains keys `"post"` and `"submit"`, each of those can be either `true` or `false`.
5. Add bot to the channel:
To use your bot of course you need to have a channel or group otherwise makes no sense to have such a bot. [Here](https://stackoverflow.com/a/33497769) you can find a quick guide how to add your bot to a channel.

View File

@ -25,7 +25,8 @@
4. Налаштуйте свого бота за допомогою текстового редактора:
`nano config.json`
Ви можете редагувати за допомогою vim, nano, у Windows це Notepad або Notepad++. На Ваш смак.
Якщо Ви не знаєте, де знайти bot_token і свій ідентифікатор, тут Ви можете знайти кілька підказок: [отримати токен бота](https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token), [отримати свій ідентифікатор](https://www.alphr.com/telegram-find-user-id/), [отримати api_hash і api_id](https://core.telegram.org/api/obtaining_api_id ).
Якщо Ви не знаєте, де знайти bot_token і свій ідентифікатор, тут Ви можете знайти кілька підказок: [отримати токен бота](https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token), [отримати свій ідентифікатор](https://www.alphr.com/telegram-find-user-id/), [отримати api_hash і api_id](https://core.telegram.org/api/obtaining_api_id).
Також не забудьте змінити режим роботи бота. Ключ `"mode"` має в собі ключі `"post"` та `"submit"`, кожен з який може бути `true` або `false`.
5. Додайте бота на канал:
Звичайно, щоб використовувати свого бота, Вам потрібно мати канал або групу, інакше немає сенсу мати такого бота. [Тут](https://stackoverflow.com/a/33497769) Ви можете знайти короткий гайд, як додати свого бота до каналу.

View File

@ -1,6 +1,5 @@
{
"module": null,
"mode": "both",
"locale": "en",
"locale_fallback": "en",
"admin": 0,
@ -9,6 +8,10 @@
"api_hash": "",
"bot_token": ""
},
"mode": {
"post": true,
"submit": true
},
"reports": {
"sent": false,
"error": true,

View File

@ -206,13 +206,13 @@ def send_content():
# Check last posts forwards
# check_forwards(app)
if configGet("mode") in ["both", "submit"]:
if configGet("submit", "mode"):
@app.on_message(~ filters.scheduled & filters.command(["start"], prefixes="/"))
def cmd_start(app, msg):
if msg.from_user.id not in jsonLoad(configGet("blocked", "locations")):
msg.reply_text(locale("start", "message", locale=msg.from_user.language_code))
if configGet("mode") in ["both", "submit"]:
if configGet("submit", "mode"):
@app.on_message(~ filters.scheduled & filters.command(["rules", "help"], prefixes="/"))
def cmd_rules(app, msg):
if msg.from_user.id not in jsonLoad(configGet("blocked", "locations")):
@ -263,7 +263,7 @@ def subUnblock(user):
blocked.remove(user)
jsonSave(blocked, configGet("blocked", "locations"))
if configGet("mode") in ["both", "submit"]:
if configGet("submit", "mode"):
@app.on_message(~ filters.scheduled & filters.photo | filters.video | filters.animation | filters.document)
def get_submission(_, msg):
try:
@ -396,8 +396,8 @@ def callback_query_unblock(app, clb): # type: ignore
# # else:
# # logWrite(f"Got raw update of type {type(update)} with contents {update}", debug=True)
if configGet("mode") in ["both", "post"]:
if configGet("post", "mode"):
for entry in configGet("time", "posting"):
schedule.every().day.at(entry).do(send_content)
@ -425,11 +425,11 @@ if __name__ == "__main__":
if configGet("startup", "reports"):
app.send_message(configGet("admin"), locale("startup", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
if configGet("mode") in ["both", "post"]:
if configGet("post", "mode"):
t = Thread(target=background_task)
t.start()
if configGet("mode") in ["both", "submit"]:
if configGet("submit", "mode"):
# Registering user commands
for entry in os.listdir(configGet("locale", "locations")):
if entry.endswith(".json"):
@ -446,7 +446,7 @@ if __name__ == "__main__":
# Registering admin commands
commands_admin_list = []
if configGet("mode") in ["both", "submit"]:
if configGet("submit", "mode"):
for command in configGet("commands"):
commands_admin_list.append(BotCommand(command, locale(command, "commands", locale=configGet("locale"))))
for command in configGet("commands_admin"):