diff --git a/examples/asynchronous_telebot/detect_changes.py b/examples/asynchronous_telebot/detect_changes.py new file mode 100644 index 0000000..0a0e142 --- /dev/null +++ b/examples/asynchronous_telebot/detect_changes.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +# This is a simple echo bot using the decorator mechanism. +# It echoes any incoming text messages. + +from telebot.async_telebot import AsyncTeleBot +bot = AsyncTeleBot('TOKEN') + + + +# Handle '/start' and '/help' +@bot.message_handler(commands=['help', 'start']) +async def send_welcome(message): + await bot.reply_to(message, """\ +Hi there, I am EchoBot. +I am here to echo your kind words back to you. Just say anything nice and I'll say the exact same thing to you!\ +""") + + +# Handle all other messages with content_type 'text' (content_types defaults to ['text']) +@bot.message_handler(func=lambda message: True) +async def echo_message(message): + await bot.reply_to(message, message.text) + + +import asyncio +# only new versions(4.7.0+) +asyncio.run(bot.polling(restart_on_change=True)) diff --git a/examples/detect_changes.py b/examples/detect_changes.py new file mode 100644 index 0000000..da2a2c8 --- /dev/null +++ b/examples/detect_changes.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +# This is a simple echo bot using the decorator mechanism. +# It echoes any incoming text messages. + +import telebot + +API_TOKEN = '' + +bot = telebot.TeleBot(API_TOKEN) + + +# Handle '/start' and '/help' +@bot.message_handler(commands=['help', 'start']) +def send_welcome(message): + bot.reply_to(message, """\ +Hi there, I am EchoBot. +I am here to echo your kind words back to you. Just say anything nice and I'll say the exact same thing to you!\ +""") + + +# Handle all other messages with content_type 'text' (content_types defaults to ['text']) +@bot.message_handler(func=lambda message: True) +def echo_message(message): + bot.reply_to(message, message.text) + +# only versions greater than 4.7.0 +bot.infinity_polling(restart_on_change=True) diff --git a/telebot/__init__.py b/telebot/__init__.py index 98f2aca..9d4c021 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -896,7 +896,9 @@ class TeleBot: self.event_handler = EventHandler() path = path_to_watch if path_to_watch else None if path is None: - path = sys.argv[1] if len(sys.argv) > 1 else '.' # current directory + # Make it possible to specify --path argument to the script + path = sys.argv[sys.argv.index('--path') + 1] if '--path' in sys.argv else '.' + self.observer = Observer() self.observer.schedule(self.event_handler, path, recursive=True) diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 4279fbd..148bb40 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -230,7 +230,8 @@ class AsyncTeleBot: self.event_handler = EventHandler() path = path_to_watch if path_to_watch else None if path is None: - path = sys.argv[1] if len(sys.argv) > 1 else '.' # current directory + # Make it possible to specify --path argument to the script + path = sys.argv[sys.argv.index('--path') + 1] if '--path' in sys.argv else '.' self.observer = Observer() self.observer.schedule(self.event_handler, path, recursive=True)