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


Python Filters.document方法代码示例

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


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

示例1: file_handler

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def file_handler(update, context):
  """handles the uploaded files"""

  file = context.bot.getFile(update.message.document.file_id)
  file.download(update.message.document.file_name)

  doc = update.message.document

  service = build('drive', 'v3', credentials=getCreds(),cache_discovery=False)
  filename = doc.file_name

  metadata = {'name': filename}
  media = MediaFileUpload(filename, chunksize=1024 * 1024, mimetype=doc.mime_type,  resumable=True)
  request = service.files().create(body=metadata,
                                media_body=media)

  response = None
  while response is None:
    status, response = request.next_chunk()
    if status:
       print( "Uploaded %d%%." % int(status.progress() * 100))

  context.bot.send_message(chat_id=update.effective_chat.id, text="✅ File uploaded!") 
开发者ID:zume2020,项目名称:Telegram-bot-Google-Drive,代码行数:25,代码来源:bot.py

示例2: __init__

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def __init__(self, api_key, fallback):
        self.compiler = HackerRankAPI(api_key=api_key)
        self.conv_handler = ConversationHandler(
            entry_points=[CommandHandler('compiler', self.compilers)],
            allow_reentry=True,
            states={
                LANG: [CallbackQueryHandler(self.lang, pass_user_data=True, pattern=r'\w*comp1\b')],
                CODE: [CallbackQueryHandler(self.code, pass_user_data=True, pattern=r'\w*so1\b')],
                DECODE: [MessageHandler(Filters.text, self.decode, pass_user_data=True)],
                TESTCASES: [MessageHandler(Filters.text, self.testcases, pass_user_data=True)],
                OTHER: [MessageHandler(Filters.text, self.other, pass_user_data=True)],
                FILE: [MessageHandler(Filters.document, self.filer, pass_user_data=True)],
                FILETEST: [MessageHandler(Filters.document, self.filetest, pass_user_data=True)]
            },
            fallbacks=[fallback]
        ) 
开发者ID:Gotham13121997,项目名称:superCodingBot,代码行数:18,代码来源:compiler.py

示例3: filetest

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def filetest(self, bot, update, user_data):
        file_id = update.message.document.file_id
        if ComHandler.check_file_size(update):
            return ConversationHandler.END
        newFile = bot.get_file(file_id)
        newFile.download('test.txt')
        with open('test.txt', 'rt') as f:
            source = f.read()
        s1 = (str(user_data['code'])).replace("«", "<<").replace("»", ">>")
        result = self.compiler.run({'source': s1,
                               'lang': user_data['lang'],
                               'testcases': [source]
                               })
        Utility.paginate(bot, update, result)
        user_data.clear()
        os.remove('test.txt')
        return ConversationHandler.END 
开发者ID:Gotham13121997,项目名称:superCodingBot,代码行数:19,代码来源:compiler.py

示例4: __init__

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def __init__(self, mount_point, admin_list, fallback):
        self.admin_list = admin_list
        self.mount_point = mount_point
        self.utility = Utility(mount_point)
        self.conv_handler1 = ConversationHandler(
            entry_points=[CommandHandler('broadcast', self.broadcast)],
            allow_reentry=True,
            states={
                BDC: [MessageHandler(Filters.text, self.broadcast_message)]
            },
            fallbacks=[fallback]
        )
        self.conv_handler2 = ConversationHandler(
            entry_points=[CommandHandler('senddb', self.getDb)],
            allow_reentry=True,
            states={
                DB: [MessageHandler(Filters.document, self.db)]
            },
            fallbacks=[fallback]
        )

    # START OF ADMIN CONVERSATION HANDLER TO BROADCAST MESSAGE 
开发者ID:Gotham13121997,项目名称:superCodingBot,代码行数:24,代码来源:admin.py

示例5: document

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def document(bot, update):
  chat_id = get_chat_id(update)
  voice_enabled = TBDB.get_chat_voice_enabled(chat_id)

  m = update.message or update.channel_post
  file_name = m.document.file_name
  _, file_ext = os.path.splitext(file_name)

  if file_ext[1:] not in config.get_config_prop("app")["audio_ext"]:
    logger.info('extension %s not recognized', file_ext)
    return

  if voice_enabled == 0:
    return

  if voice_enabled == 2:
    pass
  else:
    TranscriberBot.get().voice_thread_pool.submit(
      process_media_voice, bot, update, m.document, 'audio_document'
    ) 
开发者ID:charslab,项目名称:TranscriberBot,代码行数:23,代码来源:handlers_messages.py

示例6: _group_hook

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def _group_hook(self):
        # noinspection PyUnusedLocal
        def hook(update, context):
            msg = update.effective_message
            if msg.group_chat_created:
                self.bus.post(GroupChatCreatedEvent(chat_id=update.effective_chat.id,
                                                    message=self._plugin.parse_msg(msg).output,
                                                    user=self._plugin.parse_user(update.effective_user).output))
            elif msg.photo:
                self._msg_hook(PhotoMessageEvent)(update, context)
            elif msg.video:
                self._msg_hook(VideoMessageEvent)(update, context)
            elif msg.contact:
                self._msg_hook(ContactMessageEvent)(update, context)
            elif msg.location:
                self._msg_hook(LocationMessageEvent)(update, context)
            elif msg.document:
                self._msg_hook(DocumentMessageEvent)(update, context)
            elif msg.text:
                if msg.text.startswith('/'):
                    self._command_hook()(update, context)
                else:
                    self._msg_hook(TextMessageEvent)(update, context)

        return hook 
开发者ID:BlackLight,项目名称:platypush,代码行数:27,代码来源:telegram.py

示例7: run

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def run(self):
        # noinspection PyPackageRequirements
        from telegram.ext import MessageHandler, Filters

        super().run()
        telegram = self._plugin.get_telegram()
        dispatcher = telegram.dispatcher

        dispatcher.add_handler(MessageHandler(Filters.group, self._group_hook()))
        dispatcher.add_handler(MessageHandler(Filters.text, self._msg_hook(TextMessageEvent)))
        dispatcher.add_handler(MessageHandler(Filters.photo, self._msg_hook(PhotoMessageEvent)))
        dispatcher.add_handler(MessageHandler(Filters.video, self._msg_hook(VideoMessageEvent)))
        dispatcher.add_handler(MessageHandler(Filters.contact, self._msg_hook(ContactMessageEvent)))
        dispatcher.add_handler(MessageHandler(Filters.location, self._msg_hook(LocationMessageEvent)))
        dispatcher.add_handler(MessageHandler(Filters.document, self._msg_hook(DocumentMessageEvent)))
        dispatcher.add_handler(MessageHandler(Filters.command, self._command_hook()))

        self.logger.info('Initialized Telegram backend')
        telegram.start_polling()


# vim:sw=4:ts=4:et: 
开发者ID:BlackLight,项目名称:platypush,代码行数:24,代码来源:telegram.py

示例8: _download

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def _download(self, bot, update):
        # Check if in a private chat
        if bot.get_chat(update.message.chat_id).type != Chat.PRIVATE:
            return

        # Check if user that triggered the command is allowed to execute it
        if update.effective_user.id not in Cfg.get("admin_id"):
            return

        name = update.message.effective_attachment.file_name
        file = bot.getFile(update.message.document.file_id)
        file.download(os.path.join(con.SRC_DIR, con.PLG_DIR, name))

        try:
            self.reload_plugin(name.replace(".py", ""))
            update.message.reply_text(f"{emo.CHECK} Plugin loaded successfully")
        except Exception as ex:
            update.message.reply_text(f"{emo.ERROR} {ex}") 
开发者ID:Endogen,项目名称:OpenCryptoBot,代码行数:20,代码来源:telegrambot.py

示例9: get

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def get(bot, update):
    """Send requested file."""
    username = update.message.from_user.username
    if(username not in username_list):
        update.message.reply_text("You are not Authorized.")
        return
    file = update.message.text.split(" ")[-1]
    if(file == "/send"):
        update.message.reply_text("Invalid File name.")
    else:
        reply = "Findind and Sending a requested file to you. Hold on..."
        update.message.reply_text(reply)
        path = os.getcwd()+'/'+file
        if (os.path.exists(path)):
            bot.send_document(chat_id=update.message.chat_id,document=open(path, 'rb'), timeout = 100)
        else:
            update.message.reply_text("File not Found.") 
开发者ID:hastagAB,项目名称:Awesome-Python-Scripts,代码行数:19,代码来源:bot.py

示例10: main

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def main():
  updater = Updater(token=config.TOKEN,use_context=True)
  dispatcher = updater.dispatcher
  updater.dispatcher.add_handler(CommandHandler('start', start))
  dispatcher.add_handler(MessageHandler(Filters.document,file_handler))
  updater.start_polling() 
开发者ID:zume2020,项目名称:Telegram-bot-Google-Drive,代码行数:8,代码来源:bot.py

示例11: build_lock_message

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "There are no current locks in this chat."
    else:
        res = "These are the locks in this chat:"
        if locks:
            res += "\n - sticker = `{}`" \
                   "\n - audio = `{}`" \
                   "\n - voice = `{}`" \
                   "\n - document = `{}`" \
                   "\n - video = `{}`" \
                   "\n - videonote = `{}`" \
                   "\n - contact = `{}`" \
                   "\n - photo = `{}`" \
                   "\n - gif = `{}`" \
                   "\n - url = `{}`" \
                   "\n - bots = `{}`" \
                   "\n - forward = `{}`" \
                   "\n - game = `{}`" \
                   "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.videonote, locks.contact, locks.photo, locks.gif, locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - messages = `{}`" \
                   "\n - media = `{}`" \
                   "\n - other = `{}`" \
                   "\n - previews = `{}`" \
                   "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    return res 
开发者ID:skittles9823,项目名称:SkittBot,代码行数:34,代码来源:locks.py

示例12: receive_cf

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def receive_cf(self, bot, update):
        file_id = update.message.document.file_id
        newFile = bot.get_file(file_id)
        newFile.download(self.mount_point + 'codeforces.json')
        update.message.reply_text("saved")
        with open(self.mount_point + 'codeforces.json', 'r') as code_json:
            self.cf.change_cf(json.load(code_json))
        return ConversationHandler.END

    # END OF ADMIN CONVERSATION HANDLER TO REPLACE THE CODEFORCES JSON 
开发者ID:Gotham13121997,项目名称:superCodingBot,代码行数:12,代码来源:app.py

示例13: check_file_size

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def check_file_size(update):
        file_size = update.message.document.file_size
        if file_size > 2097152:
            update.message.reply_text("FILE SIZE GREATER THAN 2 MB")
            return True
        return False

    # FUNCTION TO DOWNLOAD THE FILE SENT AND EXTRACT ITS CONTENTS 
开发者ID:Gotham13121997,项目名称:superCodingBot,代码行数:10,代码来源:compiler.py

示例14: db

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def db(self, bot, update):
        file_id = update.message.document.file_id
        newFile = bot.get_file(file_id)
        newFile.download(self.mount_point + 'coders1.db')
        update.message.reply_text("saved")
        return ConversationHandler.END

    # END OF ADMIN CONVERSATION HANDLER TO REPLACE THE DATABASE 
开发者ID:Gotham13121997,项目名称:superCodingBot,代码行数:10,代码来源:admin.py

示例15: givememydb

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import document [as 别名]
def givememydb(self, bot, update):
        if self.not_admin(update):
            return
        bot.send_document(chat_id=update.message.chat_id, document=open(self.mount_point + 'coders1.db', 'rb'))

    # ADMIN COMMAND HANDLER FOR GETTING THE CODEFORCES JSON 
开发者ID:Gotham13121997,项目名称:superCodingBot,代码行数:8,代码来源:admin.py


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