mirror of
https://github.com/Xtao-Labs/sticker-captcha-bot.git
synced 2024-11-21 06:47:04 +00:00
support log
This commit is contained in:
parent
b206b3227a
commit
ed4e63d678
@ -7,6 +7,7 @@ bot_token: "TOKEN_HERE"
|
||||
|
||||
# Either debug logging is enabled or not
|
||||
debug: "False"
|
||||
log_channel: "0"
|
||||
|
||||
# socks5
|
||||
proxy_addr: ""
|
||||
|
@ -3,9 +3,9 @@ import contextlib
|
||||
from pyrogram.types import ChatMemberUpdated
|
||||
|
||||
from sticker.single_utils import Client
|
||||
from sticker import bot
|
||||
from sticker import bot, log
|
||||
|
||||
MSG_PUBLIC = """您好,我发现此群组为公开群组,您需要联系创建者打开 `管理员批准后才能入群` 功能,我才能正常工作。"""
|
||||
MSG_PUBLIC = """您好,我发现此群组为公开群组,您需要联系创建者打开 `管理员批准后才能入群` 功能,我就能更好地工作。"""
|
||||
MSG_SUCCESS = """验证成功,您已经成为群组的一员了!"""
|
||||
MSG_FAILURE = """验证失败,请重试。"""
|
||||
|
||||
@ -14,6 +14,9 @@ MSG_FAILURE = """验证失败,请重试。"""
|
||||
async def invite(client: Client, chat_member_updated: ChatMemberUpdated):
|
||||
chat = chat_member_updated.chat
|
||||
if user := chat_member_updated.new_chat_member:
|
||||
if user.user.is_self:
|
||||
with contextlib.suppress(Exception):
|
||||
await log(chat, user.invited_by, "NEW_GROUP")
|
||||
if user.user.is_self and chat.username:
|
||||
with contextlib.suppress(Exception):
|
||||
await client.send_message(chat.id, MSG_PUBLIC)
|
||||
|
@ -4,7 +4,7 @@ from pyrogram.types import ChatJoinRequest
|
||||
from pyrogram import filters
|
||||
|
||||
from sticker.single_utils import Client
|
||||
from sticker import bot
|
||||
from sticker import bot, log
|
||||
|
||||
from pyromod.utils.errors import TimeoutConversationError
|
||||
|
||||
@ -25,7 +25,11 @@ async def new_member(client: Client, chat_join_request: ChatJoinRequest):
|
||||
with contextlib.suppress(Exception):
|
||||
await client.send_message(user.id, MSG_SUCCESS)
|
||||
await chat_join_request.approve()
|
||||
with contextlib.suppress(Exception):
|
||||
await log(chat, user, "ACCEPT")
|
||||
except TimeoutConversationError:
|
||||
with contextlib.suppress(Exception):
|
||||
await client.send_message(user.id, MSG_FAILURE)
|
||||
await chat_join_request.decline()
|
||||
with contextlib.suppress(Exception):
|
||||
await log(chat, user, "FAIL_TIMEOUT")
|
||||
|
@ -6,7 +6,7 @@ from pyrogram.enums import MessageServiceType
|
||||
from pyrogram import filters
|
||||
|
||||
from sticker.single_utils import Client, Message
|
||||
from sticker import bot
|
||||
from sticker import bot, log
|
||||
|
||||
from pyromod.utils.errors import TimeoutConversationError
|
||||
|
||||
@ -25,7 +25,10 @@ async def chat_members_handle(client: Client, message: Message):
|
||||
return
|
||||
try:
|
||||
msg = await message.reply(MSG % user.mention)
|
||||
msg_ = await client.listen(message.chat, filters=filters.user(user.id), timeout=30)
|
||||
except Exception as e:
|
||||
return
|
||||
try:
|
||||
msg_ = await client.listen(chat.id, filters=filters.user(user.id), timeout=30)
|
||||
with contextlib.suppress(Exception):
|
||||
await msg.delete()
|
||||
if not msg_.sticker:
|
||||
@ -33,8 +36,18 @@ async def chat_members_handle(client: Client, message: Message):
|
||||
await message.delete()
|
||||
with contextlib.suppress(Exception):
|
||||
await bot.ban_chat_member(chat.id, user.id, datetime.now() + timedelta(minutes=5))
|
||||
with contextlib.suppress(Exception):
|
||||
await log(chat, user, "FAIL_ERROR")
|
||||
with contextlib.suppress(Exception):
|
||||
await msg_.delete()
|
||||
with contextlib.suppress(Exception):
|
||||
await log(chat, user, "ACCEPT")
|
||||
except TimeoutConversationError:
|
||||
with contextlib.suppress(Exception):
|
||||
await msg.delete()
|
||||
with contextlib.suppress(Exception):
|
||||
await message.delete()
|
||||
with contextlib.suppress(Exception):
|
||||
await bot.ban_chat_member(chat.id, user.id, datetime.now() + timedelta(minutes=5))
|
||||
with contextlib.suppress(Exception):
|
||||
await log(chat, user, "FAIL_TIMEOUT")
|
||||
|
@ -46,3 +46,18 @@ bot = Client("sticker",
|
||||
ipv6=Config.IPV6,
|
||||
proxy=Config.PROXY,
|
||||
plugins={"root": "plugins"})
|
||||
|
||||
|
||||
async def log(chat, user, action):
|
||||
if not Config.LOG_CHANNEL:
|
||||
return
|
||||
me = await bot.get_me()
|
||||
event = {"FAIL_ERROR": "回答错误", "FAIL_TIMEOUT": "回答超时", "ACCEPT": "通过验证", "NEW_GROUP": "加入群组"}
|
||||
msg = """#%s
|
||||
群组: %s
|
||||
群组id: <code>%s</code>
|
||||
用户: #id%s
|
||||
OPBot: #bot%s
|
||||
事件: %s"""
|
||||
msg %= (action, chat.title, chat.id, user.id if user else "", me.id, event[action])
|
||||
await bot.send_message(Config.LOG_CHANNEL, msg)
|
||||
|
@ -34,6 +34,7 @@ class Config:
|
||||
API_ID = int(os.environ.get("API_ID", config["api_id"]))
|
||||
API_HASH = os.environ.get("API_HASH", config["api_hash"])
|
||||
BOT_TOKEN = os.environ.get("BOT_TOKEN", config["bot_token"])
|
||||
LOG_CHANNEL = int(os.environ.get("LOG_CHANNEL", config["log_channel"]))
|
||||
STRING_SESSION = os.environ.get("STRING_SESSION")
|
||||
DEBUG = strtobool(os.environ.get("PGM_DEBUG", config["debug"]))
|
||||
IPV6 = strtobool(os.environ.get("PGM_IPV6", config["ipv6"]))
|
||||
|
Loading…
Reference in New Issue
Block a user