mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Added examples and made it possible to specify --path path for path
This commit is contained in:
parent
ea69b8093d
commit
27e0197855
28
examples/asynchronous_telebot/detect_changes.py
Normal file
28
examples/asynchronous_telebot/detect_changes.py
Normal 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))
|
28
examples/detect_changes.py
Normal file
28
examples/detect_changes.py
Normal 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)
|
@ -896,7 +896,9 @@ class TeleBot:
|
|||||||
self.event_handler = EventHandler()
|
self.event_handler = EventHandler()
|
||||||
path = path_to_watch if path_to_watch else None
|
path = path_to_watch if path_to_watch else None
|
||||||
if path is 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 = Observer()
|
||||||
self.observer.schedule(self.event_handler, path, recursive=True)
|
self.observer.schedule(self.event_handler, path, recursive=True)
|
||||||
|
@ -230,7 +230,8 @@ class AsyncTeleBot:
|
|||||||
self.event_handler = EventHandler()
|
self.event_handler = EventHandler()
|
||||||
path = path_to_watch if path_to_watch else None
|
path = path_to_watch if path_to_watch else None
|
||||||
if path is 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 = Observer()
|
||||||
self.observer.schedule(self.event_handler, path, recursive=True)
|
self.observer.schedule(self.event_handler, path, recursive=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user