| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- """
- MIT License
- Copyright (c) 2024 TheHamkerCat
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- """
- from pyrogram import filters
- from wbb import app
- from wbb.core.decorators.errors import capture_err
- from wbb.core.decorators.permissions import adminsOnly
- from wbb.services.blacklist_enforcement import (
- add_risk_keyword,
- enforce_risk_message,
- get_effective_risk_rules,
- remove_risk_keyword,
- risk_rule_keywords,
- )
- from wbb.services.external_risk_rules import enforce_external
- from wbb.utils.filter_groups import blacklist_filters_group
- __MODULE__ = "黑名单"
- __HELP__ = """
- /blacklisted - 查看本群全部黑名单关键词。
- /blacklist [词语或句子] - 添加黑名单关键词。
- /whitelist [词语或句子] - 移除黑名单关键词。
- """
- @app.on_message(filters.command("blacklist") & ~filters.private)
- @adminsOnly("can_restrict_members")
- async def save_filters(_, message):
- if len(message.command) < 2:
- return await message.reply_text("用法:\n/blacklist [词语或句子]")
- word = message.text.split(None, 1)[1].strip()
- if not word:
- return await message.reply_text(
- "**用法**\n__/blacklist [词语或句子]__"
- )
- chat_id = message.chat.id
- changed, _ = await add_risk_keyword(chat_id, word)
- if changed:
- return await message.reply_text(f"__**已将“{word}”加入风控关键词。**__")
- await message.reply_text("**该关键词已存在。**")
- @app.on_message(filters.command("blacklisted") & ~filters.private)
- @capture_err
- async def get_filterss(_, message):
- data = risk_rule_keywords(
- await get_effective_risk_rules(message.chat.id), enabled_only=True
- )
- if not data:
- await message.reply_text("**本群没有黑名单关键词。**")
- else:
- msg = f"{message.chat.title} 的风控关键词:\n"
- for word in data:
- msg += f"**-** `{word}`\n"
- await message.reply_text(msg)
- @app.on_message(filters.command("whitelist") & ~filters.private)
- @adminsOnly("can_restrict_members")
- async def del_filter(_, message):
- if len(message.command) < 2:
- return await message.reply_text("用法:\n/whitelist [词语或句子]")
- word = message.text.split(None, 1)[1].strip()
- if not word:
- return await message.reply_text("用法:\n/whitelist [词语或句子]")
- chat_id = message.chat.id
- deleted, _ = await remove_risk_keyword(chat_id, word)
- if deleted:
- return await message.reply_text(f"**已将“{word}”移出黑名单。**")
- await message.reply_text("**未找到该黑名单关键词。**")
- @app.on_message(
- (
- filters.text
- | filters.caption
- | filters.photo
- | filters.animation
- | filters.document
- )
- & ~filters.private,
- group=blacklist_filters_group,
- )
- @capture_err
- async def blacklist_filters_re(_, message):
- result = await enforce_risk_message(message)
- await enforce_external(message, already_deleted=bool(result and result.deleted))
|