dev #19

Merged
profitroll merged 98 commits from dev into master 2023-04-24 13:48:22 +03:00
5 changed files with 142 additions and 7 deletions
Showing only changes of commit b5e3abd4ad - Show all commits

1
.gitignore vendored
View File

@ -169,3 +169,4 @@ cython_debug/
cache cache
data data
logs logs
config.json

View File

@ -57,8 +57,10 @@ To make this bot run at first you need to have a Python interpreter, Photos API,
6. Configure "bot" and "owner" with your favorite text editor: 6. Configure "bot" and "owner" with your favorite text editor:
`nano config.json` 1. Copy file `config_example.json` to `config.json`
You can edit with vim, nano, on Windows it's Notepad or Notepad++. Whatever. 2. Open `config.json` using your favorite text editor. For example `nano config.json`, but you can edit with vim, nano, on Windows it's Notepad or Notepad++. Whatever
3. Change `"owner"`, `"bot.api_id"`, `"bot.api_hash"` and `"bot.bot_token"` keys' values.
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).
7. Configure database and API: 7. Configure database and API:

121
modules/default_config.json Normal file
View File

@ -0,0 +1,121 @@
{
"locale": "en",
"locale_log": "en",
"locale_fallback": "en",
"owner": 0,
"admins": [],
"bot": {
"api_id": 0,
"api_hash": "",
"bot_token": ""
},
"database": {
"user": null,
"password": null,
"host": "127.0.0.1",
"port": 27017,
"name": "tgposter"
},
"mode": {
"post": true,
"submit": true
},
"reports": {
"sent": false,
"error": true,
"startup": true,
"shutdown": true
},
"logging": {
"size": 512,
"location": "logs"
},
"locations": {
"tmp": "tmp",
"data": "data",
"cache": "cache",
"sent": "data/sent",
"queue": "data/queue",
"index": "data/index.json",
"locale": "locale"
},
"posting": {
"channel": 0,
"silent": false,
"move_sent": false,
"use_interval": false,
"interval": "1h30m",
"page_size": 300,
"submitted_caption": {
"enabled": true,
"ignore_admins": true,
"text": "#submitted"
},
"extensions": {
"photo": [
"jpg",
"png",
"gif",
"jpeg"
],
"video": [
"mp4",
"avi",
"mkv",
"webm",
"mov"
]
},
"time": [
"08:00",
"10:00",
"12:00",
"14:00",
"16:00",
"18:00",
"20:00",
"22:00"
],
"api": {
"address": "http://localhost:8054",
"address_external": "https://photos.domain.com",
"username": "",
"password": "",
"album": ""
}
},
"caption": {
"enabled": false,
"link": null,
"text": [
"sample text"
]
},
"submission": {
"timeout": 30,
"file_size": 15728640,
"tmp_size": 15728640,
"allow_duplicates": false,
"send_uploaded_id": false,
"require_confirmation": {
"users": true,
"admins": true
},
"mime_types": [
"image/png",
"image/gif",
"image/jpeg",
"video/mp4",
"video/quicktime"
]
},
"commands": [
"start",
"rules"
],
"commands_admin": [
"import",
"export",
"reboot"
]
}

View File

@ -1,4 +1,4 @@
from os import kill from os import kill, path
from os import name as osname from os import name as osname
from os import sep from os import sep
from sys import exit from sys import exit
@ -73,9 +73,20 @@ def configGet(key: str, *args: str):
* any: Value of provided key * any: Value of provided key
""" """
this_dict = jsonLoad("config.json") this_dict = jsonLoad("config.json")
this_key = this_dict try:
for dict_key in args: this_key = this_dict
this_key = this_key[dict_key] for dict_key in args:
this_key = this_key[dict_key]
except KeyError:
print(
f"Could not find config key '{key}' under path {args}: falling back to default config",
flush=True,
)
fallback_dict = jsonLoad(path.join("modules", "default_config.json"))
this_key = fallback_dict
for dict_key in args:
this_key = this_key[dict_key]
configSet(key, this_key[key], args)
return this_key[key] return this_key[key]