Skip to content

Commit

Permalink
Bot Add & Bot Left Updated !!!
Browse files Browse the repository at this point in the history
Co-Authored-By: Vivek Kumar <[email protected]>
  • Loading branch information
KSKOP69 and Vivekkumar-IN committed Jan 18, 2025
1 parent e382512 commit 659a049
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 21 deletions.
106 changes: 85 additions & 21 deletions AlexaMusic/plugins/modules/botwelcomlog.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,94 @@
# This code is written by (C) TheTeamAlexa bot will send message to log group when someone add
# this bot to new group make sure to star all projects
# Copyright (C) 2021-2025 by Alexa_Help@ Github, < TheTeamAlexa >.
# A Powerful Music Bot Property Of Rocks Indian Largest Chatting Group
# All rights reserved. © Alisha © Alexa © Yukki
# All rights reserved. © Alexa © Yukki

from pyrogram import Client, filters
from pyrogram.types import Message
from pyrogram import filters
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
from config import LOG, LOG_GROUP_ID
from AlexaMusic import app
from AlexaMusic.utils.database import get_served_chats
from config import LOG_GROUP_ID
from AlexaMusic.utils.database import delete_served_chat, get_assistant, is_on_off


async def lul_message(chat_id: int, message: str):
await app.send_message(chat_id=chat_id, text=message)
@app.on_message(filters.new_chat_members)
async def bot_added(_, message):
try:
if not await is_on_off(LOG):
return
userbot = await get_assistant(message.chat.id)
chat = message.chat
for members in message.new_chat_members:
if members.id == app.id:
count = await app.get_chat_members_count(chat.id)
username = (
message.chat.username if message.chat.username else "Private Chat"
)
msg = (
f"<b>Bot added in</b> {message.chat.title}\n\n"
f"<b>Name:</b> {message.chat.title}\n"
f"<b>Id:</b> {message.chat.id}\n"
f"<b>Username:</b> @{username}\n"
f"<b>Added By:</b> {message.from_user.mention}"
)
await app.send_message(
LOG_GROUP_ID,
text=msg,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text=f"Added by: {message.from_user.first_name}",
user_id=message.from_user.id,
)
]
]
),
)
if message.chat.username:
await userbot.join_chat(message.chat.username)
except Exception:
pass


@app.on_message(filters.new_chat_members)
async def on_new_chat_members(client: Client, message: Message):
if (await client.get_me()).id in [user.id for user in message.new_chat_members]:
added_by = message.from_user.first_name if message.from_user else "ᴜɴᴋɴᴏᴡɴ ᴜsᴇʀ"
matlabi_jhanto = message.chat.title
served_chats = len(await get_served_chats())
chat_id = message.chat.id
if message.chat.username:
chatusername = f"@{message.chat.username}"
else:
chatusername = "ᴩʀɪᴠᴀᴛᴇ ᴄʜᴀᴛ"
lemda_text = f"🌹 ʙᴏᴛ ᴀᴅᴅᴇᴅ ᴛᴏ ɴᴇᴡ ɢʀᴏᴜᴘ ..\n\n┏━━━━━━━━━━━━━━━━━┓\n┣★ **ᴄʜᴀᴛ** › : {matlabi_jhanto}\n┣★ **ᴄʜᴀᴛ ɪᴅ** › : {chat_id}\n┣★ **ᴄʜᴀᴛ ᴜɴᴀᴍᴇ** › : {chatusername}\n┣★ **ᴛᴏᴛᴀʟ ᴄʜᴀᴛ** › : {served_chats}\n┣★ **ᴀᴅᴅᴇᴅ ʙʏ** › :\n┗━━━ {added_by}"
await lul_message(LOG_GROUP_ID, lemda_text)
@app.on_message(filters.left_chat_member)
async def bot_kicked(_, message: Message):
try:
if not await is_on_off(LOG):
return
userbot = await get_assistant(message.chat.id)
left_chat_member = message.left_chat_member
if left_chat_member and left_chat_member.id == app.id:
remove_by = (
message.from_user.mention if message.from_user else "Unknown User"
)
title = message.chat.title
username = (
f"@{message.chat.username}" if message.chat.username else "Private Chat"
)
chat_id = message.chat.id
left = (
f"Bot was Removed in {title}\n"
f"<b>Name</b>: {title}\n"
f"<b>Id</b>: {chat_id}\n"
f"<b>Username</b>: {username}\n"
f"<b>Removed By</b>: {remove_by}"
)

await app.send_message(
LOG_GROUP_ID,
text=left,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text=f"Removed By: {message.from_user.first_name}",
user_id=message.from_user.id,
)
]
]
),
)
await delete_served_chat(chat_id)
await userbot.leave_chat(chat_id)
except Exception as e:
pass
4 changes: 4 additions & 0 deletions AlexaMusic/utils/database/mongodatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ async def add_served_user(user_id: int):
return await usersdb.insert_one({"user_id": user_id})


async def delete_served_chat(chat_id: int):
await chatsdb.delete_one({"chat_id": chat_id})


# Served Chats


Expand Down

0 comments on commit 659a049

Please sign in to comment.