Skip to content

Commit

Permalink
merge multi-account-beta to master (#12)
Browse files Browse the repository at this point in the history
* -removed ffpmeg dependency
- added video suppport

* decreasing image quality

* added silent flag

* added missing progressive tag

* .

* fetching only progressive videos

* upgrading to dev16

* updated to dev16

* init

* - mutli chat support
- updated to dev 19

* - added play command
- added pause/resume command
- added stop command
- aded skip command
- moved most taks to `callmanage`

* - resolved auth issue
- fixed chat member count check

* pause fix

* playback fixes

* - no mongo support
- fixed auto stop issue
- modified readme file
  • Loading branch information
kshubham506 authored Sep 13, 2021
1 parent b4376ac commit 7cf6d0c
Show file tree
Hide file tree
Showing 48 changed files with 2,540 additions and 1,771 deletions.
17 changes: 5 additions & 12 deletions .env copy
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
webhookUrl=<optional>
WEBHOOK_AUTH=<optional>
HELPER_ACT=<username of userbot>
HELPER_ACT_ID=<user if of userbot>
BOT_ID=<user id of bot>
LOG_INSIGHT_KEY=<optional>
LOG_INSIGHT_REGION=<optional>
BOT_TOKEN=<mandatory>
API_ID=<mandatory>
MONGO_URL=<mandatory>
API_HASH=<mandatory>
USERBOT_SESSION=<mandatory>
BOT_TOKEN=
API_ID=
API_HASH=
MONGO_URL=
USERBOT_SESSION=
5 changes: 0 additions & 5 deletions .env.common

This file was deleted.

16 changes: 2 additions & 14 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Telegram VCPlayer Bot",
"description": "Telegram Voice-Chat Music Player Bot. Dveloped and maintained by SkTechHub.",
"description": "Telegram Voice-Chat Music Player Bot. Developed and maintained by SkTechHub.",
"repository": "https://github.com/kshubham506/vcplayerbot",
"logo": "https://i.postimg.cc/QdH3XrxV/Screenshot-2021-05-05-203005-removebg-preview.png",
"keywords": [
Expand Down Expand Up @@ -34,20 +34,8 @@
"required": true
},
"USERBOT_SESSION": {
"description": "USER BOT Session string. generate this using the generateSession.py script present in github repo.",
"description": "USER BOT Session string. Generate this using the generateSession.py script present in github repo.",
"required": true
},
"MONGO_URL": {
"description": "MONGO Database URI. Leave it blank as it's not compulsory.",
"required": false
},
"MODE": {
"description": "Default is multiple, which means bot will be allowed only in one group. Allowed [single, multiple]",
"required": false
},
"AUTO_LEAVE": {
"description": "False by default. Allows the user bot to leave the grp at regualr intervals automatically. Allowed [on, off]",
"required": false
}
},
"formation": {
Expand Down
348 changes: 0 additions & 348 deletions callmanager.py

This file was deleted.

80 changes: 0 additions & 80 deletions dbhandler.py

This file was deleted.

File renamed without changes.
197 changes: 197 additions & 0 deletions decorators/extras.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import asyncio
from pyrogram.types import Message, Chat
from utils.Logger import logException, logWarning
from cache import AsyncTTL
from utils import logger, config, helperClient, logInfo
import re
from pyrogram import Client


def hasRequiredPermission(user):
try:
required = [
"can_post_messages",
"can_invite_users",
"can_manage_voice_chats",
"can_promote_members",
]
not_present = []
for _ in required:
if hasattr(user, _) is not True or user[_] is False:
not_present.append(_)
return len(not_present) == 0
except Exception as ex:
logException(f"Error in hasRequiredPermission : {ex}")


async def validate_session_string(api_id, api_hash, session_string, getUser=False):
try:
logInfo(f"Starting to validate user: {api_id}, {api_hash}")
user_app = Client(
session_string,
api_id=int(api_id),
api_hash=api_hash,
)
await user_app.start()
me = await user_app.get_me()
logInfo(f"validated session string: {me.id}")
if getUser is False:
await user_app.stop()
return True, "", None, me.id, me.username
else:
return True, "", user_app, me.id, me.username
except Exception as ex:
logException(f"Error in validate_session_string : {ex}")
return False, str(ex), None, "", ""


@AsyncTTL(time_to_live=20, maxsize=1024)
async def get_chat_member(client: Client, chat_id, bot_id):
try:
return await client.get_chat_member(chat_id, bot_id)
except Exception as ex:
logWarning(f"Error in get_chat_member : {ex}{chat_id, bot_id}")


@AsyncTTL(time_to_live=60, maxsize=1024)
async def get_chat_details(client: Client, chat_id):
try:
chat_details: Chat = await client.get_chat(chat_id)
return chat_details
except Exception as ex:
logException(f"Error in get_chat_details : {ex}")


@AsyncTTL(time_to_live=60, maxsize=1024)
async def get_chat_member_count(client: Client, chat_id):
try:
chat: Chat = await get_chat_details(client, chat_id)
return chat.members_count
# await client.get_chat_members_count(chat_id)
except Exception as ex:
logException(f"Error in get_chat_member_count : {ex}")


@AsyncTTL(time_to_live=60, maxsize=1024)
async def get_chat_member_list(client: Client, chat_id):
try:
await client.get_chat_members(client, chat_id)
except Exception as ex:
logException(f"Error in get_chat_member_list : {ex}")


@AsyncTTL(time_to_live=30, maxsize=1024)
async def getAlladmins(client: Client, chat_id):
try:
admins = await client.get_chat_members(chat_id, filter="administrators")
admins = list(
filter(
lambda a: a.user is not None
and (a.user.id == config.get("BOT_ID") or a.user.is_bot is False),
admins,
)
)
admins = [
{
"chat_id": i.user.id,
"username": i.user.username if hasattr(i.user, "username") else "",
"haspermission": hasRequiredPermission(i),
}
for i in admins
]
return admins
except Exception as ex:
logException(f"Error while fetching admins : {ex}")
return []


async def delayDelete(message, delay=1):
try:
if message is None:
return
else:
await asyncio.sleep(delay)
await message.delete()
except Exception as ex:
logException(f"Error in delayDelete : {ex}")


async def delete_message(message: Message):
try:
if message is not None and isinstance(message, Message):
await message.delete()
except Exception as ex:
logException(f"Error in delete_message : {ex}")


async def send_message(client: Client, chat_id, message):
try:
return await client.send_message(
chat_id,
message,
disable_web_page_preview=True,
)
except Exception as ex:
logException(f"Error in send_message : {ex}")


async def send_photo(client: Client, chat_id, photo, caption):
try:
return await client.send_photo(chat_id, photo=photo, caption=caption)
except Exception as ex:
logException(f"Error in send_photo : {ex}")


async def edit_message(sent_message: Message, message):
try:
return await sent_message.edit(message, disable_web_page_preview=True)
except Exception as ex:
logException(f"Error in edit_message : {ex}")


def parseIncomingCommand(command, max_video_res=None, max_audio_res=None):
try:
is_video = helperClient.checkForArguments(command, "IS_VIDEO")
resolution = helperClient.checkForArguments(command, "RES")
if resolution is None:
resolution = 256 if is_video is False else 480
song_name = helperClient.checkForArguments(command, "NAME")
is_repeat = helperClient.checkForArguments(command, "REPEAT")
only_audio = helperClient.checkForArguments(command, "ONLY_AUDIO")
lip_sync = helperClient.checkForArguments(command, "LIP_SYNC")
_urls = helperClient.getUrls(song_name)
is_url = len(_urls) > 0
song_url = _urls[0] if is_url is True else None
is_youtube = (
True
if (
is_url is False
or (
is_url is True
and re.search("youtube\.|youtu\.be|youtube-nocookie\.", song_url)
)
)
else False
)
switched = False
if is_video is False and max_audio_res and int(resolution) > max_audio_res:
resolution = max_audio_res
switched = True
elif is_video is True and max_video_res and int(resolution) > max_video_res:
resolution = max_video_res
switched = True

return {
"is_video": is_video,
"resolution": resolution,
"is_youtube": is_youtube,
"resolution_switched": switched,
"is_url": is_url,
"song_url": song_url,
"song_name": song_name,
"is_repeat": is_repeat is True,
"only_audio": only_audio is True,
"lip_sync": lip_sync is True,
}
except Exception as ex:
logException(f"Error in parseIncomingCommand : {ex}")
62 changes: 62 additions & 0 deletions decorators/is_bot_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from typing import Callable
from pyrogram import Client
from pyrogram.filters import private_filter
from pyrogram.types import Message, CallbackQuery

from utils import logException, logInfo, config, logger
from decorators.extras import get_chat_member


def is_bot_admin(func: Callable) -> Callable:
async def decorator(client: Client, incomingPayload, current_client):
try:
if isinstance(incomingPayload, CallbackQuery) is True:
message: Message = incomingPayload.message
else:
message: Message = incomingPayload

current_chat = message.chat
if await private_filter(None, None, message) is not True:
missing_permissions = []
if current_chat.permissions:
required_permissions = [
"can_send_messages",
"can_send_media_messages",
]
missing_permissions = list(
filter(
lambda perm: hasattr(current_chat.permissions, perm) is True
and getattr(current_chat.permissions, perm) is not True,
required_permissions,
)
)
if not missing_permissions:
botInfo = await get_chat_member(
client, current_chat.id, config.get("BOT_ID")
)
required_permissions = [
"can_delete_messages",
"can_manage_voice_chats",
"can_promote_members",
"can_invite_users",
]
missing_permissions = list(
filter(
lambda perm: botInfo is None
or hasattr(botInfo, perm) is False
or getattr(botInfo, perm) is not True,
required_permissions,
)
)
if missing_permissions:
missing_permissions = "\n".join(missing_permissions)
msg = f"__Please add the bot **{config.get('BOT_USERNAME')}** as an admin or at least provide the below mandatory permissions to it__.\n__Wait for at least 10 sec after granting the permissions.__\n\n`{missing_permissions}`"
return await client.send_message(
message.chat.id, f"{msg}", disable_web_page_preview=True
)

return await func(client, incomingPayload, current_client)
except Exception as ex:
logException(f"Error in is_bot_admin: {ex}")

return decorator
Loading

0 comments on commit 7cf6d0c

Please sign in to comment.