Skip to content

Commit

Permalink
向 log 频道中添加详细信息
Browse files Browse the repository at this point in the history
  • Loading branch information
NimaQu committed Dec 19, 2021
1 parent b8f8893 commit 07bc6d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 64 deletions.
40 changes: 0 additions & 40 deletions challenge_test.py

This file was deleted.

60 changes: 36 additions & 24 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

from pyrogram import (Client, filters)
from pyrogram.errors import ChatAdminRequired, ChannelPrivate, MessageNotModified
from pyrogram.types import (InlineKeyboardMarkup, InlineKeyboardButton, User, Message, ChatPermissions, CallbackQuery, ChatMemberUpdated)
from pyrogram.types import (InlineKeyboardMarkup, InlineKeyboardButton, User, Message, ChatPermissions, CallbackQuery,
ChatMemberUpdated)

from Timer import Timer
from challenge import Challenge
Expand Down Expand Up @@ -115,7 +116,8 @@ async def challenge_user(client: Client, message: ChatMemberUpdated):
chat_id = message.chat.id
current_time = int(time.time())
last_try = db.get_last_try(target.id)
if db.get_user_status(target.id) == 1 and (current_time - last_try) > group_config["global_timeout_user_blacklist_remove"]:
if db.get_user_status(target.id) == 1 and (current_time - last_try) > group_config[
"global_timeout_user_blacklist_remove"]:
await client.kick_chat_member(chat_id, target.id)
await client.unban_chat_member(chat_id, target.id)
db.update_last_try(current_time, target.id)
Expand Down Expand Up @@ -181,12 +183,9 @@ def generate_challenge_button(e):
generate_challenge_button(challenge)),
)
_me: User = await client.get_me()
chat_id = message.chat.id
chat_title = message.chat.title
target = message.from_user.id
timeout_event = Timer(
challenge_timeout(client, message.chat.id, message.from_user.id,
reply_message.message_id),
# challenge_timeout(client, message.chat.id, message.from_user.id, reply_message.message_id),
challenge_timeout(client, message, reply_message.message_id),
timeout=group_config["challenge_timeout"],
)
_cch_lock.acquire()
Expand All @@ -205,7 +204,9 @@ async def challenge_callback(client: Client,
user_id = callback_query.from_user.id
msg_id = callback_query.message.message_id
chat_title = callback_query.message.chat.title
user_name = callback_query.from_user.first_name
user_username = callback_query.from_user.username
user_first_name = callback_query.from_user.first_name
user_last_name = callback_query.from_user.last_name
group_config = _config.get(str(chat_id), _config["*"])
if query_data in ["+", "-"]:
admins = await client.get_chat_members(chat_id,
Expand All @@ -223,7 +224,7 @@ async def challenge_callback(client: Client,
_cch_lock.acquire()
# target: int = None
timeout_event: None
challenge, target, timeout_event = _current_challenges.get(
challenge, target_id, timeout_event = _current_challenges.get(
ch_id, (None, None, None))
if ch_id in _current_challenges:
# 预防异常
Expand All @@ -234,7 +235,7 @@ async def challenge_callback(client: Client,
try:
await client.restrict_chat_member(
chat_id,
target,
target_id,
permissions=ChatPermissions(
can_send_messages=True,
can_send_media_messages=True,
Expand All @@ -255,7 +256,7 @@ async def challenge_callback(client: Client,
await client.edit_message_text(
chat_id,
msg_id,
group_config["msg_approved"].format(user=user_name),
group_config["msg_approved"].format(user=user_first_name),
reply_markup=None,
)
_me: User = await client.get_me()
Expand All @@ -264,7 +265,7 @@ async def challenge_callback(client: Client,
int(_channel),
_config["msg_passed_admin"].format(
botid=str(_me.id),
targetuser=str(target),
targetuserid=str(target_id),
groupid=str(chat_id),
grouptitle=str(chat_title),
),
Expand All @@ -274,15 +275,15 @@ async def challenge_callback(client: Client,
logging.error(str(e))
else:
try:
await client.kick_chat_member(chat_id, target)
await client.kick_chat_member(chat_id, target_id)
except ChatAdminRequired:
await client.answer_callback_query(
query_id, group_config["msg_bot_no_permission"])
return
await client.edit_message_text(
chat_id,
msg_id,
group_config["msg_refused"].format(user=user_name),
group_config["msg_refused"].format(user=user_first_name),
reply_markup=None,
)
_me: User = await client.get_me()
Expand All @@ -291,7 +292,7 @@ async def challenge_callback(client: Client,
int(_channel),
_config["msg_failed_admin"].format(
botid=str(_me.id),
targetuser=str(target),
targetuserid=str(target_id),
groupid=str(chat_id),
grouptitle=str(chat_title),
),
Expand All @@ -304,18 +305,18 @@ async def challenge_callback(client: Client,

ch_id = "{chat}|{msg}".format(chat=chat_id, msg=msg_id)
_cch_lock.acquire()
challenge, target, timeout_event = _current_challenges.get(
challenge, target_id, timeout_event = _current_challenges.get(
ch_id, (None, None, None))
_cch_lock.release()
if user_id != target:
if user_id != target_id:
await client.answer_callback_query(
query_id, group_config["msg_challenge_not_for_you"])
return None
timeout_event.stop()
try:
await client.restrict_chat_member(
chat_id,
target,
target_id,
permissions=ChatPermissions(
can_send_messages=True,
can_send_media_messages=True,
Expand Down Expand Up @@ -348,7 +349,7 @@ async def challenge_callback(client: Client,
int(_channel),
_config["msg_passed_answer"].format(
botid=str(_me.id),
targetuser=str(target),
targetuserid=str(target_id),
groupid=str(chat_id),
grouptitle=str(chat_title),
),
Expand All @@ -370,7 +371,7 @@ async def challenge_callback(client: Client,
int(_channel),
_config["msg_passed_mercy"].format(
botid=str(_me.id),
targetuser=str(target),
targetuserid=str(target_id),
groupid=str(chat_id),
grouptitle=str(chat_title),
),
Expand All @@ -393,7 +394,7 @@ async def challenge_callback(client: Client,
int(_channel),
_config["msg_failed_answer"].format(
botid=str(_me.id),
targetuser=str(target),
targetuserid=str(target_id),
groupid=str(chat_id),
grouptitle=str(chat_title),
),
Expand Down Expand Up @@ -429,8 +430,14 @@ async def challenge_callback(client: Client,
group_config["delete_passed_challenge_interval"],
)

async def challenge_timeout(client: Client, chat_id, from_id, reply_id):
async def challenge_timeout(client: Client, message, reply_id):
global _current_challenges
chat_id = message.chat.id
from_id = message.from_user.id
chat_title = message.chat.title
user_username = message.from_user.username
user_first_name = message.from_user.first_name
user_last_name = message.from_user.last_name
_me: User = await client.get_me()
group_config = _config.get(str(chat_id), _config["*"])

Expand All @@ -450,8 +457,13 @@ async def challenge_timeout(client: Client, chat_id, from_id, reply_id):
await client.send_message(chat_id=_channel,
text=_config["msg_failed_timeout"].format(
botid=str(_me.id),
targetuser=str(from_id),
groupid=str(chat_id)))
targetuserid=str(from_id),
targetusername=str(user_username),
targetfirstname=str(user_first_name),
targetlastname=str(user_last_name),
groupid=str(chat_id),
grouptitle=str(chat_title)
))

if group_config["challenge_timeout_action"] == "ban":
await client.kick_chat_member(chat_id, from_id)
Expand Down

0 comments on commit 07bc6d8

Please sign in to comment.