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


Python TelegramBot.send_photo方法代码示例

本文整理汇总了Python中twx.botapi.TelegramBot.send_photo方法的典型用法代码示例。如果您正苦于以下问题:Python TelegramBot.send_photo方法的具体用法?Python TelegramBot.send_photo怎么用?Python TelegramBot.send_photo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twx.botapi.TelegramBot的用法示例。


在下文中一共展示了TelegramBot.send_photo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update

# 需要导入模块: from twx.botapi import TelegramBot [as 别名]
# 或者: from twx.botapi.TelegramBot import send_photo [as 别名]
def update():
 bot = TelegramBot(token)
 bot.update_bot_info().wait()

 if 'chat' in request.json['message']:
  chat = request.json['message']['chat']['id']
  if 'text' in request.json['message']:
   text = request.json['message']['text']
   if text.find('vice') != -1:
    bot.send_message(chat, vice()).wait()
   if text.find('drink') != -1:
    bot.send_photo(chat,bill()).wait()

 #Print in console for fast Debugging
 print(json.dumps(request.json))
 return "ok"
开发者ID:kmos,项目名称:cosbytbot,代码行数:18,代码来源:flaskapp.py

示例2: main

# 需要导入模块: from twx.botapi import TelegramBot [as 别名]
# 或者: from twx.botapi.TelegramBot import send_photo [as 别名]

#.........这里部分代码省略.........
        try:
            updates = bot.get_updates(offset=last_id).wait()
            #print updates[0].message.sender
            #print updates[0].message.message_id
            #print "-------------------------------"

            itera = 0
            for update in updates:

                #print len(update.message)
                if update.message is not None:

                    #print update.message.text
                    #print "*************************** iteration: "

                    id = update.message.message_id
                    update_id = update.update_id
                    user = update.message.sender

                    chat_id = update.message.chat.id
                    text = update.message.text

                    if int(update_id) > last_id:
                        last_id = update_id
                        save_last_id(last_id)
                        save_log(id, update_id, chat_id, text)

                        #text = regex.sub('', text)
                        if text:
                            words = text.split()

                            for i, word in enumerate(words):

                                print word

                                # Process commands:
                                if word == '/start':
                                    print "New user started the app: " + str(user)
                                    send_keyboard(bot, chat_id)
                                elif word == '/flag':
                                    if update.message.sender.username  == 'paclema' : interface.sendFlagWave(1)
                                    bot.send_message(chat_id, "Moviendo la bandera " + get_user_name(update.message.sender) + "!")
                                elif word == '/rainbow':
                                    interface.sendRainbow()
                                    break
                                elif word == '/foto':
                                    #interface.sendFlagWave(1)
                                    interface.sendStripColor(0,0,0)
                                    for a in range(30):
                                        interface.sendStripBarColor(0, 2*a, 8.5*a, 0, 0)
                                        t.sleep(0.03)

                                    interface.sendStripColor(0,0,0)
                                    t.sleep(0.2)
                                    interface.sendStripColor(0,0,0)
                                    cam.start()
                                    bot.send_message(chat_id, get_user_name(update.message.sender) + " quiere una foto!")

                                    if platform.system() == 'Windows' :
                                        img = pygame.Surface((640,480))
                                        cam.get_image(img)
                                    else:
                                        img = cam.get_image()

                                    pygame.image.save(img,"./snap_photo.jpg")
                                    pygame.mixer.music.load("./camera_shutter.mp3")
                                    interface.sendStripColor(255,255,255)
                                    pygame.mixer.music.play()

                                    fp = open('snap_photo.jpg', 'rb')
                                    file_info = InputFileInfo('snap_photo.jpg', fp, 'image/jpg')

                                    f = InputFile('photo', file_info)

                                    bot.send_photo(chat_id, photo=f)

                                    cam.stop()
                                    print "[" + t.strftime("%c") + "]" + " Foto enviada de " + get_user_name(update.message.sender, True, True) + "!"
                                    t.sleep(0.3)
                                    interface.sendStripColor(0,0,0)

                                    break
                                else:
                                    bot.send_message(chat_id, "Bad syntax!")
                                    break

                                # Restricted API
                                if int(user_id) == user.id:
                                    if word == '/move':
                                        try:
                                            interface.sendMove(int(words[i+1]))
                                            break
                                        except Exception, e:
                                            print e


        except (KeyboardInterrupt, SystemExit):
            print '\nkeyboardinterrupt caught (again)'
            print '\n...Program Stopped Manually!'
            raise
开发者ID:Wychy7,项目名称:pcmods,代码行数:104,代码来源:FlagBot.py

示例3: DigestBot

# 需要导入模块: from twx.botapi import TelegramBot [as 别名]
# 或者: from twx.botapi.TelegramBot import send_photo [as 别名]

#.........这里部分代码省略.........
                except Exception:
                    self.bot.send_message(chat.id, 'Unknow error. Sorry.')
            #Parse strory from bach.org rss and print in chat
            if Bash in text:
                d = feedparser.parse('http://bash.im/rss/')
                bot_answer =d['entries'][0]['title']+" "+d.entries[0]['link']
                try:
                    self.bot.send_message(chat.id, bot_answer)
                except Exception:
                    self.bot.send_message(chat.id, 'Unknow error. Sorry.')
            #Select random slogan from file "pogovorki.txt" and send in chat
            if Slogan in text:
                fp = open("pogovorki.txt")
                lines = fp.readlines()
                fp.close()
                phrase = ["Как говорил мой дед: ",
                          "Как говорят у нас в народе: ",
                          "Народная мудрость: ",
                          "Как мы все знаем: "]
                a = random.randrange(0,4,1)
                i = random.randrange(0,1353,1)
                slogan = (lines[i].strip())
                bot_answer = phrase[a] + slogan
                try:
                    self.bot.send_message(chat.id, bot_answer)
                except Exception:
                    self.bot.send_message(chat.id, 'Unknow error. Sorry.')
            #Send strickers in chat
            if (text == Sticker):
                stikers = ["BQADAgADeAcAAlOx9wOjY2jpAAHq9DUC"]
                try:
                    self.bot.send_sticker(chat.id, stikers[0])
                except Exception:
                    self.bot.send_photo(chat.id, 'Unknow error. Sorry.')
            #Send photo from /photo path
            if (text == Photo):
                photos = ["photo/photo1.jpg"]
                          #"photo/photo2.jpg",
                          #"photo/photo3.jpg"]
                #i = random.randrange(0,3,1)
                fp = open(photos[0], "rb")
                file_info = InputFileInfo(photos[0], fp, 'image/jpg')
                a = InputFile('photo', file_info)
                self.bot.send_photo(chat.id, a)
                fp.close()
            #Send comment from Toxa.txt file
            if Toxa in text:
                fp = open("Toxa.txt")
                lines = fp.readlines()
                fp.close()
                i = random.randrange(0,len(lines)-1,1)
                slogan = (lines[i].strip())
                bot_answer = slogan + '\n'
                try:
                    self.bot.send_message(chat.id, bot_answer)
                except Exception:
                    self.bot.send_message(chat.id, 'Unknow error. Sorry.')
            #Send comment from Zaur.txt file
            if Zaur in text:
                fp = open("Zaur.txt")
                lines = fp.readlines()
                fp.close()
                i = random.randrange(0,len(lines)-1,1)
                slogan = (lines[i].strip())
                bot_answer = slogan + '\n'
                try:
开发者ID:pablozzz,项目名称:zaurtox_bot,代码行数:70,代码来源:ZaurTox.py

示例4: print

# 需要导入模块: from twx.botapi import TelegramBot [as 别名]
# 或者: from twx.botapi.TelegramBot import send_photo [as 别名]
print("started")

bot = TelegramBot('157665031:AAHaeUoydRVxbisOrx-yA3542NYlmA0XOdo')
bot.update_bot_info().wait()
print(bot.username)

"""
Send a message to a user
"""
user_id = int(122012260)
fp = open('0005-006-TSypljonok-ostalsja-u-zabora-odin.png', 'rb')
file_info = InputFileInfo('0005-006-TSypljonok-ostalsja-u-zabora-odin.png', fp, 'image/png')

i = InputFile('photo', file_info)

bot.send_photo(chat_id=79434866, photo=i)
#result = bot.send_message(user_id, 'ddd').wait()
#print(result)

"""
Get updates sent to the bot
"""
updates = bot.get_updates().wait()
for update in updates:
    print(update)

"""
Use a custom keyboard
"""
keyboard = [
    ['7', '8', '9'],
开发者ID:VladPisatel,项目名称:CerberApp,代码行数:33,代码来源:init.py

示例5: AdapterTelegram2Channel

# 需要导入模块: from twx.botapi import TelegramBot [as 别名]
# 或者: from twx.botapi.TelegramBot import send_photo [as 别名]
class AdapterTelegram2Channel(AbstractChannel):

    def __init__(self, token, bot_id, my_user):
        self.token = token.strip()
        self.bot_id = int(bot_id)
        self.my_user = int(my_user)

        self.bot = TelegramBot(self.token)
        self.bot.update_bot_info().wait()

        self.queue = deque()
        self.offset = 0  # Needed for the bot.get_updates method to avoid getting duplicate updates

    def send_text(self, text):
        """
        Send a message to the user
        """
        # Removing the wait method will make sending multiple messages faster, of course, however in practice
        # it is too fast. It gives a better UX with the wait
        self.bot.send_message(self.my_user, text).wait()

    def get_user_messages(self):
        """
        Get updates sent to the bot
        """
        # Because many updates can happen in a short interval, we are going to store them in a queue
        # because to stick to the interface we need to return just one update by function call
        updates = self.bot.get_updates(offset=self.offset).wait()
        [self.queue.append(update) for update in updates if (update and update.message.sender.id != self.bot_id)]

        if len(updates):
            # Re-compute the offset
            self.offset = max([elem.update_id for elem in updates]) + 1

        if len(self.queue):
            # Get the oldest element in the queue
            first_update = self.queue.popleft()
            return first_update.message.text, first_update.message.sender.id
        else:
            return None, None

    def send_pic(self, path2pic):

        with open(path2pic, 'rb') as finput:
            file_info = InputFileInfo(os.path.basename(path2pic), finput, 'image/jpeg')
            input_file = InputFile('photo', file_info)
            self.bot.send_photo(self.my_user, input_file)
            time.sleep(0.5)

    def allowed_user(self, user_id):
        return user_id == self.my_user

    def close(self):
        pass

    def flush(self):
        """
        The purpose of this method is to clean the channel at the beginning of the execution.
        This is to fix a known issue with the usr_cmd_finish command that was left in the channel
        and causes the closing of Alfred every execution. This happens because at the beginning,
        self.offset it's initialized to 0 and many of the previous messages are recovered again
        """

        updates = self.bot.get_updates(offset=self.offset).wait()

        if len(updates):
            # Re-compute the offset
            self.offset = max([elem.update_id for elem in updates]) + 1
开发者ID:ricgu8086,项目名称:vAlfred-2.0,代码行数:70,代码来源:AdapterTelegram2Channel.py


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