本文整理汇总了Python中telegram.User方法的典型用法代码示例。如果您正苦于以下问题:Python telegram.User方法的具体用法?Python telegram.User怎么用?Python telegram.User使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram
的用法示例。
在下文中一共展示了telegram.User方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_settings
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [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: check_update
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [as 别名]
def check_update(self, update):
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
if super().check_update(update):
# Should be safe since check_update passed.
command = update.effective_message.text_html.split(None, 1)[0][1:].split('@')[0]
# disabled, admincmd, user admin
if sql.is_command_disabled(chat.id, command):
return command in ADMIN_CMDS and is_user_admin(chat, user.id)
# not disabled
else:
return True
return False
示例3: enforce_gban
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [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)
示例4: enforce_gmute
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [as 别名]
def enforce_gmute(bot: Bot, update: Update):
# Not using @restrict handler to avoid spamming - just ignore if cant gmute.
if sql.does_chat_gmute(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_mute(bot, update, user.id, should_message=True)
if msg.new_chat_members:
new_members = update.effective_message.new_chat_members
for mem in new_members:
check_and_mute(bot, update, mem.id, should_message=True)
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_mute(bot, update, user.id, should_message=True)
示例5: set_welcome
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [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))
示例6: set_goodbye
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [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))
示例7: set_about_bio
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [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!")
示例8: reset_warns
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [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 ""
示例9: reply_filter
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [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 ""
示例10: set_warn_limit
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [as 别名]
def set_warn_limit(bot: Bot, update: Update, args: List[str]) -> str:
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
msg = update.effective_message # type: Optional[Message]
if args:
if args[0].isdigit():
if int(args[0]) < 3:
msg.reply_text("The minimum warn limit is 3!")
else:
sql.set_warn_limit(chat.id, int(args[0]))
msg.reply_text("Updated the warn limit to {}".format(args[0]))
return "<b>{}:</b>" \
"\n#SET_WARN_LIMIT" \
"\n<b>Admin:</b> {}" \
"\nSet the warn limit to <code>{}</code>".format(html.escape(chat.title),
mention_html(user.id, user.first_name), args[0])
else:
msg.reply_text("Give me a number as an arg!")
else:
limit, soft_warn = sql.get_warn_setting(chat.id)
msg.reply_text("The current warn limit is {}".format(limit))
return ""
示例11: pin
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [as 别名]
def pin(bot: Bot, update: Update, args: List[str]) -> str:
user = update.effective_user # type: Optional[User]
chat = update.effective_chat # type: Optional[Chat]
is_group = chat.type != "private" and chat.type != "channel"
prev_message = update.effective_message.reply_to_message
is_silent = True
if len(args) >= 1:
is_silent = not (args[0].lower() == 'notify' or args[0].lower() == 'loud' or args[0].lower() == 'violent')
if prev_message and is_group:
try:
bot.pinChatMessage(chat.id, prev_message.message_id, disable_notification=is_silent)
except BadRequest as excp:
if excp.message == "Chat_not_modified":
pass
else:
raise
return "<b>{}:</b>" \
"\n#PINNED" \
"\n<b>Admin:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name))
return ""
示例12: unpin
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [as 别名]
def unpin(bot: Bot, update: Update) -> str:
chat = update.effective_chat
user = update.effective_user # type: Optional[User]
try:
bot.unpinChatMessage(chat.id)
except BadRequest as excp:
if excp.message == "Chat_not_modified":
pass
else:
raise
return "<b>{}:</b>" \
"\n#UNPINNED" \
"\n<b>Admin:</b> {}".format(html.escape(chat.title),
mention_html(user.id, user.first_name))
示例13: get_settings
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [as 别名]
def get_settings(update, context):
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 = tl(update.effective_message, "Klik di sini untuk mendapatkan pengaturan obrolan ini, serta milik Anda.")
msg.reply_text(text,
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton(text="Pengaturan",
url="t.me/{}?start=stngs_{}".format(
context.bot.username, chat.id))]]))
# else:
# text = tl(update.effective_message, "Klik di sini untuk memeriksa pengaturan Anda.")
else:
send_settings(chat.id, user.id, True)
示例14: enforce_gban
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [as 别名]
def enforce_gban(update, context):
# 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(context.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)
示例15: set_welcome
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import User [as 别名]
def set_welcome(update, context) -> str:
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
msg = update.effective_message # type: Optional[Message]
# If user is not set text and not reply a message
if not msg.reply_to_message:
if len(msg.text.split()) == 1:
send_message(update.effective_message, tl(update.effective_message, "Anda harus memberikan isi dalam pesan selamat datang!\nKetik `/welcomehelp` untuk beberapa bantuan pada welcome"), parse_mode="markdown")
return ""
text, data_type, content, buttons = get_welcome_type(msg)
if data_type is None:
send_message(update.effective_message, tl(update.effective_message, "Anda tidak menentukan apa yang harus dibalas!"))
return ""
sql.set_custom_welcome(chat.id, content, text, data_type, buttons)
send_message(update.effective_message, tl(update.effective_message, "Berhasil mengatur pesan sambutan kustom!"))
return "<b>{}:</b>" \
"\n#SET_WELCOME" \
"\n<b>Admin:</b> {}" \
"\nSet a welcome message.".format(html.escape(chat.title),
mention_html(user.id, user.first_name))