本文整理匯總了Python中telebot.TeleBot方法的典型用法代碼示例。如果您正苦於以下問題:Python telebot.TeleBot方法的具體用法?Python telebot.TeleBot怎麽用?Python telebot.TeleBot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類telebot
的用法示例。
在下文中一共展示了telebot.TeleBot方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_default_middleware_handler
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_default_middleware_handler(self):
from telebot import apihelper
apihelper.ENABLE_MIDDLEWARE = True
tb = telebot.TeleBot('')
update = self.create_message_update('/help')
@tb.middleware_handler()
def middleware(tb_instance, update):
update.message.text = 'got'
@tb.message_handler(func=lambda m: m.text == 'got')
def command_handler(message):
message.text = message.text + message.text
tb.process_new_updates([update])
time.sleep(1)
assert update.message.text == 'got' * 2
示例2: __init__
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def __init__(self):
self.__db = expanduser("~") + os.sep + "SiteAlert.db"
if not os.path.isfile(self.__db):
print("[WARNING]: No db found, creating a new one.")
connection = sqlite3.connect(self.__db)
connection.execute(
"CREATE TABLE `SiteAlert` (`name` TEXT NOT NULL UNIQUE,`link` TEXT NOT NULL,`hash` TEXT NOT NULL,PRIMARY KEY(link));")
connection.execute(
"CREATE TABLE 'Registered'('name' TEXT NOT NULL,'mail' TEXT NOT NULL, PRIMARY KEY(name, mail));")
connection.execute(
"CREATE TABLE Users ('mail' TEXT NOT NULL, 'telegram' TEXT NOT NULL UNIQUE, 'mailnotification' BOOLEAN NOT NULL DEFAULT TRUE, 'telegramnotification' BOOLEAN NOT NULL DEFAULT TRUE, PRIMARY KEY (mail));")
connection.close()
self.__connection = sqlite3.connect(self.__db, check_same_thread=False)
self.__header = [('User-Agent',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'),
('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'),
('Accept-Encoding', 'none'),
('Accept-Language', 'en-US,en;q=0.8'),
('Connection', 'keep-alive')]
self.__TOKEN = os.environ['SITE_ALERT_TOKEN']
self.__MAIL = os.environ['SITE_ALERT_MAIL']
self.__PSW = os.environ['SITE_ALERT_PASSWORD']
self.__tb = telebot.TeleBot(self.__TOKEN)
self.saved_on_db()
示例3: test_typed_middleware_handler
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_typed_middleware_handler(self):
from telebot import apihelper
apihelper.ENABLE_MIDDLEWARE = True
tb = telebot.TeleBot('')
update = self.create_message_update('/help')
@tb.middleware_handler(update_types=['message'])
def middleware(tb_instance, message):
message.text = 'got'
@tb.message_handler(func=lambda m: m.text == 'got')
def command_handler(message):
message.text = message.text + message.text
tb.process_new_updates([update])
time.sleep(1)
assert update.message.text == 'got' * 2
示例4: listener
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def listener(messages):
"""
When new messages arrive TeleBot will call this function.
"""
for m in messages:
if m.content_type == 'text':
# print the sent message to the console
print(str(m.chat.first_name) + " [" + str(m.chat.id) + "]: " + m.text)
示例5: test_message_listener
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_message_listener(self):
msg_list = []
for x in range(100):
msg_list.append(self.create_text_message('Message ' + str(x)))
def listener(messages):
assert len(messages) == 100
tb = telebot.TeleBot('')
tb.set_update_listener(listener)
示例6: test_message_handler
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_message_handler(self):
tb = telebot.TeleBot('')
msg = self.create_text_message('/help')
@tb.message_handler(commands=['help', 'start'])
def command_handler(message):
message.text = 'got'
tb.process_new_messages([msg])
time.sleep(1)
assert msg.text == 'got'
示例7: test_message_handler_reg
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_message_handler_reg(self):
bot = telebot.TeleBot('')
msg = self.create_text_message(r'https://web.telegram.org/')
@bot.message_handler(regexp=r'((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
def command_url(message):
msg.text = 'got'
bot.process_new_messages([msg])
time.sleep(1)
assert msg.text == 'got'
示例8: test_message_handler_lambda
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_message_handler_lambda(self):
bot = telebot.TeleBot('')
msg = self.create_text_message(r'lambda_text')
@bot.message_handler(func=lambda message: r'lambda' in message.text)
def command_url(message):
msg.text = 'got'
bot.process_new_messages([msg])
time.sleep(1)
assert msg.text == 'got'
示例9: test_message_handler_reg_fail
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_message_handler_reg_fail(self):
bot = telebot.TeleBot('')
msg = self.create_text_message(r'web.telegram.org/')
@bot.message_handler(regexp=r'((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
def command_url(message):
msg.text = 'got'
bot.process_new_messages([msg])
time.sleep(1)
assert not msg.text == 'got'
示例10: test_send_message_with_markdown
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_send_message_with_markdown(self):
tb = telebot.TeleBot(TOKEN)
markdown = """
*bold text*
_italic text_
[text](URL)
"""
ret_msg = tb.send_message(CHAT_ID, markdown, parse_mode="Markdown")
assert ret_msg.message_id
示例11: test_send_message_with_disable_notification
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_send_message_with_disable_notification(self):
tb = telebot.TeleBot(TOKEN)
markdown = """
*bold text*
_italic text_
[text](URL)
"""
ret_msg = tb.send_message(CHAT_ID, markdown, parse_mode="Markdown", disable_notification=True)
assert ret_msg.message_id
示例12: test_send_file
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_send_file(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_document(CHAT_ID, file_data)
assert ret_msg.message_id
ret_msg = tb.send_document(CHAT_ID, ret_msg.document.file_id)
assert ret_msg.message_id
示例13: test_send_file_dis_noti
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_send_file_dis_noti(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_document(CHAT_ID, file_data, disable_notification=True)
assert ret_msg.message_id
ret_msg = tb.send_document(CHAT_ID, ret_msg.document.file_id)
assert ret_msg.message_id
示例14: test_send_video
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_send_video(self):
file_data = open('./test_data/test_video.mp4', 'rb')
tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_video(CHAT_ID, file_data)
assert ret_msg.message_id
示例15: test_send_video_dis_noti
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import TeleBot [as 別名]
def test_send_video_dis_noti(self):
file_data = open('./test_data/test_video.mp4', 'rb')
tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_video(CHAT_ID, file_data, disable_notification=True)
assert ret_msg.message_id