-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
34 lines (27 loc) · 1.08 KB
/
main.py
File metadata and controls
34 lines (27 loc) · 1.08 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
import argparse
from init import create_bot
from common.texts import bot_name
from common.utils.logging_tools import get_logger
from common.utils.socket_app_lock import SocketAppLock
def main():
logger = get_logger()
logger.info("Booting...")
if not __debug__:
lock_name = "python-telegram-bot.main.lock"
app_lock = SocketAppLock(lock_name, logger)
if not app_lock.lock():
print(f"The bot already has been started or did not shutdown correctly. "
f"Please stop the running bot / remove the {lock_name} file.")
return
args = get_args()
bot = create_bot(args.admin_id)
bot.run(args.token)
if not __debug__:
app_lock.unlock()
def get_args():
parser = argparse.ArgumentParser(description=f"Run the {bot_name} for Telegram.")
parser.add_argument('-t', dest="token", required=True, help='Your Telegram API token')
parser.add_argument('-a', dest="admin_id", type=int, required=False, help='The admin user\'s Telegram ID')
return parser.parse_args()
if __name__ == '__main__':
main()