async def afk(client, message): if PRIVATE_GROUP_ID is None: await message.edit("<b><i>Please set the variable</b></i> `PRIVATE_GROUP_ID` for this to function.") return global afk_start afk_time = None afk_end = {} start_1 = datetime.now() afk_start = start_1.replace(microsecond=0) if len(message.text.split()) >= 2: await message.edit_text( "I am going AFK now...\nBecause of {}".format(message.text.split(None, 1)[1])) await client.send_message(PRIVATE_GROUP_ID, "You are AFK!\nBecause of {}".format(message.text.split(None, 1)[1])) await asyncio.sleep(2) await message.delete() await asyncio.sleep(2) set_afk(True, message.text.split(None, 1)[1]) else: await message.edit_text( "{} is now AFK!".format(mention_markdown(message.from_user.first_name, message.from_user.id))) await client.send_message(PRIVATE_GROUP_ID, "{} is now AFK!".format(mention_markdown(message.from_user.first_name, message.from_user.id))) await asyncio.sleep(2) await message.delete() await asyncio.sleep(2) set_afk(True, "") return
async def demote_usr(client, message): msg = await message.edit("`Trying to Demote user...`") is_admin = await admin_check(message) if not is_admin: await msg.edit("`I'm not admin nub nibba!`") await asyncio.sleep(2) await message.delete() return user_id, user_first_name = await extract_user(client, message) try: await message.chat.promote_member(user_id=user_id, can_change_info=False, can_delete_messages=False, can_restrict_members=False, can_invite_users=False, can_pin_messages=False) await asyncio.sleep(2) if str(user_id).lower().startswith("@"): await message.edit(f"**Demoted** {user_first_name}") await client.send_message( PRIVATE_GROUP_ID, f"#DEMOTE\nDemoted {user_first_name} in chat {message.chat.title}" ) else: await message.edit("**Demoted** {}".format( mention_markdown(user_first_name, user_id))) await client.send_message( PRIVATE_GROUP_ID, "#DEMOTE\nDemoted {} in chat {}".format( mention_markdown(user_first_name, user_id), message.chat.title)) except Exception as ef: await message.edit(f"**Error:**\n\n`{ef}`")
async def unrestrict_usr(client, message): await message.edit("`Trying to Unrestrict user...`") is_admin = await admin_check(message) if not is_admin: await msg.edit("`I'm not admin nub nibba!`") await asyncio.sleep(2) await message.delete() return user_id, user_first_name = await extract_user(client, message) try: await message.chat.unban_member(user_id) if str(user_id).lower().startswith("@"): await message.edit(f"**UnRestricted** {user_first_name}") await client.send_message( PRIVATE_GROUP_ID, f"#UNRESTRICT\nUnrestricted {user_first_name} in chat {message.chat.title}" ) else: await message.edit("**UnRestricted** {}".format( mention_markdown(user_first_name, user_id))) await client.send_message( PRIVATE_GROUP_ID, "#UNRESTRICT\nUnrestricted {} in chat {}".format( mention_markdown(user_first_name, user_id), message.chat.title)) except Exception as ef: await message.edit(f"**Error:**\n\n`{ef}`")
async def restrict_usr(client, message): await message.edit("`Trying to Mute user...`") is_admin = await admin_check(message) chat_id = message.chat.id if not is_admin: await msg.edit("`I'm not admin nub nibba!`") await asyncio.sleep(2) await message.delete() return user_id, user_first_name = await extract_user(client, message) try: await message.chat.restrict_member(user_id=user_id, permisssions=ChatPermissions()) if str(user_id).lower().startswith("@"): await message.edit(f"**Muted** {user_first_name}") await client.send_message( PRIVATE_GROUP_ID, f"#MUTE\nMuted {user_first_name} in chat {message.chat.title}") else: await message.edit("**Muted** {}".format( mention_markdown(user_first_name, user_id))) await client.send_message( PRIVATE_GROUP_ID, "#MUTE\nMuted {} in chat {}".format( mention_markdown(user_first_name, user_id), message.chat.title)) except Exception as ef: await message.edit(f"**Error:**\n\n`{ef}`")
async def ban_usr(client, message): await message.edit("`Trying to Ban user...`") is_admin = await admin_check(message) if not is_admin: await msg.edit("`I'm not admin nub nibba!`") await asyncio.sleep(2) await message.delete() return user_id, user_first_name = await extract_user(client, message) if message.reply_to_message: await client.delete_messages(message.chat.id, message.reply_to_message.message_id) try: await message.chat.kick_member(user_id=user_id) if str(user_id).lower().startswith("@"): await message.edit(f"**Banned** {user_first_name}") await client.send_message( PRIVATE_GROUP_ID, f"#BAN\nBanned {user_first_name} in chat {message.chat.title}") else: await message.edit("**Banned** {}".format( mention_markdown(user_first_name, user_id))) await client.send_message( PRIVATE_GROUP_ID, "#BAN\nBanned {} in chat {}".format( mention_markdown(user_first_name, user_id), message.chat.title)) except Exception as ef: await message.edit(f"**Error:**\n\n`{ef}`")
async def adminlist(client, message): replyid = None toolong = False if len(message.text.split()) >= 2: chat = message.text.split(None, 1)[1] grup = await client.get_chat(chat) else: chat = message.chat.id grup = await client.get_chat(chat) if message.reply_to_message: replyid = message.reply_to_message.message_id alladmins = client.iter_chat_members(chat, filter="administrators") creator = [] admin = [] badmin = [] async for a in alladmins: try: nama = a.user.first_name + " " + a.user.last_name except: nama = a.user.first_name if nama is None: nama = "☠️ Deleted account" if a.status == "administrator": if a.user.is_bot: badmin.append(mention_markdown(nama, a.user.id)) else: admin.append(mention_markdown(nama, a.user.id)) elif a.status == "creator": creator.append(mention_markdown(nama, a.user.id)) admin.sort() badmin.sort() totaladmins = len(creator) + len(admin) + len(badmin) teks = "**Admins in {}**\n".format(grup.title) teks += "「 Creator 」\n" for x in creator: teks += "│ • {}\n".format(x) if len(teks) >= 4096: await message.reply(message.chat.id, teks, reply_to_message_id=replyid, parse_mode="md") teks = "" toolong = True teks += "「 {} Human Administrator 」\n".format(len(admin)) for x in admin: teks += "│ • {}\n".format(x) if len(teks) >= 4096: await message.reply(message.chat.id, teks, reply_to_message_id=replyid, parse_mode="md") teks = "" toolong = True teks += "「 {} Bot Administrator 」\n".format(len(badmin)) for x in badmin: teks += "│ • {}\n".format(x) if len(teks) >= 4096: await message.reply(message.chat.id, teks, reply_to_message_id=replyid, parse_mode="md") teks = "" toolong = True teks += "「 Total {} Admins 」".format(totaladmins) if toolong: await message.reply(message.chat.id, teks, reply_to_message_id=replyid, parse_mode="md") else: await message.edit(teks, parse_mode="md")
async def listbots(client, message): replyid = None if len(message.text.split()) >= 2: chat = message.text.split(None, 1)[1] grup = await client.get_chat(chat) else: chat = message.chat.id grup = await client.get_chat(chat) if message.reply_to_message: replyid = message.reply_to_message.message_id getbots = client.iter_chat_members(chat) bots = [] async for a in getbots: try: nama = a.user.first_name + " " + a.user.last_name except: nama = a.user.first_name if nama is None: nama = "☠️ Deleted account" if a.user.is_bot: bots.append(mention_markdown(nama, a.user.id)) teks = "**All bots in group {}**\n".format(grup.title) teks += "Bots\n" for x in bots: teks += "│ • {}\n".format(x) teks += "Total {} Bots".format(len(bots)) if replyid: await client.send_message(message.chat.id, teks, reply_to_message_id=replyid, parse_mode="md") else: await message.edit(teks, parse_mode="md")
async def revoke_pm_block(client, message): if message.chat.type == "private": user_id = message.chat.id else: user_id = message.text.split(" ")[1] db.del_whitelist(user_id) user = await client.get_users(user_id) await message.edit("__**PM permission was revoked for**__ {}".format(mention_markdown(user.first_name, user_id))) user_id = message.chat.id await client.send_message(PRIVATE_GROUP_ID, "{}'s **permission to contact you in PM has been revoked!**".format(mention_markdown(user.first_name, user_id))) await asyncio.sleep(5) await message.delete()
async def approve_pm(client, message): if message.chat.type == "private": user_id = message.chat.id else: user_id, user_first_name = extract_user(message) db.set_whitelist(user_id, True) user = await client.get_users(user_id) await message.edit("**__PM permission was approved__** for {}".format(mention_markdown(user.first_name, user_id))) if db.get_msg_id(message.chat.id): old_msg_id = db.get_msg_id(message.chat.id) await client.delete_messages( chat_id=message.chat.id, message_ids=old_msg_id) await client.send_message(PRIVATE_GROUP_ID, "{} **is approved to contact you in PM!**".format(mention_markdown(user.first_name, user_id))) await asyncio.sleep(5) await message.delete()
async def start_gmute(client, message): await message.edit("`Putting duct tape...`") user_id, user_first_name = await extract_user(client, message) if db.is_gmuted(user_id): await message.edit("`This user is already gmuted!`") return try: db.gmute(user_id) except Exception as e: await message.edit(f"<b>Error:</b>\n\n{str(e)}") else: await message.edit("`Successfully gmuted that person`") await client.send_message( PRIVATE_GROUP_ID, "#GMUTE\nUser: {} in Chat {}".format( mention_markdown(user_first_name, user_id), message.chat.title)) return
async def mention(client, message): args = message.text.split(" ", 2) if len(args) == 3: name = args[1] if isinstance(args[3], int): user = args[2] rep = "{}".format(mention_markdown(name, user)) else: user = args[2] rep = f'<a href="tg://resolve?domain={name}">{user}</a>' await message.edit(rep, disable_web_page_preview=True, parse_mode="html") else: await message.edit( f"Check `{COMMAND_HAND_LER}help {__PLUGIN__}` for infor on how to use", parse_mode="md") return
async def end_gmute(client, message): await message.edit("`Removing duct tape...`") user_id, user_first_name = await extract_user(client, message) if not db.is_gmuted(user_id): await message.edit("`This user is not gmuted!`") return try: db.ungmute(user_id) except Exception as e: await message.edit(f"<b>Error:</b>\n\n{str(e)}") else: await message.edit("`Successfully ungmuted that person`") await client.send_message(PRIVATE_GROUP_ID, "#UNGMUTE\nUser:{} in Chat {}".format( mention_markdown(user_first_name, user_id), message.chat.title), parse_mode="html") return
async def restrict_usr_tmp(client, message): await message.edit("`Trying to Temporarily Mute user...`") is_admin = await admin_check(message) chat_id = message.chat.id if not is_admin: await msg.edit("`I'm not admin nub nibba!`") await asyncio.sleep(2) await message.delete() return user_id, user_first_name = await extract_user(client, message) until_date_val = extract_time(message.command[1]) try: await message.chat.restrict_member(user_id=user_id, permisssions=ChatPermissions(), until_date=until_date_val) if str(user_id).lower().startswith("@"): await message.edit(f"**T Muted** {user_first_name} till {until_date_val}") await client.send_message(PRIVATE_GROUP_ID, f"#TEMPMUTE\nTemp. Muted {user_first_name} in chat {message.chat.title} till {until_date_val}") else: await message.edit("**T Muted** {} till {}".format(mention_markdown(user_first_name, user_id), until_date_val)) await client.send_message(PRIVATE_GROUP_ID, "#TEMPMUTE\nTemp. Muted {} in chat {}".format(mention_markdown(user_first_name, user_id), message.chat.title)) except Exception as ef: await message.edit(f"**Error:**\n\n`{ef}`")
async def afk_mentioned(client, message): global MENTIONED global afk_time global afk_start global afk_end get = get_afk() if get and get['afk']: current_time_afk = datetime.now() afk_end = current_time_afk.replace(microsecond=0) if afk_start != {}: total_afk_time = str((afk_end - afk_start)) afk_since = "**a while ago**" if afk_time: now = datetime.datetime.now() datime_since_afk = now - afk_time time_of_akf = float(datime_since_afk.seconds) days = time_of_akf // (24 * 3600) time_of_akf = time_of_akf % (24 * 3600) hours = time_of_akf // 3600 time_of_akf %= 3600 minutes = time_of_akf // 60 time_of_akf %= 60 seconds = time_of_akf if days == 1: afk_since = "**Yesterday**" elif days > 1: if days > 6: date = now + \ datetime.timedelta( days=-days, hours=-hours, minutes=-minutes) afk_since = date.strftime("%A, %Y %B %m, %H:%I") else: wday = now + datetime.timedelta(days=-days) afk_since = wday.strftime('%A') elif hours > 1: afk_since = f"`{int(hours)}h{int(minutes)}m` **ago**" elif minutes > 0: afk_since = f"`{int(minutes)}m{int(seconds)}s` **ago**" else: afk_since = f"`{int(seconds)}s` **ago**" if "-" in str(message.chat.id): cid = str(message.chat.id)[4:] else: cid = str(message.chat.id) if cid in list(AFK_RESTIRECT) and int(AFK_RESTIRECT[cid]) >= int( time.time() ): return AFK_RESTIRECT[cid] = int(time.time()) + DELAY_TIME if get['reason']: await message.reply_text( "Sorry, My Master {} is AFK right now!\nReason: {}\n\nAFK Since:{}".format(mention_markdown(OWNER_NAME, OWNER_ID), get['reason'], total_afk_time)) else: await message.reply_text("Sorry, My Master {} is AFK right now!\n\nAFK Since:{}".format(mention_markdown(OWNER_NAME, OWNER_ID), total_afk_time)) _, message_type = get_message_type(message) if message_type == Types.TEXT: text = message.text if message.text else message.caption else: text = message_type.name MENTIONED.append( {"user": message.from_user.first_name, "user_id": message.from_user.id, "chat": message.chat.title, "chat_id": cid, "text": text, "message_id": message.message_id, "time": datetime.now()}) await client.send_message(PRIVATE_GROUP_ID, "{}({}) mentioned you in {}({})\nText:\n`{}`\n\nTotal count: `{}`".format( mention_markdown(message.from_user.first_name, message.from_user.id), message.from_user.id, message.chat.title, message.chat.id, text[:3500], len(MENTIONED))) await message.stop_propagation()
async def pm_block(client, message): if not PM_PERMIT: return try: if not db.get_whitelist(message.chat.id): if db.get_msg_id(message.chat.id): old_msg_id = db.get_msg_id(message.chat.id) await client.delete_messages( chat_id=message.chat.id, message_ids=old_msg_id) rply_msg = await message.reply_text(welc_txt) db.set_last_msg_id(message.chat.id, rply_msg.message_id) await asyncio.sleep(2) await client.send_message(PRIVATE_GROUP_ID, "{} **wants to contact you in PM**".format(mention_markdown(message.from_user.first_name, message.from_user.id))) return except Exception as ef: print("Error!\n\n", ef) return