mirror of
https://github.com/cdryzun/tg_bot_collections.git
synced 2025-08-05 13:16:42 +08:00
feat: add summary and search commands (#54)
* feat: add summary and search commands Signed-off-by: Frost Ming <me@frostming.com> * fix formats Signed-off-by: Frost Ming <me@frostming.com> * fix: clean up Signed-off-by: Frost Ming <me@frostming.com>
This commit is contained in:
29
tg.py
29
tg.py
@ -1,13 +1,34 @@
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
from telebot import TeleBot
|
||||
|
||||
from config import settings
|
||||
from handlers import list_available_commands, load_handlers
|
||||
|
||||
logger = logging.getLogger("bot")
|
||||
|
||||
|
||||
def setup_logging(debug: bool):
|
||||
logger.setLevel(logging.DEBUG if debug else logging.INFO)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setFormatter(
|
||||
logging.Formatter(
|
||||
"%(asctime)s - [%(levelname)s] - %(filename)s:%(lineno)d - %(message)s"
|
||||
)
|
||||
)
|
||||
logger.addHandler(handler)
|
||||
|
||||
|
||||
def main():
|
||||
# Init args
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("tg_token", help="tg token")
|
||||
parser.add_argument(
|
||||
"tg_token", help="tg token", default=settings.telegram_bot_token, nargs="?"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--debug", "--verbose", "-v", action="store_true", help="Enable debug mode"
|
||||
)
|
||||
|
||||
# 'disable-command' option
|
||||
# The action 'append' will allow multiple entries to be saved into a list
|
||||
@ -22,15 +43,15 @@ def main():
|
||||
)
|
||||
|
||||
options = parser.parse_args()
|
||||
print("Arg parse done.")
|
||||
setup_logging(options.debug)
|
||||
|
||||
# Init bot
|
||||
bot = TeleBot(options.tg_token)
|
||||
load_handlers(bot, options.disable_commands)
|
||||
print("Bot init done.")
|
||||
logger.info("Bot init done.")
|
||||
|
||||
# Start bot
|
||||
print("Starting tg collections bot.")
|
||||
logger.info("Starting tg collections bot.")
|
||||
bot.infinity_polling(timeout=10, long_polling_timeout=5)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user