async def fun_slap(c: Alita, m: Message): me = await c.get_me() reply_text = m.reply_to_message.reply_text if m.reply_to_message else m.reply_text curr_user = html.escape(m.from_user.first_name) user_id = extract_user(m)[0] if user_id == me.id: temp = random.choice(fun_strings.SLAP_ALITA_TEMPLATES) return if user_id: slapped_user = await c.get_member(user_id) user1 = curr_user user2 = html.escape(slapped_user.first_name) else: user1 = me.first_name user2 = curr_user temp = random.choice(fun_strings.SLAP_ALITA_TEMPLATES) item = random.choice(fun_strings.ITEMS) hit = random.choice(fun_strings.HIT) throw = random.choice(fun_strings.THROW) reply = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) await reply_text(reply) return
async def unmute_usr(c: Alita, m: Message): _ = GetLang(m).strs res = await admin_check(c, m) if not res: return from_user = await m.chat.get_member(m.from_user.id) if len(m.text.split()) == 1 and not m.reply_to_message: await m.reply_text("Whom should I unmute?\nSpecify a user first.") return if from_user.can_restrict_members or from_user.status == "creator": user_id, user_first_name = extract_user(m) try: await m.chat.restrict_member(user_id, unmute_permissions) await m.reply_text(f"<b>Muted</b> {mention_html(user_first_name,user_id)}") except errors.ChatAdminRequired: await m.reply_text(_("admin.notadmin")) except Exception as ef: await m.reply_text(f"<code>{ef}</code>\nReport to @{SUPPORT_GROUP}") LOGGER.error(ef) return await m.reply_text("You don't have permissions to restrict users.") return
async def kick_usr(c: Alita, m: Message): _ = GetLang(m).strs res = await admin_check(c, m) if not res: return from_user = await m.chat.get_member(m.from_user.id) if len(m.text.split()) == 1 and not m.reply_to_message: await m.reply_text("Whom should I kick?\nSpecify a user first.") return if from_user.can_restrict_members or from_user.status == "creator": user_id, user_first_name = extract_user(m) try: await c.kick_chat_member(m.chat.id, user_id, int(time.time() + 45)) await m.reply_text(f"Banned {mention_html(user_first_name, user_id)}") except errors.ChatAdminRequired: await m.reply_text(_("admin.notadmin")) except Exception as ef: await m.reply_text(f"<code>{ef}</code>\nReport to @{SUPPORT_GROUP}") LOGGER.error(ef) return
async def gban(c: Alita, m: Message): if len(m.text.split()) == 1: await m.reply_text( "<b>How to gban?</b>\n<b>Answer:</b> `/gban user_id reason`") return if len(m.text.split()) == 2 and not m.reply_to_message: await m.reply_text("Please enter a reason to gban user!") return user_id, user_first_name = extract_user(m) me = await c.get_me() if m.reply_to_message: gban_reason = m.text.split(None, 1)[1] else: gban_reason = m.text.split(None, 2)[2] if user_id in SUPPORT_STAFF: await m.reply_text("This user is part of Skuzzers!, Can't ban our own!" ) return if user_id == me.id: await m.reply_text("You can't gban me n***a!\nNice Try...!") return if db.is_user_gbanned(user_id): old_reason = db.update_gban_reason(user_id, user_first_name, gban_reason) await m.reply_text((f"Updated Gban reason to: `{gban_reason}`.\n" f"Old Reason was: `{old_reason}`")) return db.gban_user(user_id, user_first_name, gban_reason) await m.reply_text( (f"Added {user_first_name} to Global Ban List.\n" "They will now be banned in all groups where I'm admin!")) log_msg = ( f"#GBAN\n" f"<b>Originated from:</b> {m.chat.id}\n" f"<b>Admin:</b> {mention_html(m.from_user.first_name, m.from_user.id)}\n" f"<b>Gbanned User:</b> {mention_html(user_first_name, user_id)}\n" f"<b>Gbanned User ID:</b> {user_id}\n" f"<b>Event Stamp:</b> {datetime.utcnow().strftime('%H:%M - %d-%m-%Y')}" ) await c.send_message(MESSAGE_DUMP, log_msg) try: # Send message to user telling that he's gbanned await c.send_message( user_id, ("You have been added to my global ban list!\n" f"Reason: `{gban_reason}`\n\n" f"Appeal Chat: @{SUPPORT_GROUP}"), ) except Exception: # TO DO: Improve Error Detection pass return
async def my_info(c: Alita, m: Message): infoMsg = await m.reply_text("<code>Getting user information...</code>") user_id, first_name = extract_user(m) try: user = await c.get_users(user_id) except errors.PeerIdInvalid: await m.reply_text( "Failed to get user\nPeer ID invalid, I haven't seen this user anywhere earlier, maybe username would help to know them!" ) except Exception as ef: await m.reply_text(f"<code>{ef}</code>\nReport to @{SUPPORT_GROUP}") return text = ( f"<b>Characteristics:</b>\n" f"<b>ID:</b> <code>{user.id}</code>\n" f"<b>First Name:</b> <code>{html.escape(user.first_name)}</code>" ) if user.last_name: text += f"\n<b>Last Name:</b></b> <code>{html.escape(user.last_name)}</code>" if user.username: text += f"\n<b>Username</b>: @{html.escape(user.username)}" text += f"\n<b>Permanent user link:</b> {mention_html('Click Here', user.id)}" if user.id == OWNER_ID: text += "\n\nThis person is my Owner, I would never do anything against them!" elif user.id in DEV_USERS: text += "\n\nThis member is one of my Developers ⚡️" elif user.id in SUDO_USERS: text += "\n\nThe Power level of this person is 'Sudo'" elif user.id in WHITELIST_USERS: text += "\n\nThis person is 'Whitelist User', they cannot be banned!" try: user_member = await c.get_users(user.id) if user_member.status == "administrator": result = requests.post( ( f"https://api.telegram.org/bot{TOKEN}/" f"getChatMember?chat_id={m.chat.id}&user_id={user.id}" ) ) result = result.json()["result"] if "custom_title" in result.keys(): custom_title = result["custom_title"] text += f"\n\nThis user holds the title <b>{custom_title}</b> here." except BaseException: pass await infoMsg.edit_text(text, parse_mode="html", disable_web_page_preview=True) return
async def demote_usr(c: Alita, m: Message): _ = GetLang(m).strs res = await admin_check(c, m) if not res: return from_user = await m.chat.get_member(m.from_user.id) if len(m.text.split()) == 1 and not m.reply_to_message: await m.reply_text("Whom should I demote?\nSpecify a user first.") return # If user does not have permission to demote other users, return if from_user.can_promote_members or from_user.status == "creator": user_id, user_first_name = extract_user(m) try: await m.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 m.reply_text( _("admin.demoted").format( demoter=mention_html(m.from_user.first_name, m.from_user.id), demoted=mention_html(user_first_name, user_id), chat_title=m.chat.title, ) ) # ----- Add admin to redis cache! ----- ADMINDICT = get_key("ADMINDICT") # Load ADMINDICT from string adminlist = [] async for i in m.chat.iter_members(filter="administrators"): adminlist.append(i.user.id) ADMINDICT[str(m.chat.id)] = adminlist set_key("ADMINDICT", ADMINDICT) except errors.ChatAdminRequired: await m.reply_text(_("admin.notadmin")) except errors.RightForbidden: await m.reply_text("I don't have enough rights to demote this user.") except Exception as ef: await m.reply_text(f"<code>{ef}</code>\nReport to @{SUPPORT_GROUP}") LOGGER.error(ef) return await m.reply_text(_("admin.nodemoteperm")) return
async def check_approval(c: Alita, m: Message): res = await admin_check(c, m) if not res: return user_id, user_first_name = extract_user(m) if not user_id: await m.reply_text( "I don't know who you're talking about, you're going to need to specify a user!" ) return if db.is_approved(m.chat.id, user_id): await m.reply_text( f"{mention_html(user_first_name, user_id)} is an approved user. Locks, antiflood, and blocklists won't apply to them." ) else: await m.reply_text( f"{mention_html(user_first_name, user_id)} is not an approved user. They are affected by normal commands." ) return
async def ungban(c: Alita, m: Message): if len(m.text.split()) == 1: await m.reply_text("Pass a user id or username as an argument!") return user_id, user_first_name = extract_user(m) me = await c.get_me() if user_id in SUPPORT_STAFF: await m.reply_text( "They can't be banned, so how am I supposed to ungban them?") return if user_id == me.id: await m.reply_text("Nice Try...!") return if db.is_user_gbanned(user_id): db.ungban_user(user_id) await m.reply_text(f"Removed {user_first_name} from Global Ban List.") log_msg = ( f"#UNGBAN\n" f"<b>Originated from:</b> {m.chat.id}\n" f"<b>Admin:</b> {mention_html(m.from_user.first_name, m.from_user.id)}\n" f"<b>UnGbanned User:</b> {mention_html(user_first_name, user_id)}\n" f"<b>UnGbanned User ID:</b> {user_id}\n" f"<b>Event Stamp:</b> {datetime.utcnow().strftime('%H:%M - %d-%m-%Y')}" ) await c.send_message(MESSAGE_DUMP, log_msg) try: # Send message to user telling that he's ungbanned await c.send_message( user_id, "You have been removed from my global ban list!\n") except Exception: # TO DO: Improve Error Detection pass return await m.reply_text("User is not gbanned!") return
async def disapprove_user(c: Alita, m: Message): res = await owner_check(c, m) if not res: return chat_title = m.chat.title chat_id = m.chat.id user_id, user_first_name = extract_user(m) if not user_id: await m.reply_text( "I don't know who you're talking about, you're going to need to specify a user!" ) return try: member = await c.get_chat_member(chat_id=chat_id, user_id=user_id) except errors.UserNotParticipant: if db.is_approved(chat_id, user_id): db.disapprove(chat_id, user_id) await m.reply_text("This user is not in this chat!") return except Exception as ef: await m.reply_text( f"<b>Error</b>: <code>{ef}</code>\nReport it to @{SUPPORT_GROUP}") return if member.status in ["administrator", "creator"]: await m.reply_text("This user is an admin, they can't be unapproved.") return if not db.is_approved(chat_id, user_id): await m.reply_text( f"{mention_html(user_first_name, user_id)} isn't approved yet!") return db.disapprove(chat_id, user_id) await m.reply_text( f"{mention_html(user_first_name, user_id)} is no longer approved in {chat_title}." ) return
async def approve_user(c: Alita, m: Message): res = await owner_check(c, m) if not res: return chat_title = m.chat.title chat_id = m.chat.id user_id, user_first_name = extract_user(m) if not user_id: await m.reply_text( "I don't know who you're talking about, you're going to need to specify a user!" ) return try: member = await c.get_chat_member(chat_id=chat_id, user_id=user_id) except errors.UserNotParticipant: await m.reply_text("This user is not in this chat!") return except Exception as ef: await m.reply_text( f"<b>Error</b>: <code>{ef}</code>\nReport it to @{SUPPORT_GROUP}") return if member.status in ["administrator", "creator"]: await m.reply_text( f"User is already admin - blocklists already don't apply to them.") return if db.is_approved(chat_id, user_id): await m.reply_text( f"{mention_html(user_first_name, user_id)} is already approved in {chat_title}" ) return db.approve(chat_id, user_id) await m.reply_text( f"{mention_html(user_first_name, user_id)} has been approved in {chat_title}! They will now be ignored by blocklists." ) return
async def id_info(c: Alita, m: Message): user_id = extract_user(m)[0] if user_id: if m.reply_to_message and m.reply_to_message.forward_from: user1 = m.reply_to_m.from_user user2 = m.reply_to_m.forward_from await m.reply_text( ( f"Original Sender - {mention_html(user2.first_name, user2.id)} " f"(<code>{user2.id}</code>).\n" f"Forwarder - {mention_html(user1.first_name, user1.id)} " f"(<code>{user1.id}</code>)." ), parse_mode="HTML", ) else: try: user = await c.get_users(user_id) except errors.PeerIdInvalid: await m.reply_text( "Failed to get user\nPeer ID invalid, I haven't seen this user anywhere earlier, maybe username would help to know them!" ) await m.reply_text( f"{mention_html(user.first_name, user.id)}'s ID is <code>{user.id}</code>.", parse_mode="HTML", ) else: if m.chat.type == "private": await m.reply_text( f"Your ID is <code>{m.chat.id}</code>.", parse_mode="HTML" ) else: await m.reply_text( f"This Group's ID is <code>{m.chat.id}</code>.", parse_mode="HTML" ) return