-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (43 loc) · 1.71 KB
/
main.py
File metadata and controls
56 lines (43 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from telegram.ext import Updater
from telegram.ext import MessageHandler, Filters
import logging
import os
from dotenv import load_dotenv
from downloader import Downloader
from processor import Processor
from s3_client import S3Client
from pg_client import PgClient
load_dotenv()
logging.basicConfig(level=os.environ.get('log_level'),
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def main():
s3_client = S3Client(os.environ.get('s3_url'),
os.environ.get('s3_access_key'),
os.environ.get('s3_secret_key'),
os.environ.get('s3_bucket'),
)
pg_client = PgClient(
host=os.environ.get('pg_host'),
port=os.environ.get('pg_port'),
user=os.environ.get('pg_user'),
passwd=os.environ.get('pg_pass'),
db=os.environ.get('pg_db')
)
admin_users = os.environ.get('admin_users').split(',')
processor = Processor(s3_client, pg_client, admin_users)
"""Start the bot."""
# Create the Updater and pass it your bot's token.
updater = Updater(os.environ.get('bot_key'), use_context=True, )
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on noncommand i.e message - echo the message on Telegram
dp.add_handler(MessageHandler(Filters.sticker, processor.filter))
# Start the Bot
updater.start_polling()
# Run the bot until you press Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
if __name__ == '__main__':
main()