本文整理汇总了Python中telegram.ext.Filters.group方法的典型用法代码示例。如果您正苦于以下问题:Python Filters.group方法的具体用法?Python Filters.group怎么用?Python Filters.group使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram.ext.Filters
的用法示例。
在下文中一共展示了Filters.group方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gbanstat
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [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)))
示例2: log_incoming_messages
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def log_incoming_messages(_, update):
"""Log incoming messages to a log file and influxdb."""
frontend_logger.debug('incoming messages: %s' % update)
chat = update.message.chat
target_chat = ''
if chat.type == 'group':
target_chat = chat.title
elif chat.type == 'private':
if chat.first_name:
target_chat += chat.first_name
if chat.last_name:
target_chat += ' %s' % chat.last_name
if chat.username:
target_chat += ' (%s)' % chat.username
message_logger.info('In: %s: %s' % (target_chat, update.message.text))
fields = {'message': update.message.text}
tags = {'chat': target_chat}
log_to_influxdb.delay('messages', fields, tags)
示例3: cleanservice
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def cleanservice(update, context):
args = context.args
chat = update.effective_chat # type: Optional[Chat]
if chat.type != chat.PRIVATE:
if len(args) >= 1:
var = args[0].lower()
if (var == "no" or var == "off" or var == "tidak"):
sql.set_clean_service(chat.id, False)
send_message(update.effective_message, tl(update.effective_message, "Saya meninggalkan pesan layanan"))
elif(var == "yes" or var == "ya" or var == "on"):
sql.set_clean_service(chat.id, True)
send_message(update.effective_message, tl(update.effective_message, "Saya akan membersihkan pesan layanan"))
else:
send_message(update.effective_message, tl(update.effective_message, "Silakan masukkan yes/ya atau no/tidak!"), parse_mode=ParseMode.MARKDOWN)
else:
send_message(update.effective_message, tl(update.effective_message, "Silakan masukkan yes/ya atau no/tidak!"), parse_mode=ParseMode.MARKDOWN)
else:
curr = sql.clean_service(chat.id)
if curr:
send_message(update.effective_message, tl(update.effective_message, "Saat ini saya akan membersihkan `x joined the group` ketika ada member baru."), parse_mode=ParseMode.MARKDOWN)
else:
send_message(update.effective_message, tl(update.effective_message, "Saat ini saya tidak akan membersihkan `x joined the group` ketika ada member baru."), parse_mode=ParseMode.MARKDOWN)
示例4: _command_hook
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def _command_hook(self):
# noinspection PyUnusedLocal
def hook(update, context):
msg = update.effective_message
m = re.match('\s*/([0-9a-zA-Z_-]+)\s*(.*)', msg.text)
cmd = m.group(1).lower()
args = [arg for arg in re.split('\s+', m.group(2)) if len(arg)]
try:
self._authorize(msg)
self.bus.post(CommandMessageEvent(chat_id=update.effective_chat.id,
command=cmd,
cmdargs=args,
message=self._plugin.parse_msg(msg).output,
user=self._plugin.parse_user(update.effective_user).output))
except PermissionError:
pass
return hook
示例5: run
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def run(self):
# noinspection PyPackageRequirements
from telegram.ext import MessageHandler, Filters
super().run()
telegram = self._plugin.get_telegram()
dispatcher = telegram.dispatcher
dispatcher.add_handler(MessageHandler(Filters.group, self._group_hook()))
dispatcher.add_handler(MessageHandler(Filters.text, self._msg_hook(TextMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.photo, self._msg_hook(PhotoMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.video, self._msg_hook(VideoMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.contact, self._msg_hook(ContactMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.location, self._msg_hook(LocationMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.document, self._msg_hook(DocumentMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.command, self._command_hook()))
self.logger.info('Initialized Telegram backend')
telegram.start_polling()
# vim:sw=4:ts=4:et:
示例6: add_towel_mode
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def add_towel_mode(upd: Updater, handlers_group: int):
logger.info("registering towel-mode handlers")
dp = upd.dispatcher
# catch all new users and drop the towel
dp.add_handler(MessageHandler(Filters.status_update.new_chat_members, catch_new_user),
handlers_group)
# check for reply or remove messages
dp.add_handler(MessageHandler(
Filters.group & ~Filters.status_update, catch_reply),
handlers_group
)
# "i am a bot button"
dp.add_handler(CallbackQueryHandler(i_am_a_bot_btn), handlers_group)
# ban quarantine users, if time is gone
upd.job_queue.run_repeating(ban_user, interval=60, first=60, context={
"chat_id": get_config()["GROUP_CHAT_ID"]
})
示例7: gmutestat
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def gmutestat(bot: Bot, update: Update, args: List[str]):
if len(args) > 0:
if args[0].lower() in ["on", "yes"]:
sql.enable_gmutes(update.effective_chat.id)
update.effective_message.reply_text("I've enabled gmutes in this group. This will help protect you "
"from spammers, unsavoury characters, and Anirudh.")
elif args[0].lower() in ["off", "no"]:
sql.disable_gmutes(update.effective_chat.id)
update.effective_message.reply_text("I've disabled gmutes in this group. GMutes wont affect your users "
"anymore. You'll be less protected from Anirudh 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 gmutes 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_gmute(update.effective_chat.id)))
示例8: button
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def button(bot: Bot, update: Update) -> str:
query = update.callback_query # type: Optional[CallbackQuery]
user = update.effective_user # type: Optional[User]
match = re.match(r"rm_warn\((.+?)\)", query.data)
if match:
user_id = match.group(1)
chat = update.effective_chat # type: Optional[Chat]
res = sql.remove_warn(user_id, chat.id)
if res:
update.effective_message.edit_text(
"Warn removed by {}.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
user_member = chat.get_member(user_id)
return "<b>{}:</b>" \
"\n#UNWARN" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {}".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(user_member.user.id, user_member.user.first_name))
else:
update.effective_message.edit_text(
"User has already has no warns.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
return ""
示例9: broadcast
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def broadcast(bot: Bot, update: Update):
to_send = update.effective_message.text.split(None, 1)
if len(to_send) >= 2:
chats = sql.get_all_chats() or []
failed = 0
for chat in chats:
try:
bot.sendMessage(int(chat.chat_id), to_send[1])
sleep(0.1)
except TelegramError:
failed += 1
LOGGER.warning("Couldn't send broadcast to %s, group name %s", str(chat.chat_id), str(chat.chat_name))
update.effective_message.reply_text("Broadcast complete. {} groups failed to receive the message, probably "
"due to being kicked.".format(failed))
示例10: unban
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def unban(bot: Bot, update: Update, args: List[str]) -> str:
message = update.effective_message # type: Optional[Message]
user = update.effective_user # type: Optional[User]
chat = update.effective_chat # type: Optional[Chat]
user_id, reason = extract_user_and_text(message, args)
if not user_id:
return ""
try:
member = chat.get_member(user_id)
except BadRequest as excp:
if excp.message == "User not found":
message.reply_text("This user is ded mate.")
return ""
else:
raise
if user_id == bot.id:
message.reply_text("What exactly are you attempting to do?")
return ""
if is_user_in_chat(chat, user_id):
message.reply_text("Boi! this user is already in the group!")
return ""
chat.unban_member(user_id)
message.reply_text("Fine, I'll allow it, this time...")
log = "<b>{}:</b>" \
"\n#UNBANNED" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(member.user.id, member.user.first_name),
member.user.id)
if reason:
log += "\n<b>Reason:</b> {}".format(reason)
return log
示例11: send_rules
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def send_rules(update, chat_id, from_pm=False):
bot = dispatcher.bot
user = update.effective_user # type: Optional[User]
try:
chat = bot.get_chat(chat_id)
except BadRequest as excp:
if excp.message == "Chat not found" and from_pm:
bot.send_message(user.id, "The rules shortcut for this chat hasn't been set properly! Ask admins to "
"fix this.")
return
else:
raise
rules = sql.get_rules(chat_id)
text = "The rules for *{}* are:\n\n{}".format(escape_markdown(chat.title), rules)
if from_pm and rules:
bot.send_message(user.id, text, parse_mode=ParseMode.MARKDOWN)
elif from_pm:
bot.send_message(user.id, "The group admins haven't set any rules for this chat yet. "
"This probably doesn't mean it's lawless though...!")
elif rules:
update.effective_message.reply_text("Contact me in PM to get this group's rules.",
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton(text="Rules",
url="t.me/{}?start={}".format(bot.username,
chat_id))]]))
else:
update.effective_message.reply_text("The group admins haven't set any rules for this chat yet. "
"This probably doesn't mean it's lawless though...!")
示例12: set_rules
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def set_rules(bot: Bot, update: Update):
chat_id = update.effective_chat.id
msg = update.effective_message # type: Optional[Message]
raw_text = msg.text
args = raw_text.split(None, 1) # use python's maxsplit to separate cmd and args
if len(args) == 2:
txt = args[1]
offset = len(txt) - len(raw_text) # set correct offset relative to command
markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset)
sql.set_rules(chat_id, markdown_rules)
update.effective_message.reply_text("Successfully set rules for this group.")
示例13: welcome_help
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def welcome_help(bot: Bot, update: Update):
update.effective_message.reply_text(WELC_HELP_TXT, parse_mode=ParseMode.MARKDOWN)
# TODO: get welcome data from group butler snap
# def __import_data__(chat_id, data):
# welcome = data.get('info', {}).get('rules')
# welcome = welcome.replace('$username', '{username}')
# welcome = welcome.replace('$name', '{fullname}')
# welcome = welcome.replace('$id', '{id}')
# welcome = welcome.replace('$title', '{chatname}')
# welcome = welcome.replace('$surname', '{lastname}')
# welcome = welcome.replace('$rules', '{rules}')
# sql.set_custom_welcome(chat_id, welcome, sql.Types.TEXT)
示例14: button
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def button(bot: Bot, update: Update) -> str:
query = update.callback_query # type: Optional[CallbackQuery]
user = update.effective_user # type: Optional[User]
match = re.match(r"rm_warn\((.+?)\)", query.data)
if match:
user_id = match.group(1)
chat = update.effective_chat # type: Optional[Chat]
res = sql.remove_warn(user_id, chat.id)
if res:
update.effective_message.edit_text(
"Warn removed by {}.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
user_member = chat.get_member(user_id)
return "<b>{}:</b>" \
"\n#UNWARN" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(user_member.user.id, user_member.user.first_name),
user_member.user.id)
else:
update.effective_message.edit_text(
"User has already has no warns.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
return ""
示例15: check_flood
# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import group [as 别名]
def check_flood(bot: Bot, update: Update) -> str:
user = update.effective_user # type: Optional[User]
chat = update.effective_chat # type: Optional[Chat]
msg = update.effective_message # type: Optional[Message]
if not user: # ignore channels
return ""
# ignore admins
if is_user_admin(chat, user.id):
sql.update_flood(chat.id, None)
return ""
should_ban = sql.update_flood(chat.id, user.id)
if not should_ban:
return ""
try:
chat.kick_member(user.id)
msg.reply_text("I like to leave the flooding to natural disasters. But you, you were just a "
"disappointment. Get out.")
return "<b>{}:</b>" \
"\n#BANNED" \
"\n<b>User:</b> {}" \
"\nFlooded the group.".format(html.escape(chat.title),
mention_html(user.id, user.first_name))
except BadRequest:
msg.reply_text("I can't kick people here, give me permissions first! Until then, I'll disable antiflood.")
sql.set_flood(chat.id, 0)
return "<b>{}:</b>" \
"\n#INFO" \
"\nDon't have kick permissions, so automatically disabled antiflood.".format(chat.title)