This commit is contained in:
yasirarism 2023-04-16 11:54:32 +07:00 committed by GitHub
parent 4202ab631e
commit a153514c41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,9 +39,9 @@ Just type something in group to remove AFK Status."""
@ratelimiter @ratelimiter
@use_chat_lang() @use_chat_lang()
async def active_afk(self: Client, ctx: Message, strings): async def active_afk(self: Client, ctx: Message, strings):
if message.sender_chat: if ctx.sender_chat:
return await ctx.reply_msg(strings("no_channel"), del_in=6) return await ctx.reply_msg(strings("no_channel"), del_in=6)
user_id = message.from_user.id user_id = ctx.from_user.id
verifier, reasondb = await is_afk(user_id) verifier, reasondb = await is_afk(user_id)
if verifier: if verifier:
await remove_afk(user_id) await remove_afk(user_id)
@ -53,96 +53,96 @@ async def active_afk(self: Client, ctx: Message, strings):
seenago = get_readable_time2((int(time.time() - timeafk))) seenago = get_readable_time2((int(time.time() - timeafk)))
if afktype == "animation": if afktype == "animation":
send = ( send = (
await message.reply_animation( await ctx.reply_animation(
data, data,
caption=strings("on_afk_msg_no_r").format(usr=message.from_user.mention, id=message.from_user.id, tm=seenago), caption=strings("on_afk_msg_no_r").format(usr=ctx.from_user.mention, id=ctx.from_user.id, tm=seenago),
) )
if str(reasonafk) == "None" if str(reasonafk) == "None"
else await message.reply_animation( else await ctx.reply_animation(
data, data,
caption=strings("on_afk_msg_with_r").format(usr=message.from_user.mention, id=message.from_user.id, tm=seenago, reas=reasonafk), caption=strings("on_afk_msg_with_r").format(usr=ctx.from_user.mention, id=ctx.from_user.id, tm=seenago, reas=reasonafk),
) )
) )
elif afktype == "photo": elif afktype == "photo":
send = ( send = (
await message.reply_photo( await ctx.reply_photo(
photo=f"downloads/{user_id}.jpg", photo=f"downloads/{user_id}.jpg",
caption=strings("on_afk_msg_no_r").format(usr=message.from_user.mention, id=message.from_user.id, tm=seenago), caption=strings("on_afk_msg_no_r").format(usr=ctx.from_user.mention, id=ctx.from_user.id, tm=seenago),
) )
if str(reasonafk) == "None" if str(reasonafk) == "None"
else await message.reply_photo( else await ctx.reply_photo(
photo=f"downloads/{user_id}.jpg", photo=f"downloads/{user_id}.jpg",
caption=strings("on_afk_msg_with_r").format(usr=message.from_user.first_name, tm=seenago, reas=reasonafk), caption=strings("on_afk_msg_with_r").format(usr=ctx.from_user.first_name, tm=seenago, reas=reasonafk),
) )
) )
elif afktype == "text": elif afktype == "text":
send = await message.reply_text( send = await ctx.reply_text(
caption=strings("on_afk_msg_no_r").format(usr=message.from_user.mention, id=message.from_user.id, tm=seenago), caption=strings("on_afk_msg_no_r").format(usr=ctx.from_user.mention, id=ctx.from_user.id, tm=seenago),
disable_web_page_preview=True, disable_web_page_preview=True,
) )
elif afktype == "text_reason": elif afktype == "text_reason":
send = await message.reply_text( send = await ctx.reply_text(
caption=strings("on_afk_msg_with_r").format(usr=message.from_user.mention, id=message.from_user.id, tm=seenago, reas=reasonafk), caption=strings("on_afk_msg_with_r").format(usr=ctx.from_user.mention, id=ctx.from_user.id, tm=seenago, reas=reasonafk),
disable_web_page_preview=True, disable_web_page_preview=True,
) )
except Exception: except Exception:
send = await message.reply_text( send = await ctx.reply_text(
strings("is_online").format(usr=message.from_user.first_name), strings("is_online").format(usr=ctx.from_user.first_name),
disable_web_page_preview=True, disable_web_page_preview=True,
) )
await put_cleanmode(message.chat.id, send.id) await put_cleanmode(ctx.chat.id, send.id)
return return
if len(message.command) == 1 and not message.reply_to_message: if len(ctx.command) == 1 and not ctx.reply_to_message:
details = { details = {
"type": "text", "type": "text",
"time": time.time(), "time": time.time(),
"data": None, "data": None,
"reason": None, "reason": None,
} }
elif len(message.command) > 1 and not message.reply_to_message: elif len(ctx.command) > 1 and not ctx.reply_to_message:
_reason = (message.text.split(None, 1)[1].strip())[:100] _reason = (ctx.text.split(None, 1)[1].strip())[:100]
details = { details = {
"type": "text_reason", "type": "text_reason",
"time": time.time(), "time": time.time(),
"data": None, "data": None,
"reason": _reason, "reason": _reason,
} }
elif len(message.command) == 1 and message.reply_to_message.animation: elif len(ctx.command) == 1 and ctx.reply_to_message.animation:
_data = message.reply_to_message.animation.file_id _data = ctx.reply_to_message.animation.file_id
details = { details = {
"type": "animation", "type": "animation",
"time": time.time(), "time": time.time(),
"data": _data, "data": _data,
"reason": None, "reason": None,
} }
elif len(message.command) > 1 and message.reply_to_message.animation: elif len(ctx.command) > 1 and ctx.reply_to_message.animation:
_data = message.reply_to_message.animation.file_id _data = ctx.reply_to_message.animation.file_id
_reason = (message.text.split(None, 1)[1].strip())[:100] _reason = (ctx.text.split(None, 1)[1].strip())[:100]
details = { details = {
"type": "animation", "type": "animation",
"time": time.time(), "time": time.time(),
"data": _data, "data": _data,
"reason": _reason, "reason": _reason,
} }
elif len(message.command) == 1 and message.reply_to_message.photo: elif len(ctx.command) == 1 and ctx.reply_to_message.photo:
await app.download_media(message.reply_to_message, file_name=f"{user_id}.jpg") await app.download_media(ctx.reply_to_message, file_name=f"{user_id}.jpg")
details = { details = {
"type": "photo", "type": "photo",
"time": time.time(), "time": time.time(),
"data": None, "data": None,
"reason": None, "reason": None,
} }
elif len(message.command) > 1 and message.reply_to_message.photo: elif len(ctx.command) > 1 and ctx.reply_to_message.photo:
await app.download_media(message.reply_to_message, file_name=f"{user_id}.jpg") await app.download_media(ctx.reply_to_message, file_name=f"{user_id}.jpg")
_reason = message.text.split(None, 1)[1].strip() _reason = ctx.text.split(None, 1)[1].strip()
details = { details = {
"type": "photo", "type": "photo",
"time": time.time(), "time": time.time(),
"data": None, "data": None,
"reason": _reason, "reason": _reason,
} }
elif len(message.command) == 1 and message.reply_to_message.sticker: elif len(ctx.command) == 1 and ctx.reply_to_message.sticker:
if message.reply_to_message.sticker.is_animated: if ctx.reply_to_message.sticker.is_animated:
details = { details = {
"type": "text", "type": "text",
"time": time.time(), "time": time.time(),
@ -150,16 +150,16 @@ async def active_afk(self: Client, ctx: Message, strings):
"reason": None, "reason": None,
} }
else: else:
await app.download_media(message.reply_to_message, file_name=f"{user_id}.jpg") await app.download_media(ctx.reply_to_message, file_name=f"{user_id}.jpg")
details = { details = {
"type": "photo", "type": "photo",
"time": time.time(), "time": time.time(),
"data": None, "data": None,
"reason": None, "reason": None,
} }
elif len(message.command) > 1 and message.reply_to_message.sticker: elif len(ctx.command) > 1 and ctx.reply_to_message.sticker:
_reason = (message.text.split(None, 1)[1].strip())[:100] _reason = (ctx.text.split(None, 1)[1].strip())[:100]
if message.reply_to_message.sticker.is_animated: if ctx.reply_to_message.sticker.is_animated:
details = { details = {
"type": "text_reason", "type": "text_reason",
"time": time.time(), "time": time.time(),
@ -167,7 +167,7 @@ async def active_afk(self: Client, ctx: Message, strings):
"reason": _reason, "reason": _reason,
} }
else: else:
await app.download_media(message.reply_to_message, file_name=f"{user_id}.jpg") await app.download_media(ctx.reply_to_message, file_name=f"{user_id}.jpg")
details = { details = {
"type": "photo", "type": "photo",
"time": time.time(), "time": time.time(),
@ -183,8 +183,8 @@ async def active_afk(self: Client, ctx: Message, strings):
} }
await add_afk(user_id, details) await add_afk(user_id, details)
send = await ctx.reply_msg(strings("now_afk").format(usr=message.from_user.mention, id=message.from_user.id)) send = await ctx.reply_msg(strings("now_afk").format(usr=ctx.from_user.mention, id=ctx.from_user.id))
await put_cleanmode(message.chat.id, send.id) await put_cleanmode(ctx.chat.id, send.id)
@app.on_message(filters.command("afkdel", COMMAND_HANDLER) & filters.group) @app.on_message(filters.command("afkdel", COMMAND_HANDLER) & filters.group)
@ -192,12 +192,12 @@ async def active_afk(self: Client, ctx: Message, strings):
@adminsOnly("can_change_info") @adminsOnly("can_change_info")
@use_chat_lang() @use_chat_lang()
async def afk_state(self: Client, ctx: Message, strings): async def afk_state(self: Client, ctx: Message, strings):
if not message.from_user: if not ctx.from_user:
return return
if len(message.command) == 1: if len(ctx.command) == 1:
return await ctx.reply_msg(strings("afkdel_help").format(cmd=message.command[0]), del_in=6) return await ctx.reply_msg(strings("afkdel_help").format(cmd=ctx.command[0]), del_in=6)
chat_id = message.chat.id chat_id = ctx.chat.id
state = message.text.split(None, 1)[1].strip() state = ctx.text.split(None, 1)[1].strip()
state = state.lower() state = state.lower()
if state == "enable": if state == "enable":
await cleanmode_on(chat_id) await cleanmode_on(chat_id)
@ -206,7 +206,7 @@ async def afk_state(self: Client, ctx: Message, strings):
await cleanmode_off(chat_id) await cleanmode_off(chat_id)
await ctx.reply_msg(strings("afkdel_disable")) await ctx.reply_msg(strings("afkdel_disable"))
else: else:
await ctx.reply_msg(strings("afkdel_help").format(cmd=message.command[0]), del_in=6) await ctx.reply_msg(strings("afkdel_help").format(cmd=ctx.command[0]), del_in=6)
# Detect user that AFK based on Yukki Repo # Detect user that AFK based on Yukki Repo
@ -216,14 +216,14 @@ async def afk_state(self: Client, ctx: Message, strings):
) )
@use_chat_lang() @use_chat_lang()
async def chat_watcher_func(self: Client, ctx: Message, strings): async def chat_watcher_func(self: Client, ctx: Message, strings):
if message.sender_chat: if ctx.sender_chat:
return return
userid = message.from_user.id userid = ctx.from_user.id
user_name = message.from_user.mention user_name = ctx.from_user.mention
if message.entities: if ctx.entities:
possible = ["/afk", f"/afk@{self.me.username}", "!afk"] possible = ["/afk", f"/afk@{self.me.username}", "!afk"]
message_text = message.text or message.caption message_text = ctx.text or ctx.caption
for entity in message.entities: for entity in ctx.entities:
if entity.type == enums.MessageEntityType.BOT_COMMAND: if entity.type == enums.MessageEntityType.BOT_COMMAND:
if (message_text[0 : 0 + entity.length]).lower() in possible: if (message_text[0 : 0 + entity.length]).lower() in possible:
return return
@ -247,23 +247,23 @@ async def chat_watcher_func(self: Client, ctx: Message, strings):
msg += strings("on_afk_msg_with_r").format(usr=user_name, id=userid, tm=seenago, reas=reasonafk) msg += strings("on_afk_msg_with_r").format(usr=user_name, id=userid, tm=seenago, reas=reasonafk)
if afktype == "animation": if afktype == "animation":
if str(reasonafk) == "None": if str(reasonafk) == "None":
send = await message.reply_animation( send = await ctx.reply_animation(
data, data,
caption=strings("on_afk_msg_no_r").format(usr=user_name, id=userid, tm=seenago), caption=strings("on_afk_msg_no_r").format(usr=user_name, id=userid, tm=seenago),
) )
else: else:
send = await message.reply_animation( send = await ctx.reply_animation(
data, data,
caption=strings("on_afk_msg_with_r").format(usr=user_name, id=userid, tm=seenago, reas=reasonafk), caption=strings("on_afk_msg_with_r").format(usr=user_name, id=userid, tm=seenago, reas=reasonafk),
) )
if afktype == "photo": if afktype == "photo":
if str(reasonafk) == "None": if str(reasonafk) == "None":
send = await message.reply_photo( send = await ctx.reply_photo(
photo=f"downloads/{userid}.jpg", photo=f"downloads/{userid}.jpg",
caption=strings("on_afk_msg_no_r").format(usr=user_name, id=userid, tm=seenago), caption=strings("on_afk_msg_no_r").format(usr=user_name, id=userid, tm=seenago),
) )
else: else:
send = await message.reply_photo( send = await ctx.reply_photo(
photo=f"downloads/{userid}.jpg", photo=f"downloads/{userid}.jpg",
caption=strings("on_afk_msg_with_r").format(usr=user_name, id=userid, tm=seenago, reas=reasonafk), caption=strings("on_afk_msg_with_r").format(usr=user_name, id=userid, tm=seenago, reas=reasonafk),
) )
@ -271,10 +271,10 @@ async def chat_watcher_func(self: Client, ctx: Message, strings):
msg += strings("is_online").format(usr=user_name, id=userid) msg += strings("is_online").format(usr=user_name, id=userid)
# Replied to a User which is AFK # Replied to a User which is AFK
if message.reply_to_message: if ctx.reply_to_message:
try: try:
replied_first_name = message.reply_to_message.from_user.mention replied_first_name = ctx.reply_to_message.from_user.mention
replied_user_id = message.reply_to_message.from_user.id replied_user_id = ctx.reply_to_message.from_user.id
verifier, reasondb = await is_afk(replied_user_id) verifier, reasondb = await is_afk(replied_user_id)
if verifier: if verifier:
try: try:
@ -289,23 +289,23 @@ async def chat_watcher_func(self: Client, ctx: Message, strings):
msg += strings("is_afk_msg_with_r").format(usr=replied_first_name, id=replied_user_id, tm=seenago, reas=reasonafk) msg += strings("is_afk_msg_with_r").format(usr=replied_first_name, id=replied_user_id, tm=seenago, reas=reasonafk)
if afktype == "animation": if afktype == "animation":
if str(reasonafk) == "None": if str(reasonafk) == "None":
send = await message.reply_animation( send = await ctx.reply_animation(
data, data,
caption=strings("is_afk_msg_no_r").format(usr=replied_first_name, id=replied_user_id, tm=seenago), caption=strings("is_afk_msg_no_r").format(usr=replied_first_name, id=replied_user_id, tm=seenago),
) )
else: else:
send = await message.reply_animation( send = await ctx.reply_animation(
data, data,
caption=strings("is_afk_msg_with_r").format(usr=replied_first_name, id=replied_user_id, tm=seenago, reas=reasonafk), caption=strings("is_afk_msg_with_r").format(usr=replied_first_name, id=replied_user_id, tm=seenago, reas=reasonafk),
) )
if afktype == "photo": if afktype == "photo":
if str(reasonafk) == "None": if str(reasonafk) == "None":
send = await message.reply_photo( send = await ctx.reply_photo(
photo=f"downloads/{replied_user_id}.jpg", photo=f"downloads/{replied_user_id}.jpg",
caption=strings("is_afk_msg_no_r").format(usr=replied_first_name, id=replied_user_id, tm=seenago), caption=strings("is_afk_msg_no_r").format(usr=replied_first_name, id=replied_user_id, tm=seenago),
) )
else: else:
send = await message.reply_photo( send = await ctx.reply_photo(
photo=f"downloads/{replied_user_id}.jpg", photo=f"downloads/{replied_user_id}.jpg",
caption=strings("is_afk_msg_with_r").format(usr=replied_first_name, id=replied_user_id, tm=seenago, reas=reasonafk), caption=strings("is_afk_msg_with_r").format(usr=replied_first_name, id=replied_user_id, tm=seenago, reas=reasonafk),
) )
@ -315,12 +315,12 @@ async def chat_watcher_func(self: Client, ctx: Message, strings):
pass pass
# If username or mentioned user is AFK # If username or mentioned user is AFK
if message.entities: if ctx.entities:
entity = message.entities entity = ctx.entities
j = 0 j = 0
for x in range(len(entity)): for x in range(len(entity)):
if (entity[j].type) == enums.MessageEntityType.MENTION: if (entity[j].type) == enums.MessageEntityType.MENTION:
found = re.findall("@([_0-9a-zA-Z]+)", message.text) found = re.findall("@([_0-9a-zA-Z]+)", ctx.text)
try: try:
get_user = found[j] get_user = found[j]
user = await app.get_users(get_user) user = await app.get_users(get_user)
@ -344,23 +344,23 @@ async def chat_watcher_func(self: Client, ctx: Message, strings):
msg += strings("is_afk_msg_with_r").format(usr=user.first_name[:25], id=user.id, tm=seenago, reas=reasonafk) msg += strings("is_afk_msg_with_r").format(usr=user.first_name[:25], id=user.id, tm=seenago, reas=reasonafk)
if afktype == "animation": if afktype == "animation":
if str(reasonafk) == "None": if str(reasonafk) == "None":
send = await message.reply_animation( send = await ctx.reply_animation(
data, data,
caption=strings("is_afk_msg_no_r").format(usr=user.first_name[:25], id=user.id, tm=seenago), caption=strings("is_afk_msg_no_r").format(usr=user.first_name[:25], id=user.id, tm=seenago),
) )
else: else:
send = await message.reply_animation( send = await ctx.reply_animation(
data, data,
caption=strings("is_afk_msg_with_r").format(usr=user.first_name[:25], id=user.id, tm=seenago, reas=reasonafk), caption=strings("is_afk_msg_with_r").format(usr=user.first_name[:25], id=user.id, tm=seenago, reas=reasonafk),
) )
if afktype == "photo": if afktype == "photo":
if str(reasonafk) == "None": if str(reasonafk) == "None":
send = await message.reply_photo( send = await ctx.reply_photo(
photo=f"downloads/{user.id}.jpg", photo=f"downloads/{user.id}.jpg",
caption=strings("is_afk_msg_no_r").format(usr=user.first_name[:25], id=user.id, tm=seenago), caption=strings("is_afk_msg_no_r").format(usr=user.first_name[:25], id=user.id, tm=seenago),
) )
else: else:
send = await message.reply_photo( send = await ctx.reply_photo(
photo=f"downloads/{user.id}.jpg", photo=f"downloads/{user.id}.jpg",
caption=strings("is_afk_msg_with_r").format(usr=user.first_name[:25], id=user.id, tm=seenago, reas=reasonafk), caption=strings("is_afk_msg_with_r").format(usr=user.first_name[:25], id=user.id, tm=seenago, reas=reasonafk),
) )
@ -390,23 +390,23 @@ async def chat_watcher_func(self: Client, ctx: Message, strings):
msg += strings("is_afk_msg_with_r").format(usr=first_name[:25], id=user_id, tm=seenago, reas=reasonafk) msg += strings("is_afk_msg_with_r").format(usr=first_name[:25], id=user_id, tm=seenago, reas=reasonafk)
if afktype == "animation": if afktype == "animation":
if str(reasonafk) == "None": if str(reasonafk) == "None":
send = await message.reply_animation( send = await ctx.reply_animation(
data, data,
caption=strings("is_afk_msg_no_r").format(usr=first_name[:25], id=user_id, tm=seenago), caption=strings("is_afk_msg_no_r").format(usr=first_name[:25], id=user_id, tm=seenago),
) )
else: else:
send = await message.reply_animation( send = await ctx.reply_animation(
data, data,
caption=strings("is_afk_msg_with_r").format(usr=first_name[:25], id=user_id, tm=seenago, reas=reasonafk), caption=strings("is_afk_msg_with_r").format(usr=first_name[:25], id=user_id, tm=seenago, reas=reasonafk),
) )
if afktype == "photo": if afktype == "photo":
if str(reasonafk) == "None": if str(reasonafk) == "None":
send = await message.reply_photo( send = await ctx.reply_photo(
photo=f"downloads/{user_id}.jpg", photo=f"downloads/{user_id}.jpg",
caption=strings("is_afk_msg_no_r").format(usr=first_name[:25], id=user_id, tm=seenago), caption=strings("is_afk_msg_no_r").format(usr=first_name[:25], id=user_id, tm=seenago),
) )
else: else:
send = await message.reply_photo( send = await ctx.reply_photo(
photo=f"downloads/{user_id}.jpg", photo=f"downloads/{user_id}.jpg",
caption=strings("is_afk_msg_with_r").format(usr=first_name[:25], id=user_id, tm=seenago, reas=reasonafk), caption=strings("is_afk_msg_with_r").format(usr=first_name[:25], id=user_id, tm=seenago, reas=reasonafk),
) )
@ -415,10 +415,10 @@ async def chat_watcher_func(self: Client, ctx: Message, strings):
j += 1 j += 1
if msg != "": if msg != "":
try: try:
send = await message.reply_text(msg, disable_web_page_preview=True) send = await ctx.reply_text(msg, disable_web_page_preview=True)
except: except:
pass pass
try: try:
await put_cleanmode(message.chat.id, send.id) await put_cleanmode(ctx.chat.id, send.id)
except: except:
pass pass