-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
52 lines (43 loc) · 1.36 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
import click
import logging
from configobj import ConfigObj
from app.database import first_db_init
from app.telebot import start_telebot
# Create and configure logger
logging.basicConfig(filename="tele.log",
format='%(asctime)s, %(levelname)s : %(message)s',
filemode='w')
logger = logging.getLogger()
logger.setLevel(logging.WARNING)
config = ConfigObj("setting.ini")
@click.group()
def cli():
first_db_init()
channel = config['main']['channel']
duration = config['main']['duration']
if len(channel) == 0:
print("Please specify channel username for bot to send message in setting.ini")
exit()
@cli.command()
@click.argument("token", required=True)
def polling(token):
'''bot mode polling'''
start_telebot(token)
@cli.command()
@click.argument("token", required=True)
def webhook(token):
'''bot mode webhook'''
domain = config['webhook']['domain']
port = config['webhook']['port']
cert = config['webhook']['cert']
if len(domain) == 0:
print("Please specify domain for receive webhook in setting.ini")
exit()
elif len(cert) == 0:
print("Please specify certificate location in setting.ini")
exit()
print(f"Webhook url : https://{domain}/{path}:{port}")
print(f"Cert location : {cert}")
start_telebot(token, mode="webhook")
if __name__ == '__main__':
cli()