本文整理汇总了Python中telegram.Update方法的典型用法代码示例。如果您正苦于以下问题:Python telegram.Update方法的具体用法?Python telegram.Update怎么用?Python telegram.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram
的用法示例。
在下文中一共展示了telegram.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forward_faq
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [as 别名]
def forward_faq(update: Update, context: CallbackContext):
if update.message.chat.username not in [ONTOPIC_USERNAME, OFFTOPIC_USERNAME]:
return
admins = context.bot.get_chat_administrators(ONTOPIC_USERNAME)
if update.effective_user.id not in [x.user.id for x in admins]:
return
if not update.message:
return
reply_to = update.message.reply_to_message
if not reply_to:
return
try:
update.message.delete()
except BadRequest:
pass
# Forward message to FAQ channel
reply_to.forward(const.FAQ_CHANNEL_ID, disable_notification=True)
示例2: disable
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [as 别名]
def disable(bot: Bot, update: Update, args: List[str]):
chat = update.effective_chat # type: Optional[Chat]
if len(args) >= 1:
disable_cmd = args[0]
if disable_cmd.startswith(CMD_STARTERS):
disable_cmd = disable_cmd[1:]
if disable_cmd in set(DISABLE_CMDS + DISABLE_OTHER):
sql.disable_command(chat.id, disable_cmd)
update.effective_message.reply_text("Disabled the use of `{}`".format(disable_cmd),
parse_mode=ParseMode.MARKDOWN)
else:
update.effective_message.reply_text("That command can't be disabled")
else:
update.effective_message.reply_text("What should I disable?")
示例3: get_help
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [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)
示例4: get_settings
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [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)
示例5: migrate_chats
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [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
示例6: log_user
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [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)
示例7: gbanlist
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [as 别名]
def gbanlist(bot: Bot, update: Update):
banned_users = sql.get_gban_list()
if not banned_users:
update.effective_message.reply_text("There aren't any gbanned users! You're kinder than I expected...")
return
banfile = 'Screw these guys.\n'
for user in banned_users:
banfile += "[x] {} - {}\n".format(user["name"], user["user_id"])
if user["reason"]:
banfile += "Reason: {}\n".format(user["reason"])
with BytesIO(str.encode(banfile)) as output:
output.name = "gbanlist.txt"
update.effective_message.reply_document(document=output, filename="gbanlist.txt",
caption="Here is the list of currently gbanned users.")
示例8: enforce_gban
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [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)
示例9: gbanstat
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [as 别名]
def gbanstat(bot: Bot, update: Update, args: List[str]):
if len(args) > 0:
if args[0].lower() in ["on", "yes"]:
sql.enable_gbans(update.effective_chat.id)
update.effective_message.reply_text("I've enabled gbans in this group. This will help protect you "
"from spammers, unsavoury characters, and the biggest trolls.")
elif args[0].lower() in ["off", "no"]:
sql.disable_gbans(update.effective_chat.id)
update.effective_message.reply_text("I've disabled gbans in this group. GBans wont affect your users "
"anymore. You'll be less protected from any trolls and spammers "
"though!")
else:
update.effective_message.reply_text("Give me some arguments to choose a setting! on/off, yes/no!\n\n"
"Your current setting is: {}\n"
"When True, any gbans that happen will also happen in your group. "
"When False, they won't, leaving you at the possible mercy of "
"spammers.".format(sql.does_chat_gban(update.effective_chat.id)))
示例10: blacklist
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [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)
示例11: add_blacklist
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [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.")
示例12: gmutelist
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [as 别名]
def gmutelist(bot: Bot, update: Update):
muted_users = sql.get_gmute_list()
if not muted_users:
update.effective_message.reply_text("There aren't any gmuted users! You're kinder than I expected...")
return
mutefile = 'Screw these guys.\n'
for user in muted_users:
mutefile += "[x] {} - {}\n".format(user["name"], user["user_id"])
if user["reason"]:
mutefile += "Reason: {}\n".format(user["reason"])
with BytesIO(str.encode(mutefile)) as output:
output.name = "gmutelist.txt"
update.effective_message.reply_document(document=output, filename="gmutelist.txt",
caption="Here is the list of currently gmuted users.")
示例13: enforce_gmute
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [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)
示例14: list_handlers
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [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
示例15: stop_filter
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import Update [as 别名]
def stop_filter(bot: Bot, update: Update):
chat = update.effective_chat # type: Optional[Chat]
args = update.effective_message.text.split(None, 1)
if len(args) < 2:
return
chat_filters = sql.get_chat_triggers(chat.id)
if not chat_filters:
update.effective_message.reply_text("No filters are active here!")
return
for keyword in chat_filters:
if keyword == args[1]:
sql.remove_filter(chat.id, args[1])
update.effective_message.reply_text("Yep, I'll stop replying to that.")
raise DispatcherHandlerStop
update.effective_message.reply_text("That's not a current filter - run /filters for all active filters.")