Skip to content

Commit

Permalink
Super Verion 8 - stream feature + Fixed Bugs
Browse files Browse the repository at this point in the history
no need to buy paid sources codes while LazyDeveloperr is here.... #rip_paid_developers 😍
  • Loading branch information
LazyDeveloperr authored Aug 23, 2023
1 parent 2273afe commit 225954e
Show file tree
Hide file tree
Showing 34 changed files with 2,278 additions and 162 deletions.
6 changes: 6 additions & 0 deletions ai_LazyDeveloper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@
# ...while you are removing my credit and calling yourself a developerr...
# _____ just imagine, At that time i am fucking your mom and sis at same time, harder & too harder...
#
# Credit @LazyDeveloper.
# Please Don't remove credit.
# Born to make history @LazyDeveloper !
# Thank you LazyDeveloper for helping us in this Journey
# πŸ₯° Thank you for giving me credit @LazyDeveloperr πŸ₯°
# for any error please contact me -> telegram@LazyDeveloperr or insta @LazyDeveloperr
40 changes: 38 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,49 @@
"required": true
},
"DATABASE_NAME": {
"description": "Name of the database in mongoDB.",
"description": "mongoDB Database name.",
"required": false
},
"COLLECTION_NAME": {
"description": "Name of the collections. Defaults to Telegram_files. If you are using the same database, then use different collection name for each bot",
"description": "Name of the collections. Defaults name is Telegram_files. If you are using the same database, then use different collection name for each bot",
"value": "Telegram_files",
"required": false
},
"SLEEP_THRESHOLD": {
"description": "Floodwait Sleep timer. Read the readme for more info about this var",
"required": false
},
"WORKERS": {
"description": "Number of workers that is to be assigned. Read the readme for more info about this var",
"required": false
},
"PORT": {
"description": "Port that you want your webApp to be listened to. Read the readme for more info about this var",
"value": "8080",
"required": false
},
"NO_PORT": {
"description": "If you don't want your port to be displayed. Read the readme for more info about this var",
"value": "False",
"required": false
},
"HAS_SSL": {
"description": "Default value is True",
"value": "True",
"required": false
},
"BIND_ADRESS": {
"description": "Read the readme for more info about this var Leave Empty For heroku",
"required": false
},
"FQDN": {
"description": "Read the readme for more info about this var **Leave Empty for heroku**",
"required": false
},
"name": {
"description": " Session Name ",
"value": "File-To-Link",
"required": false
}
},
"addons": [],
Expand Down
167 changes: 92 additions & 75 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,99 +1,116 @@
import logging
import logging.config

# Credit @LazyDeveloper.
# Please Don't remove credit.
# Born to make history @LazyDeveloper !
# Thank you LazyDeveloper for helping us in this Journey
# πŸ₯° Thank you for giving me credit @LazyDeveloperr πŸ₯°
# for any error please contact me -> telegram@LazyDeveloperr or insta @LazyDeveloperr
# rip paid developers 🀣 - >> No need to buy paid source code while @LazyDeveloperr is here 😍😍
# Get logging configurations
logging.config.fileConfig('logging.conf')
logging.getLogger().setLevel(logging.INFO)
logging.getLogger("pyrogram").setLevel(logging.ERROR)
logging.getLogger("imdbpy").setLevel(logging.ERROR)
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logging.getLogger("aiohttp").setLevel(logging.ERROR)
logging.getLogger("aiohttp.web").setLevel(logging.ERROR)

from pyrogram import Client, __version__
from pyrogram.raw.all import layer
from database.ia_filterdb import Media
from database.users_chats_db import db
from info import SESSION, API_ID, API_HASH, BOT_TOKEN, LOG_STR
from info import *
from utils import temp
from typing import Union, Optional, AsyncGenerator
from pyrogram import types
from aiohttp import web
from plugins import web_server

PORT = "8080"
import asyncio
from pyrogram import idle
from lazybot import LazyPrincessBot
from util.keepalive import ping_server
from lazybot.clients import initialize_clients

class Bot(Client):
PORT = "8080"
LazyPrincessBot.start()
loop = asyncio.get_event_loop()

def __init__(self):
super().__init__(
name=SESSION,
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
workers=50,
plugins={"root": "plugins"},
sleep_threshold=5,
)

async def start(self):
b_users, b_chats = await db.get_banned()
temp.BANNED_USERS = b_users
temp.BANNED_CHATS = b_chats
await super().start()
await Media.ensure_indexes()
me = await self.get_me()
temp.ME = me.id
temp.U_NAME = me.username
temp.B_NAME = me.first_name
self.username = '@' + me.username
app = web.AppRunner(await web_server())
await app.setup()
bind_address = "0.0.0.0"
await web.TCPSite(app, bind_address, PORT).start()
logging.info(f"{me.first_name} with for Pyrogram v{__version__} (Layer {layer}) started on {me.username}.")
logging.info(LOG_STR)

async def stop(self, *args):
await super().stop()
logging.info("Bot stopped. Bye.")

async def iter_messages(
self,
chat_id: Union[int, str],
limit: int,
offset: int = 0,
) -> Optional[AsyncGenerator["types.Message", None]]:
"""Iterate through a chat sequentially.
This convenience method does the same as repeatedly calling :meth:`~pyrogram.Client.get_messages` in a loop, thus saving
you from the hassle of setting up boilerplate code. It is useful for getting the whole chat messages with a
single call.
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
For your personal cloud (Saved Messages) you can simply use "me" or "self".
For a contact that exists in your Telegram address book you can use his phone number (str).
limit (``int``):
Identifier of the last message to be returned.
offset (``int``, *optional*):
Identifier of the first message to be returned.
Defaults to 0.
Returns:
``Generator``: A generator yielding :obj:`~pyrogram.types.Message` objects.
Example:
.. code-block:: python
for message in app.iter_messages("pyrogram", 1, 15000):
print(message.text)
"""
current = offset
while True:
new_diff = min(200, limit - current)
if new_diff <= 0:
return
messages = await self.get_messages(chat_id, list(range(current, current+new_diff+1)))
for message in messages:
yield message
current += 1
# async def iter_messages(
# client,
# chat_id: Union[int, str],
# limit: int,
# offset: int = 0,
# ) -> Optional[AsyncGenerator["types.Message", None]]:
# """Iterate through a chat sequentially.
# This convenience method does the same as repeatedly calling :meth:`~pyrogram.Client.get_messages` in a loop, thus saving
# you from the hassle of setting up boilerplate code. It is useful for getting the whole chat messages with a
# single call.
# Parameters:
# client (:obj:`pyrogram.Client`):
# The Pyrogram client instance.

# chat_id (``int`` | ``str``):
# Unique identifier (int) or username (str) of the target chat.
# For your personal cloud (Saved Messages) you can simply use "me" or "self".
# For a contact that exists in your Telegram address book you can use his phone number (str).

# limit (``int``):
# Identifier of the last message to be returned.

# offset (``int``, *optional*):
# Identifier of the first message to be returned.
# Defaults to 0.
# Returns:
# ``Generator``: A generator yielding :obj:`~pyrogram.types.Message` objects.
# Example:
# .. code-block:: python
# for message in iter_messages(client, "pyrogram", 1, 15000):
# print(message.text)
# """
# current = offset
# while True:
# new_diff = min(200, limit - current)
# if new_diff <= 0:
# return
# messages = await client.get_messages(chat_id, list(range(current, current + new_diff + 1)))
# for message in messages:
# yield message
# current += 1

async def Lazy_start():
print('\n')
print(' Initalizing Telegram Bot ')
bot_info = await LazyPrincessBot.get_me()
LazyPrincessBot.username = bot_info.username
await initialize_clients()
if ON_HEROKU:
asyncio.create_task(ping_server())
b_users, b_chats = await db.get_banned()
temp.BANNED_USERS = b_users
temp.BANNED_CHATS = b_chats
await Media.ensure_indexes()
me = await LazyPrincessBot.get_me()
temp.ME = me.id
temp.U_NAME = me.username
temp.B_NAME = me.first_name
LazyPrincessBot.username = '@' + me.username
app = web.AppRunner(await web_server())
await app.setup()
bind_address = "0.0.0.0" if ON_HEROKU else BIND_ADRESS
await web.TCPSite(app, bind_address, PORT).start()
logging.info(f"{me.first_name} with for Pyrogram v{__version__} (Layer {layer}) started on {me.username}.")
logging.info(LOG_STR)
await idle()

app = Bot()
app.run()
if __name__ == '__main__':
try:
loop.run_until_complete(Lazy_start())
except KeyboardInterrupt:
logging.info('----------------------- Service Stopped -----------------------')
65 changes: 58 additions & 7 deletions info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from os import environ
from os import getenv, environ

id_pattern = re.compile(r'^.\d+$')
def is_enabled(value, default):
Expand Down Expand Up @@ -63,25 +63,69 @@ def is_enabled(value, default):
REQ_CHANNEL = int(environ.get('REQ_CHANNEL'))

#ai
AI = is_enabled((environ.get("AI","True")), False)
OPENAI_API = environ.get("OPENAI_API","")
AI = is_enabled((environ.get("AI","True")), False)
LAZY_AI_LOGS = int(environ.get("LAZY_AI_LOGS","")) #GIVE YOUR NEW LOG CHANNEL ID TO STORE MESSAGES THAT THEY SEARCH IN BOT PM.... [ i have added this to keep an eye on the users message, to avoid misuse of LazyPrincess ]
# Requested Content template variables ---
ADMIN_USRNM = environ.get('ADMIN_USRNM','real_heros') # WITHOUT @
MAIN_CHANNEL_USRNM = environ.get('MAIN_CHANNEL_USRNM','Channel_UserName') # WITHOUT @
MAIN_CHANNEL_USRNM = environ.get('MAIN_CHANNEL_USRNM','@real_MoviesAdda2') # WITHOUT @
DEV_CHANNEL_USRNM = environ.get('DEV_CHANNEL_USRNM','LayDeveloperr') # WITHOUT @
LAZY_YT_HANDLE = environ.get('LAZY_YT_HANDLE','LayDeveloperr') # WITHOUT @ [ add only handle - don't add full url ]
MOVIE_GROUP_USERNAME = environ.get('MOVIE_GROUP_USERNAME', "+qAxoGBvSc34yNmU1") #[ without @ ]

# Url Shortner
URL_MODE = is_enabled((environ.get("URL_MODE","True")), False)
URL_SHORTENR_WEBSITE = environ.get('URL_SHORTENR_WEBSITE', 'omegalinks.in') #Always use website url from api section
URL_SHORTNER_WEBSITE_API = environ.get('URL_SHORTNER_WEBSITE_API', '3e3ea22a23eecb70d24ab987ccdc596efb72f9a8')
URL_SHORTENR_WEBSITE = environ.get('URL_SHORTENR_WEBSITE', '') #Always use website url from api section
URL_SHORTNER_WEBSITE_API = environ.get('URL_SHORTNER_WEBSITE_API', '')
LZURL_PRIME_USERS = [int(lazyurlers) if id_pattern.search(lazyurlers) else lazyurlers for lazyurlers in environ.get('LZURL_PRIME_USERS', '5965340120').split()]
lazy_groups = environ.get('LAZY_GROUPS','')
LAZY_GROUPS = [int(lazy_groups) for lazy_groups in lazy_groups.split()] if lazy_groups else None # ADD GROUP ID IN THIS VARIABLE
my_users = [int(my_users) if id_pattern.search(my_users) else my_users for my_users in environ.get('MY_USERS', '').split()]
MY_USERS = (my_users) if my_users else []



# Online Stream and Download
PORT = int(environ.get('PORT', 8080))
NO_PORT = bool(environ.get('NO_PORT', False))
APP_NAME = None
if 'DYNO' in environ:
ON_HEROKU = True
APP_NAME = environ.get('APP_NAME')
else:
ON_HEROKU = False
BIND_ADRESS = str(getenv('WEB_SERVER_BIND_ADDRESS', '0.0.0.0'))
FQDN = str(getenv('FQDN', BIND_ADRESS)) if not ON_HEROKU or getenv('FQDN') else APP_NAME+'.herokuapp.com'
URL = "https://{}/".format(FQDN) if ON_HEROKU or NO_PORT else \
"http://{}:{}/".format(FQDN, PORT)
SLEEP_THRESHOLD = int(environ.get('SLEEP_THRESHOLD', '60'))
WORKERS = int(environ.get('WORKERS', '4'))
SESSION_NAME = str(environ.get('SESSION_NAME', 'LazyBot'))
MULTI_CLIENT = False
name = str(environ.get('name', 'LazyPrincess'))
PING_INTERVAL = int(environ.get("PING_INTERVAL", "1200")) # 20 minutes
if 'DYNO' in environ:
ON_HEROKU = True
APP_NAME = str(getenv('APP_NAME'))

else:
ON_HEROKU = False
HAS_SSL=bool(getenv('HAS_SSL',False))
if HAS_SSL:
URL = "https://{}/".format(FQDN)
else:
URL = "http://{}/".format(FQDN)
UPDATES_CHANNEL = str(getenv('UPDATES_CHANNEL', None))
BANNED_CHANNELS = list(set(int(x) for x in str(getenv("BANNED_CHANNELS", "-1001987654567")).split()))
OWNER_USERNAME = "LazyDeveloper"



# Auto Delete For Group Message (Self Delete) #
SELF_DELETE_SECONDS = int(environ.get('SELF_DELETE_SECONDS', 180))
SELF_DELETE = is_enabled((environ.get('SELF_DELETE','True')), False)
SELF_DELETE_SECONDS = int(environ.get('SELF_DELETE_SECONDS', 300))
SELF_DELETE = environ.get('SELF_DELETE', True)
if SELF_DELETE == "True":
SELF_DELETE = True

# Download Tutorial Button #
DOWNLOAD_TEXT_NAME = "πŸ“₯ HOW TO DOWNLOAD πŸ“₯"
Expand All @@ -100,3 +144,10 @@ def is_enabled(value, default):
LOG_STR += ("Spell Check Mode Is Enabled, bot will be suggesting related movies if movie not found\n" if SPELL_CHECK_REPLY else "SPELL_CHECK_REPLY Mode disabled\n")
LOG_STR += (f"MAX_LIST_ELM Found, long list will be shortened to first {MAX_LIST_ELM} elements\n" if MAX_LIST_ELM else "Full List of casts and crew will be shown in imdb template, restrict them by adding a value to MAX_LIST_ELM\n")
LOG_STR += f"Your current IMDB template is {IMDB_TEMPLATE}"
# Credit @LazyDeveloper.
# Please Don't remove credit.
# Born to make history @LazyDeveloper !
# Thank you LazyDeveloper for helping us in this Journey
# πŸ₯° Thank you for giving me credit @LazyDeveloperr πŸ₯°
# for any error please contact me -> telegram@LazyDeveloperr or insta @LazyDeveloperr
# rip paid developers 🀣 - >> No need to buy paid source code while @LazyDeveloperr is here 😍😍
Loading

0 comments on commit 225954e

Please sign in to comment.