-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
55 lines (40 loc) · 1.33 KB
/
main.py
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
# -*- coding: utf-8 -*-
'''
Project: /root/projects/Pythons/telePicCutBot
File Name: main.py
Author: Chaos
Email: life0531@foxmail.com
Date: 2022/02/27
Software: Vscode
'''
'''Main Entrence of the whole Bot'''
import logging
import yaml
# Set parameters
from argparse import ArgumentParser
from telethon import events
from functions.glue import get_config, read_config, set_logger
from functions.login import get_bot, login
from handlers.new_messages import new_message_handler
parser = ArgumentParser()
parser.add_argument("--config", "-c", default="./config.yaml", help="Configeration file")
args = parser.parse_args()
if __name__ == '__main__':
# Read the configs
print("Reading Configurations...")
read_config(args.config)
config = get_config()
# Set logger
set_logger(config=config)
# login the bot account
login(config=config)
bot = get_bot()
logging.info("Logged in as a bot")
# add handler: listening all new messages from given chats by config file
logging.info("Adding New Message handler")
bot.add_event_handler(new_message_handler, event=events.NewMessage(chats=config["chats"]))
# start the bot
logging.info("Bot Started!")
bot.start(bot_token=config["bot"]["bot_token"])
# run forever
bot.run_until_disconnected()