本文整理汇总了Python中telegram.ChatAction.TYPING属性的典型用法代码示例。如果您正苦于以下问题:Python ChatAction.TYPING属性的具体用法?Python ChatAction.TYPING怎么用?Python ChatAction.TYPING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类telegram.ChatAction
的用法示例。
在下文中一共展示了ChatAction.TYPING属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_typing
# 需要导入模块: from telegram import ChatAction [as 别名]
# 或者: from telegram.ChatAction import TYPING [as 别名]
def send_typing(cls, func):
def _send_typing_action(self, bot, update, **kwargs):
if update.message:
user_id = update.message.chat_id
elif update.callback_query:
user_id = update.callback_query.message.chat_id
else:
return func(self, bot, update, **kwargs)
try:
bot.send_chat_action(
chat_id=user_id,
action=ChatAction.TYPING)
except Exception as ex:
logging.error(f"{ex} - {update}")
return func(self, bot, update, **kwargs)
return _send_typing_action
示例2: github
# 需要导入模块: from telegram import ChatAction [as 别名]
# 或者: from telegram.ChatAction import TYPING [as 别名]
def github(update: Update, context: CallbackContext):
message = update.message or update.edited_message
last = 0
thing_matches = []
things = {}
# Due to bug in ptb we need to convert entities of type URL to TEXT_LINK for them to be converted to html
for entity in message.entities:
if entity.type == MessageEntity.URL:
entity.type = MessageEntity.TEXT_LINK
entity.url = message.parse_entity(entity)
for match in GITHUB_PATTERN.finditer(get_text_not_in_entities(message.text_html)):
logging.debug(match.groupdict())
owner, repo, number, sha = [match.groupdict()[x] for x in ('owner', 'repo', 'number', 'sha')]
if number or sha:
thing_matches.append((owner, repo, number, sha))
for thing_match in thing_matches:
last = keep_typing(last, update.effective_chat, ChatAction.TYPING)
owner, repo, number, sha = thing_match
if number:
issue = github_issues.get_issue(int(number), owner, repo)
things[issue.url] = github_issues.pretty_format_issue(issue)
elif sha:
commit = github_issues.get_commit(sha, owner, repo)
things[commit.url] = github_issues.pretty_format_commit(commit)
if things:
reply_or_edit(update, context, '\n'.join([f'<a href="{url}">{name}</a>' for url, name in things.items()]))
示例3: wait
# 需要导入模块: from telegram import ChatAction [as 别名]
# 或者: from telegram.ChatAction import TYPING [as 别名]
def wait(bot, update, t=1.5):
chat_id = uid_from_update(update)
bot.sendChatAction(chat_id, ChatAction.TYPING)
time.sleep(t)
示例4: start
# 需要导入模块: from telegram import ChatAction [as 别名]
# 或者: from telegram.ChatAction import TYPING [as 别名]
def start(bot, update):
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text="Hi. I'm sudobot.")
if update.message.from_user.id != int(config['ADMIN']['id']):
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
time.sleep(1)
bot.sendMessage(chat_id=update.message.chat_id,
text="It seems like you aren't allowed to use me. :(")
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
time.sleep(1.5)
bot.sendMessage(chat_id=update.message.chat_id,
text="But sudobot is open source software, which means you can have your own! See my [GitHub repo](https://github.com/bvanrijn/sudobot) for details.", parse_mode="Markdown")
else:
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
time.sleep(1)
bot.sendMessage(chat_id=update.message.chat_id,
text="You can use me to run commands on your computer or server.")
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
time.sleep(1.5)
bot.sendMessage(chat_id=update.message.chat_id,
text="Note that interactive commands or commands that generate a lot of output won't work.")
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
time.sleep(1)
bot.sendMessage(chat_id=update.message.chat_id, text="Have fun!")
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
time.sleep(1.5)
bot.sendMessage(chat_id=update.message.chat_id,
text="Oh, before I forget: sudobot is open source software. See my [GitHub repo](https://github.com/bvanrijn/sudobot).", parse_mode="Markdown")
示例5: execute
# 需要导入模块: from telegram import ChatAction [as 别名]
# 或者: from telegram.ChatAction import TYPING [as 别名]
def execute(bot, update, direct=True):
try:
user_id = update.message.from_user.id
command = update.message.text
inline = False
except AttributeError:
# Using inline
user_id = update.inline_query.from_user.id
command = update.inline_query.query
inline = True
if user_id == int(config['ADMIN']['id']):
if not inline:
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = output.stdout.read().decode('utf-8')
output = '`{0}`'.format(output)
if not inline:
bot.sendMessage(chat_id=update.message.chat_id,
text=output, parse_mode="Markdown")
return False
if inline:
return output
示例6: send_typing_action
# 需要导入模块: from telegram import ChatAction [as 别名]
# 或者: from telegram.ChatAction import TYPING [as 别名]
def send_typing_action(bot, update):
"""Send 'typing...' message to chat as long as it is not a reply message."""
if not update.message.reply_to_message:
frontend_logger.debug("Send typing")
bot.sendChatAction(chat_id=update.message.chat_id, action=ChatAction.TYPING)
示例7: bot_send_message
# 需要导入模块: from telegram import ChatAction [as 别名]
# 或者: from telegram.ChatAction import TYPING [as 别名]
def bot_send_message(bot, update, text):
bot.sendChatAction(update.message.chat_id, action=ChatAction.TYPING)
sleep(random.random() * 2 + 1.)
bot.sendMessage(update.message.chat_id, text=text)
示例8: typing_illusion
# 需要导入模块: from telegram import ChatAction [as 别名]
# 或者: from telegram.ChatAction import TYPING [as 别名]
def typing_illusion(bot, chat_id):
try:
bot.sendChatAction(chat_id=chat_id, action=ChatAction.TYPING) # typing illusion
except:
sleep(1)
bot.sendChatAction(chat_id=chat_id, action=ChatAction.TYPING) # typing illusion