本文整理汇总了Python中telegram.Chat方法的典型用法代码示例。如果您正苦于以下问题:Python telegram.Chat方法的具体用法?Python telegram.Chat怎么用?Python telegram.Chat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram
的用法示例。
在下文中一共展示了telegram.Chat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_help
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [as 别名]
def get_help(bot: Bot, update: Update):
chat = update.effective_chat # type: Optional[Chat]
args = update.effective_message.text.split(None, 1)
# ONLY send help in PM
if chat.type != chat.PRIVATE:
update.effective_message.reply_text("Contact me in PM to get the list of possible commands.",
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton(text="Help",
url="t.me/{}?start=help".format(
bot.username))]]))
return
elif len(args) >= 2 and any(args[1].lower() == x for x in HELPABLE):
module = args[1].lower()
text = "Here is the available help for the *{}* module:\n".format(HELPABLE[module].__mod_name__) \
+ HELPABLE[module].__help__
send_help(chat.id, text, InlineKeyboardMarkup([[InlineKeyboardButton(text="Back", callback_data="help_back")]]))
else:
send_help(chat.id, HELP_STRINGS)
示例2: get_settings
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [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)
示例3: donate
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [as 别名]
def donate(bot: Bot, update: Update):
user = update.effective_message.from_user
chat = update.effective_chat # type: Optional[Chat]
if chat.type == "private":
update.effective_message.reply_text(DONATE_STRING, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True)
if OWNER_ID != 254318997 and DONATION_LINK:
update.effective_message.reply_text("You can also donate to the person currently running me "
"[here]({})".format(DONATION_LINK),
parse_mode=ParseMode.MARKDOWN)
else:
try:
bot.send_message(user.id, DONATE_STRING, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True)
update.effective_message.reply_text("I've PM'ed you about donating to my creator!")
except Unauthorized:
update.effective_message.reply_text("Contact me in PM first to get donation information.")
示例4: log_user
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [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)
示例5: check_update
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [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
示例6: enforce_gban
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [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)
示例7: add_blacklist
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [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 Chat [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: enforce_gmute
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [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)
示例10: list_handlers
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [as 别名]
def list_handlers(bot: Bot, update: Update):
chat = update.effective_chat # type: Optional[Chat]
all_handlers = sql.get_chat_triggers(chat.id)
if not all_handlers:
update.effective_message.reply_text("No filters are active here!")
return
filter_list = BASIC_FILTER_STRING
for keyword in all_handlers:
entry = " - {}\n".format(escape_markdown(keyword))
if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH:
update.effective_message.reply_text(filter_list, parse_mode=telegram.ParseMode.MARKDOWN)
filter_list = entry
else:
filter_list += entry
if not filter_list == BASIC_FILTER_STRING:
update.effective_message.reply_text(filter_list, parse_mode=telegram.ParseMode.MARKDOWN)
# NOT ASYNC BECAUSE DISPATCHER HANDLER RAISED
示例11: set_welcome
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [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))
示例12: set_goodbye
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [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))
示例13: del_message
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [as 别名]
def del_message(bot: Bot, update: Update) -> str:
if update.effective_message.reply_to_message:
user = update.effective_user # type: Optional[User]
chat = update.effective_chat # type: Optional[Chat]
if can_delete(chat, bot.id):
update.effective_message.reply_to_message.delete()
update.effective_message.delete()
return "<b>{}:</b>" \
"\n#DEL" \
"\n<b>Admin:</b> {}" \
"\nMessage deleted.".format(html.escape(chat.title),
mention_html(user.id, user.first_name))
else:
update.effective_message.reply_text("Whadya want to delete?")
return ""
示例14: list_warn_filters
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [as 别名]
def list_warn_filters(bot: Bot, update: Update):
chat = update.effective_chat # type: Optional[Chat]
all_handlers = sql.get_chat_warn_triggers(chat.id)
if not all_handlers:
update.effective_message.reply_text("No warning filters are active here!")
return
filter_list = CURRENT_WARNING_FILTER_STRING
for keyword in all_handlers:
entry = " - {}\n".format(html.escape(keyword))
if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH:
update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML)
filter_list = entry
else:
filter_list += entry
if not filter_list == CURRENT_WARNING_FILTER_STRING:
update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML)
示例15: reply_filter
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Chat [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 ""