This repository was archived by the owner on Aug 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.py
74 lines (60 loc) · 2.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright SquirrelNetwork
import sys
import pytz
import logging
from config import Config
from loguru import logger
from telegram.ext import Updater, Defaults
from telegram import ParseMode
from core.commands import index
from plugins import plugin_index
from core import handlers
from core.handlers import handlers_index
from tabulate import tabulate
# crea la tabella con i dati desiderati
table_data = [
["Type", "Description", "Extra"],
["Version", Config.VERSION, Config.VERSION_NAME],
["Author", "SquirrelNetwork", Config.REPO],
["Debug", Config.DEBUG],
["Plugins", "Enable"]
]
# stampa la tabella formattata
# if version < 3.7, stop bot.
LOGGING = logging.getLogger(__name__)
if sys.version_info[0] < 3 or sys.version_info[1] < 7:
LOGGING.error("You MUST have a python version of at least 3.7! Multiple features depend on this. Bot quitting.")
quit(1)
# Enable logging (In config.py DEBUG = True enable Debug Logging)
logging.basicConfig(level=(logging.INFO, logging.DEBUG)[Config.DEBUG], format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
@logger.catch
def main():
"""Instantiate a Defaults object"""
defaults = Defaults(parse_mode=ParseMode.HTML, tzinfo=pytz.timezone('Europe/Rome'))
updater = Updater(Config.BOT_TOKEN, defaults=defaults, workers=32)
dsp = updater.dispatcher
job_updater = updater.job_queue
# I load all admin, user and owner commands
index.user_command(dsp)
index.admin_command(dsp)
index.owner_command(dsp)
#Plugins Section (if in the config.py ENABLE_PLUGINS is True it loads the plugins if ENABLE_PLUGINS is False it does not load them)
if Config.ENABLE_PLUGINS == True :
plugin_index.function_plugins(dsp)
logger.info('Plugin Enabled')
else:
logger.info('Plugin Disabled')
# I load all handlers, commands without '/'
handlers_index.core_handlers(dsp)
handlers.logs.sys_loggers()
handlers.handlers_index.jobs_handlers(job_updater)
# I load the error handler, when the bot receives an error it sends a private message to the developer
dsp.add_error_handler(handlers.errors.error_handler)
dsp.add_error_handler(handlers.handler_errors.init)
# Start the Bot Polling
updater.start_polling(poll_interval=1.0, timeout=5.0)
updater.idle()
if __name__ == '__main__':
main()