Added examples and made it possible to specify --path path for path

This commit is contained in:
coder2020official 2022-10-01 21:28:53 +04:00
parent ea69b8093d
commit 27e0197855
4 changed files with 61 additions and 2 deletions

View File

@ -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))

View File

@ -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 = '<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)

View File

@ -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)

View File

@ -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)