当前位置: 首页>>代码示例>>Python>>正文


Python telebot.TeleBot方法代码示例

本文整理汇总了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 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:21,代码来源:test_telebot.py

示例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() 
开发者ID:ilteoood,项目名称:SiteAlert-Python,代码行数:27,代码来源:SiteAlert.py

示例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 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:21,代码来源:test_telebot.py

示例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) 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:10,代码来源:detailed_example.py

示例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) 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:12,代码来源:test_telebot.py

示例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' 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:13,代码来源:test_telebot.py

示例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' 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:13,代码来源:test_telebot.py

示例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' 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:13,代码来源:test_telebot.py

示例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' 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:13,代码来源:test_telebot.py

示例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 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:11,代码来源:test_telebot.py

示例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 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:11,代码来源:test_telebot.py

示例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 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:10,代码来源:test_telebot.py

示例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 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:10,代码来源:test_telebot.py

示例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 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:7,代码来源:test_telebot.py

示例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 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:7,代码来源:test_telebot.py


注:本文中的telebot.TeleBot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。