本文整理汇总了Python中telegram.Message方法的典型用法代码示例。如果您正苦于以下问题:Python telegram.Message方法的具体用法?Python telegram.Message怎么用?Python telegram.Message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram
的用法示例。
在下文中一共展示了telegram.Message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_settings
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def get_settings(bot: Bot, update: Update):
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
msg = update.effective_message # type: Optional[Message]
args = msg.text.split(None, 1)
# ONLY send settings in PM
if chat.type != chat.PRIVATE:
if is_user_admin(chat, user.id):
text = "Click here to get this chat's settings, as well as yours."
msg.reply_text(text,
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton(text="Settings",
url="t.me/{}?start=stngs_{}".format(
bot.username, chat.id))]]))
else:
text = "Click here to check your settings."
else:
send_settings(chat.id, user.id, True)
示例2: migrate_chats
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def migrate_chats(bot: Bot, update: Update):
msg = update.effective_message # type: Optional[Message]
if msg.migrate_to_chat_id:
old_chat = update.effective_chat.id
new_chat = msg.migrate_to_chat_id
elif msg.migrate_from_chat_id:
old_chat = msg.migrate_from_chat_id
new_chat = update.effective_chat.id
else:
return
LOGGER.info("Migrating from %s, to %s", str(old_chat), str(new_chat))
for mod in MIGRATEABLE:
mod.__migrate__(old_chat, new_chat)
LOGGER.info("Successfully migrated!")
raise DispatcherHandlerStop
示例3: log_user
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def log_user(bot: Bot, update: Update):
chat = update.effective_chat # type: Optional[Chat]
msg = update.effective_message # type: Optional[Message]
sql.update_user(msg.from_user.id,
msg.from_user.username,
chat.id,
chat.title)
if msg.reply_to_message:
sql.update_user(msg.reply_to_message.from_user.id,
msg.reply_to_message.from_user.username,
chat.id,
chat.title)
if msg.forward_from:
sql.update_user(msg.forward_from.id,
msg.forward_from.username)
示例4: loggable
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def loggable(func):
@wraps(func)
def log_action(bot: Bot, update: Update, *args, **kwargs):
result = func(bot, update, *args, **kwargs)
chat = update.effective_chat # type: Optional[Chat]
message = update.effective_message # type: Optional[Message]
if result:
if chat.type == chat.SUPERGROUP and chat.username:
result += "\n<b>Link:</b> " \
"<a href=\"http://telegram.me/{}/{}\">click here</a>".format(chat.username,
message.message_id)
log_chat = sql.get_chat_log_channel(chat.id)
if log_chat:
send_log(bot, log_chat, chat.id, result)
elif result == "":
pass
else:
LOGGER.warning("%s was set as loggable, but had no return statement.", func)
return result
return log_action
示例5: enforce_gban
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def enforce_gban(bot: Bot, update: Update):
# Not using @restrict handler to avoid spamming - just ignore if cant gban.
if sql.does_chat_gban(update.effective_chat.id) and update.effective_chat.get_member(bot.id).can_restrict_members:
user = update.effective_user # type: Optional[User]
chat = update.effective_chat # type: Optional[Chat]
msg = update.effective_message # type: Optional[Message]
if user and not is_user_admin(chat, user.id):
check_and_ban(update, user.id)
if msg.new_chat_members:
new_members = update.effective_message.new_chat_members
for mem in new_members:
check_and_ban(update, mem.id)
if msg.reply_to_message:
user = msg.reply_to_message.from_user # type: Optional[User]
if user and not is_user_admin(chat, user.id):
check_and_ban(update, user.id, should_message=False)
示例6: blacklist
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def blacklist(bot: Bot, update: Update, args: List[str]):
msg = update.effective_message # type: Optional[Message]
chat = update.effective_chat # type: Optional[Chat]
all_blacklisted = sql.get_chat_blacklist(chat.id)
filter_list = BASE_BLACKLIST_STRING
if len(args) > 0 and args[0].lower() == 'copy':
for trigger in all_blacklisted:
filter_list += "<code>{}</code>\n".format(html.escape(trigger))
else:
for trigger in all_blacklisted:
filter_list += " - <code>{}</code>\n".format(html.escape(trigger))
split_text = split_message(filter_list)
for text in split_text:
if text == BASE_BLACKLIST_STRING:
msg.reply_text("There are no blacklisted messages here!")
return
msg.reply_text(text, parse_mode=ParseMode.HTML)
示例7: add_blacklist
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def add_blacklist(bot: Bot, update: Update):
msg = update.effective_message # type: Optional[Message]
chat = update.effective_chat # type: Optional[Chat]
words = msg.text.split(None, 1)
if len(words) > 1:
text = words[1]
to_blacklist = list(set(trigger.strip() for trigger in text.split("\n") if trigger.strip()))
for trigger in to_blacklist:
sql.add_to_blacklist(chat.id, trigger.lower())
if len(to_blacklist) == 1:
msg.reply_text("Added <code>{}</code> to the blacklist!".format(html.escape(to_blacklist[0])),
parse_mode=ParseMode.HTML)
else:
msg.reply_text(
"Added <code>{}</code> triggers to the blacklist.".format(len(to_blacklist)), parse_mode=ParseMode.HTML)
else:
msg.reply_text("Tell me which words you would like to add to the blacklist.")
示例8: del_blacklist
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def del_blacklist(bot: Bot, update: Update):
chat = update.effective_chat # type: Optional[Chat]
message = update.effective_message # type: Optional[Message]
to_match = extract_text(message)
if not to_match:
return
chat_filters = sql.get_chat_blacklist(chat.id)
for trigger in chat_filters:
pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])"
if re.search(pattern, to_match, flags=re.IGNORECASE):
try:
message.delete()
except BadRequest as excp:
if excp.message == "Message to delete not found":
pass
else:
LOGGER.exception("Error while deleting blacklist message.")
break
示例9: set_welcome
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def set_welcome(bot: Bot, update: Update) -> str:
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
msg = update.effective_message # type: Optional[Message]
text, data_type, content, buttons = get_welcome_type(msg)
if data_type is None:
msg.reply_text("You didn't specify what to reply with!")
return ""
sql.set_custom_welcome(chat.id, content or text, data_type, buttons)
msg.reply_text("Successfully set custom welcome message!")
return "<b>{}:</b>" \
"\n#SET_WELCOME" \
"\n<b>Admin:</b> {}" \
"\nSet the welcome message.".format(html.escape(chat.title),
mention_html(user.id, user.first_name))
示例10: set_goodbye
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def set_goodbye(bot: Bot, update: Update) -> str:
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
msg = update.effective_message # type: Optional[Message]
text, data_type, content, buttons = get_welcome_type(msg)
if data_type is None:
msg.reply_text("You didn't specify what to reply with!")
return ""
sql.set_custom_gdbye(chat.id, content or text, data_type, buttons)
msg.reply_text("Successfully set custom goodbye message!")
return "<b>{}:</b>" \
"\n#SET_GOODBYE" \
"\n<b>Admin:</b> {}" \
"\nSet the goodbye message.".format(html.escape(chat.title),
mention_html(user.id, user.first_name))
示例11: about_me
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def about_me(bot: Bot, update: Update, args: List[str]):
message = update.effective_message # type: Optional[Message]
user_id = extract_user(message, args)
if user_id:
user = bot.get_chat(user_id)
else:
user = message.from_user
info = sql.get_user_me_info(user.id)
if info:
update.effective_message.reply_text("*{}*:\n{}".format(user.first_name, escape_markdown(info)),
parse_mode=ParseMode.MARKDOWN)
elif message.reply_to_message:
username = message.reply_to_message.from_user.first_name
update.effective_message.reply_text(username + " hasn't set an info message about themselves yet!")
else:
update.effective_message.reply_text("You haven't set an info message about yourself yet!")
示例12: about_bio
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def about_bio(bot: Bot, update: Update, args: List[str]):
message = update.effective_message # type: Optional[Message]
user_id = extract_user(message, args)
if user_id:
user = bot.get_chat(user_id)
else:
user = message.from_user
info = sql.get_user_bio(user.id)
if info:
update.effective_message.reply_text("*{}*:\n{}".format(user.first_name, escape_markdown(info)),
parse_mode=ParseMode.MARKDOWN)
elif message.reply_to_message:
username = user.first_name
update.effective_message.reply_text("{} hasn't had a message set about themselves yet!".format(username))
else:
update.effective_message.reply_text("You haven't had a bio set about yourself yet!")
示例13: set_about_bio
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def set_about_bio(bot: Bot, update: Update):
message = update.effective_message # type: Optional[Message]
sender = update.effective_user # type: Optional[User]
if message.reply_to_message:
repl_message = message.reply_to_message
user_id = repl_message.from_user.id
if user_id == message.from_user.id:
message.reply_text("Ha, you can't set your own bio! You're at the mercy of others here...")
return
elif user_id == bot.id and sender.id not in SUDO_USERS:
message.reply_text("Erm... yeah, I only trust sudo users to set my bio.")
return
text = message.text
bio = text.split(None, 1) # use python's maxsplit to only remove the cmd, hence keeping newlines.
if len(bio) == 2:
if len(bio[1]) < MAX_MESSAGE_LENGTH // 4:
sql.set_user_bio(user_id, bio[1])
message.reply_text("Updated {}'s bio!".format(repl_message.from_user.first_name))
else:
message.reply_text(
"A bio needs to be under {} characters! You tried to set {}.".format(
MAX_MESSAGE_LENGTH // 4, len(bio[1])))
else:
message.reply_text("Reply to someone's message to set their bio!")
示例14: reset_warns
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str:
message = update.effective_message # type: Optional[Message]
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
user_id = extract_user(message, args)
if user_id:
sql.reset_warns(user_id, chat.id)
message.reply_text("Warnings have been reset!")
warned = chat.get_member(user_id).user
return "<b>{}:</b>" \
"\n#RESETWARNS" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(warned.id, warned.first_name),
warned.id)
else:
message.reply_text("No user has been designated!")
return ""
示例15: reply_filter
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Message [as 别名]
def reply_filter(bot: Bot, update: Update) -> str:
chat = update.effective_chat # type: Optional[Chat]
message = update.effective_message # type: Optional[Message]
chat_warn_filters = sql.get_chat_warn_triggers(chat.id)
to_match = extract_text(message)
if not to_match:
return ""
for keyword in chat_warn_filters:
pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])"
if re.search(pattern, to_match, flags=re.IGNORECASE):
user = update.effective_user # type: Optional[User]
warn_filter = sql.get_warn_filter(chat.id, keyword)
return warn(user, chat, warn_filter.reply, message)
return ""