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


Python Filters.voice方法代码示例

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


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

示例1: build_lock_message

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import voice [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

示例2: voice

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import voice [as 别名]
def voice(bot, update):
  chat_id = get_chat_id(update)
  voice_enabled = TBDB.get_chat_voice_enabled(chat_id)
  if voice_enabled == 0:
    return
  
  message = update.message or update.channel_post
  v = message.voice
  
  if voice_enabled == 2:
    pass
  else:
    TranscriberBot.get().voice_thread_pool.submit(
      process_media_voice, bot, update, v, "voice"
    ) 
开发者ID:charslab,项目名称:TranscriberBot,代码行数:17,代码来源:handlers_messages.py

示例3: build_lock_message

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import voice [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 - 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.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:TGExplore,项目名称:Marie-2.0-English,代码行数:33,代码来源:locks.py

示例4: __init__

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import voice [as 别名]
def __init__(self, params):
        """
        A Telegram bot interface for Macaw.

        Args:
            params(dict): A dict of parameters. The params 'logger' and 'bot_token' are mandatory.
        """
        super().__init__(params)
        self.logger = self.params['logger']

        self.MAX_MSG_LEN = 1000  # maximum number of characters in each response message.
        self.MAX_OPTION_LEN = 30  # maximum number of characters in each clickable option text.

        # Starting the bot by creating the Updater.
        # Make sure to set use_context=True to use the new context based callbacks
        # If you don't have a bot_token, add 'botfather' to your personal Telegram account and follow the instructions
        # to get a token for your bot.
        self.updater = Updater(self.params['bot_token'], use_context=True)
        self.dp = self.updater.dispatcher

        # Telegram command handlers (e.g., /start)
        self.dp.add_handler(CommandHandler('start', self.start))
        self.dp.add_handler(CommandHandler('help', self.help))

        # Telegram message handlers
        self.dp.add_handler(MessageHandler(Filters.text, self.request_handler))
        self.dp.add_handler(MessageHandler(Filters.voice, self.voice_request_handler))
        self.dp.add_handler(CallbackQueryHandler(self.button_click_handler))

        # logging all errors
        self.dp.add_error_handler(self.error) 
开发者ID:microsoft,项目名称:macaw,代码行数:33,代码来源:telegram.py

示例5: voice_request_handler

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import voice [as 别名]
def voice_request_handler(self, update, context):
        """This method handles all voice messages, and asks result_presentation to send the response to the user."""
        try:
            ogg_file = tempfile.NamedTemporaryFile(delete=True)
            update.message.voice.get_file().download(ogg_file.name)
            text = self.params['asr'].speech_to_text(ogg_file.name)
            ogg_file.close()
            update.message.reply_text('Macaw heard: ' + text)

            user_info = {'first_name': update.message.chat.first_name,
                         'last_name': update.message.chat.last_name,
                         'is_bot': update._effective_user.is_bot
                         }
            msg_info = {'msg_id': update.message.message_id,
                        'msg_type': 'voice',
                        'msg_source': 'user'}
            msg = Message(user_interface='telegram',
                          user_id=update.message.chat.id,
                          user_info=user_info,
                          msg_info=msg_info,
                          text=text,
                          timestamp=util.current_time_in_milliseconds())
            output = self.params['live_request_handler'](msg)
            self.result_presentation(output, {'update': update})
        except Exception:
            traceback.print_exc() 
开发者ID:microsoft,项目名称:macaw,代码行数:28,代码来源:telegram.py

示例6: result_presentation

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import voice [as 别名]
def result_presentation(self, response_msg, params):
        """This method produces an appropriate response to be sent to the client."""
        try:
            if response_msg is None:
                return
            update = params['update']
            if response_msg.msg_info['msg_type'] == 'text':
                if update.message is not None:
                    update.message.reply_text(response_msg.text[:self.MAX_MSG_LEN])
                elif update.callback_query.message is not None:
                    update.callback_query.message.reply_text(response_msg.text[:self.MAX_MSG_LEN])
            elif response_msg.msg_info['msg_type'] == 'voice':
                ogg_file_name = self.params['asg'].text_to_speech(response_msg.text[:self.MAX_MSG_LEN])
                self.updater.bot.send_voice(chat_id=update.message.chat.id, voice=open(ogg_file_name, 'rb'))
                os.remove(ogg_file_name)  # removing audio files for privacy reasons.
            elif response_msg.msg_info['msg_type'] == 'options':
                keyboard = [[InlineKeyboardButton(option_text[:self.MAX_OPTION_LEN],
                                                  callback_data=urllib.parse.unquote(option_data))]
                            for (option_text, option_data, output_score) in response_msg.msg_info['options']]
                reply_markup = InlineKeyboardMarkup(keyboard)
                update.message.reply_text(response_msg.text[:self.MAX_MSG_LEN], reply_markup=reply_markup)
            elif response_msg.msg_info['msg_type'] == 'error':
                error_msg = 'ERROR: NO RESULT!'
                if update.message is not None:
                    update.message.reply_text(error_msg)
                elif update.callback_query.message is not None:
                    update.callback_query.message.reply_text(error_msg)
            else:
                raise Exception('The msg_type is not recognized:', response_msg.msg_info['msg_type'])
        except Exception:
            traceback.print_exc() 
开发者ID:microsoft,项目名称:macaw,代码行数:33,代码来源:telegram.py

示例7: build_lock_message

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import voice [as 别名]
def build_lock_message(chat_id):
	locks = sql.get_locks(chat_id)
	res = ""
	locklist = []
	permslist = []
	if locks:
		res += "*" + tl(chat_id, "Ini adalah kunci dalam obrolan ini:") + "*"
		if locks:
			locklist.append("sticker = `{}`".format(locks.sticker))
			locklist.append("audio = `{}`".format(locks.audio))
			locklist.append("voice = `{}`".format(locks.voice))
			locklist.append("document = `{}`".format(locks.document))
			locklist.append("video = `{}`".format(locks.video))
			locklist.append("contact = `{}`".format(locks.contact))
			locklist.append("photo = `{}`".format(locks.photo))
			locklist.append("gif = `{}`".format(locks.gif))
			locklist.append("url = `{}`".format(locks.url))
			locklist.append("bots = `{}`".format(locks.bots))
			locklist.append("forward = `{}`".format(locks.forward))
			locklist.append("game = `{}`".format(locks.game))
			locklist.append("location = `{}`".format(locks.location))
			locklist.append("rtl = `{}`".format(locks.rtl))
			locklist.append("button = `{}`".format(locks.button))
	permissions = dispatcher.bot.get_chat(chat_id).permissions
	permslist.append("messages = `{}`".format(permissions.can_send_messages))
	permslist.append("media = `{}`".format(permissions.can_send_media_messages))
	permslist.append("poll = `{}`".format(permissions.can_send_polls))
	permslist.append("other = `{}`".format(permissions.can_send_other_messages))
	permslist.append("previews = `{}`".format(permissions.can_add_web_page_previews))
	permslist.append("info = `{}`".format(permissions.can_change_info))
	permslist.append("invite = `{}`".format(permissions.can_invite_users))
	permslist.append("pin = `{}`".format(permissions.can_pin_messages))

	if locklist:
		# Ordering lock list
		locklist.sort()
		# Building lock list string
		for x in locklist:
			res += "\n - {}".format(x)
	res += "\n\n*" + tl(chat_id, "Ini adalah izin dalam obrolan ini:") + "*"
	for x in permslist:
		res += "\n - {}".format(x)
	return res 
开发者ID:AyraHikari,项目名称:EmiliaHikari,代码行数:45,代码来源:locks.py


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