本文整理匯總了Python中telegram.ext.Filters.private方法的典型用法代碼示例。如果您正苦於以下問題:Python Filters.private方法的具體用法?Python Filters.private怎麽用?Python Filters.private使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類telegram.ext.Filters
的用法示例。
在下文中一共展示了Filters.private方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: gps
# 需要導入模塊: from telegram.ext import Filters [as 別名]
# 或者: from telegram.ext.Filters import private [as 別名]
def gps(bot: Bot, update: Update, args: List[str]):
message = update.effective_message
try:
geolocator = Nominatim(user_agent="SkittBot")
location = " ".join(args)
geoloc = geolocator.geocode(location)
chat_id = update.effective_chat.id
lon = geoloc.longitude
lat = geoloc.latitude
the_loc = Location(lon, lat)
gm = "https://www.google.com/maps/search/{},{}".format(lat,lon)
bot.send_location(chat_id, location=the_loc)
message.reply_text("Open with: [Google Maps]({})".format(gm), parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True)
except AttributeError:
message.reply_text("I can't find that")
# /ip is for private use
示例2: getsticker
# 需要導入模塊: from telegram.ext import Filters [as 別名]
# 或者: from telegram.ext.Filters import private [as 別名]
def getsticker(bot: Bot, update: Update):
msg = update.effective_message
chat_id = update.effective_chat.id
if msg.reply_to_message and msg.reply_to_message.sticker:
bot.sendChatAction(chat_id, "typing")
update.effective_message.reply_text("Hello " + "[{}](tg://user?id={})".format(msg.from_user.first_name,
msg.from_user.id) + ", Please check the file you requested below."
"\nPlease use this feature wisely!",
parse_mode=ParseMode.MARKDOWN)
bot.sendChatAction(chat_id, "upload_document")
file_id = msg.reply_to_message.sticker.file_id
newFile = bot.get_file(file_id)
newFile.download('sticker.png')
bot.sendDocument(chat_id, document=open('sticker.png', 'rb'))
bot.sendChatAction(chat_id, "upload_photo")
bot.send_photo(chat_id, photo=open('sticker.png', 'rb'))
else:
bot.sendChatAction(chat_id, "typing")
update.effective_message.reply_text("Hello " + "[{}](tg://user?id={})".format(msg.from_user.first_name,
msg.from_user.id) + ", Please reply to sticker message to get sticker image",
parse_mode=ParseMode.MARKDOWN)
# /ip is for private use
示例3: get_id
# 需要導入模塊: from telegram.ext import Filters [as 別名]
# 或者: from telegram.ext.Filters import private [as 別名]
def get_id(bot: Bot, update: Update, args: List[str]):
user_id = extract_user(update.effective_message, args)
if user_id:
if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from:
user1 = update.effective_message.reply_to_message.from_user
user2 = update.effective_message.reply_to_message.forward_from
update.effective_message.reply_text(
"The original sender, {}, has an ID of `{}`.\nThe forwarder, {}, has an ID of `{}`.".format(
escape_markdown(user2.first_name),
user2.id,
escape_markdown(user1.first_name),
user1.id),
parse_mode=ParseMode.MARKDOWN)
else:
user = bot.get_chat(user_id)
update.effective_message.reply_text("{}'s id is `{}`.".format(escape_markdown(user.first_name), user.id),
parse_mode=ParseMode.MARKDOWN)
else:
chat = update.effective_chat # type: Optional[Chat]
if chat.type == "private":
update.effective_message.reply_text("Your id is `{}`.".format(chat.id),
parse_mode=ParseMode.MARKDOWN)
else:
update.effective_message.reply_text("This group's id is `{}`.".format(chat.id),
parse_mode=ParseMode.MARKDOWN)
示例4: stats
# 需要導入模塊: from telegram.ext import Filters [as 別名]
# 或者: from telegram.ext.Filters import private [as 別名]
def stats(update, context):
send_message(update.effective_message, tl(update.effective_message, "Statistik saat ini:\n") + "\n".join([mod.__stats__() for mod in STATS]))
# /ip is for private use
示例5: stats
# 需要導入模塊: from telegram.ext import Filters [as 別名]
# 或者: from telegram.ext.Filters import private [as 別名]
def stats(bot: Bot, update: Update):
update.effective_message.reply_text("Current stats:\n" + "\n".join([mod.__stats__() for mod in STATS]))
# /ip is for private use
示例6: check_channel_message
# 需要導入模塊: from telegram.ext import Filters [as 別名]
# 或者: from telegram.ext.Filters import private [as 別名]
def check_channel_message(bot, message):
logger = Logger.logger
chat_id = message.chat_id
if not message.forward_from_chat:
helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_invalid", "register_cmd_invalid")
return
chat_type = message.forward_from_chat.type
if not chat_type == "channel":
helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_invalid", "register_cmd_invalid")
return
channel_username = message.forward_from_chat.username
channel_id = message.forward_from_chat.id
user_id = message.from_user.id
logger.msg({
"user_id": chat_id,
"channel_id": channel_id,
"action": "check channel"
}, tag="private", log_level=90)
bot_id = int(helper_const.BOT_TOKEN.split(":")[0])
try:
chat_members = bot.get_chat_administrators(chat_id=channel_id).result()
chat_member_ids = [member.user.id for member in chat_members]
if not user_id in chat_member_ids:
helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_not_admin", "register_cmd_not_admin")
return
for member in chat_members:
if member.user.id == bot_id:
post_permission = member.can_post_messages if member.can_post_messages else False
edit_permission = member.can_edit_messages if member.can_edit_messages else False
delete_permission = member.can_delete_messages if member.can_delete_messages else False
if not post_permission or not edit_permission or not delete_permission:
helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_no_permission", "register_cmd_no_permission")
return
break
except:
helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_no_info", "register_cmd_no_info")
return
try:
helper_database.add_channel_config(channel_id, helper_const.DEFAULT_LANG, 1, 10, channel_username, chat_id, 1, 1)
except:
helper_global.assign(str(chat_id) + "_status", "0,0")
helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_failed", "register_cmd_failed")
return
helper_global.assign(str(chat_id) + "_status", "0,0")
helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_success", "register_cmd_success")
示例7: get_id
# 需要導入模塊: from telegram.ext import Filters [as 別名]
# 或者: from telegram.ext.Filters import private [as 別名]
def get_id(update, context):
args = context.args
user_id = extract_user(update.effective_message, args)
if user_id and user_id != "error":
if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from:
user1 = update.effective_message.reply_to_message.from_user
user2 = update.effective_message.reply_to_message.forward_from
text = tl(update.effective_message, "Pengirim asli, {}, memiliki ID `{}`.\nSi penerus pesan, {}, memiliki ID `{}`.").format(
escape_markdown(user2.first_name),
user2.id,
escape_markdown(user1.first_name),
user1.id)
if update.effective_message.chat.type != "private":
text += "\n" + tl(update.effective_message, "Id grup ini adalah `{}`.").format(update.effective_message.chat.id)
send_message(update.effective_message,
text,
parse_mode=ParseMode.MARKDOWN)
else:
user = context.bot.get_chat(user_id)
text = tl(update.effective_message, "Id {} adalah `{}`.").format(escape_markdown(user.first_name), user.id)
if update.effective_message.chat.type != "private":
text += "\n" + tl(update.effective_message, "Id grup ini adalah `{}`.").format(update.effective_message.chat.id)
send_message(update.effective_message, text,
parse_mode=ParseMode.MARKDOWN)
elif user_id == "error":
try:
user = context.bot.get_chat(args[0])
except BadRequest:
send_message(update.effective_message, "Error: Unknown User/Chat!")
return
text = tl(update.effective_message, "Id Anda adalah `{}`.").format(update.effective_message.from_user.id)
text += "\n" + tl(update.effective_message, "Id grup tersebut adalah `{}`.").format(user.id)
if update.effective_message.chat.type != "private":
text += "\n" + tl(update.effective_message, "Id grup ini adalah `{}`.").format(update.effective_message.chat.id)
send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN)
else:
chat = update.effective_chat # type: Optional[Chat]
if chat.type == "private":
send_message(update.effective_message, tl(update.effective_message, "Id Anda adalah `{}`.").format(update.effective_message.from_user.id),
parse_mode=ParseMode.MARKDOWN)
else:
send_message(update.effective_message, tl(update.effective_message, "Id Anda adalah `{}`.").format(update.effective_message.from_user.id) + "\n" + tl(update.effective_message, "Id grup ini adalah `{}`.").format(chat.id),
parse_mode=ParseMode.MARKDOWN)