Skip to content

Commit

Permalink
new updated files uploaded✨
Browse files Browse the repository at this point in the history
removed callback error fixed database.py and much more
  • Loading branch information
GamingBeast1 authored Feb 23, 2024
1 parent 2182ac3 commit 52e6a05
Show file tree
Hide file tree
Showing 23 changed files with 2,512 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.8-slim-buster

RUN apt update && apt upgrade -y
RUN apt install git -y
COPY requirements.txt /requirements.txt

RUN cd /
RUN pip3 install -U pip && pip3 install -U -r requirements.txt
RUN mkdir /fwdbot
WORKDIR /fwdbot
COPY start.sh /start.sh
CMD ["/bin/bash", "/start.sh"]
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker: python3 main.py
52 changes: 52 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "Auto-Forward-Bot-V2",
"description": "Telegram's Best Smart Plugin File Forward Bot",
"logo": "https://telegra.ph/file/5c3499c3b2ec282cf0c4e.jpg",
"stack": "container",
"keywords": [
"telegram",
"best",
"file",
"forward",
"bot"
],
"success_url": "https://t.me/DForDarkAngel",
"website": "https://github.com/SadKidBGMZ/fwdbot",
"repository": "https://github.com/SadKidBGMZ/fwdbot",
"env": {
"API_ID": {
"description": "Get this value from https://my.telegram.org or @UseTGSBot",
"required": true
},
"API_HASH": {
"description": "Get this value from https://my.telegram.org or @UseTGSBot",
"required": true
},
"BOT_TOKEN": {
"description": "Your bot token from @BotFather",
"required": true
},
"BOT_OWNER_ID": {
"description": "Enter Your Telegram id",
"required": true
},
"BANNED_USERS": {
"description": "If you want to add a caption to the forwarded file, enter it here",
"required": false
},
"DATABASE_NAME": {
"description": "Type Of filters (document , audio , photo , video , animation)",
"required": true
},
"DATABASE_URI": {
"description": "Pyrogram string Seccion - https://replit.com/@JijinR/PyroSessionString?v=1",",
"required": true
}
},
"formation": {
"worker": {
"quantity": 1,
"size": "free"
}
}
}
64 changes: 64 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import asyncio
import logging
from asyncio import coroutines
import logging.config
from database import db
from config import Config
from pyropatch import listen
from pyrogram import Client, __version__
from pyrogram.raw.all import layer
from pyrogram.enums import ParseMode
from pyrogram.errors import FloodWait

logging.config.fileConfig('logging.conf')
logging.getLogger().setLevel(logging.INFO)
logging.getLogger("pyrogram").setLevel(logging.ERROR)

class Bot(Client):
def __init__(self):
super().__init__(
Config.BOT_SESSION,
api_hash=Config.API_HASH,
api_id=Config.API_ID,
plugins={
"root": "plugins"
},
workers=50,
bot_token=Config.BOT_TOKEN
)
self.log = logging

async def start(self):
await super().start()
me = await self.get_me()
logging.info(f"{me.first_name} with for Pyrogram v{__version__} (Layer {layer}) started on @{me.username}.")
self.id = me.id
self.username = me.username
self.first_name = me.first_name
self.set_parse_mode(ParseMode.DEFAULT)
text = "**๏[-ิ_•ิ]๏ bot restarted !**"
logging.info(text)
success = failed = 0
users = await db.get_all_frwd()
async for user in users:
chat_id = user['user_id']
try:
await self.send_message(chat_id, text)
success += 1
except FloodWait as e:
await asyncio.sleep(e.value + 1)
await self.send_message(chat_id, text)
success += 1
except Exception:
failed += 1
# await self.send_message("venombotsupport", text)
if (success + failed) != 0:
await db.rmve_frwd(all=True)
logging.info(f"Restart message status"
f"success: {success}"
f"failed: {failed}")

async def stop(self, *args):
msg = f"@{self.username} stopped. Bye."
await super().stop()
logging.info(msg)
18 changes: 18 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from os import environ

class Config:
API_ID = int(environ.get("API_ID", ""))
API_HASH = environ.get("API_HASH", "")
BOT_TOKEN = environ.get("BOT_TOKEN", "")
BOT_SESSION = environ.get("BOT_SESSION", "bot")
DATABASE_URI = environ.get("DATABASE_URI", "")
DATABASE_NAME = environ.get("DATABASE_NAME", "")
BOT_OWNER_ID = [int(id) for id in environ.get("BOT_OWNER_ID", '').split()]

class temp(object):
lock = {}
CANCEL = {}
forwardings = 0
BANNED_USERS = []
IS_FRWD_CHAT = []

161 changes: 161 additions & 0 deletions database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
from os import environ
from config import Config
import motor.motor_asyncio

class Database:

def __init__(self, uri, database_name):
self._client = motor.motor_asyncio.AsyncIOMotorClient(uri)
self.db = self._client[database_name]
self.bot = self.db.bots
self.col = self.db.users
self.nfy = self.db.notify
self.chl = self.db.channels

def new_user(self, id, name):
return dict(
id = id,
name = name,
ban_status=dict(
is_banned=False,
ban_reason="",
),
)

async def add_user(self, id, name):
user = self.new_user(id, name)
await self.col.insert_one(user)

async def is_user_exist(self, id):
user = await self.col.find_one({'id':int(id)})
return bool(user)

async def total_users_bots_count(self):
bcount = await self.bot.count_documents({})
count = await self.col.count_documents({})
return count, bcount

async def remove_ban(self, id):
ban_status = dict(
is_banned=False,
ban_reason=''
)
await self.col.update_one({'id': id}, {'$set': {'ban_status': ban_status}})

async def ban_user(self, user_id, ban_reason="No Reason"):
ban_status = dict(
is_banned=True,
ban_reason=ban_reason
)
await self.col.update_one({'id': user_id}, {'$set': {'ban_status': ban_status}})

async def get_ban_status(self, id):
default = dict(
is_banned=False,
ban_reason=''
)
user = await self.col.find_one({'id':int(id)})
if not user:
return default
return user.get('ban_status', default)

async def get_all_users(self):
return self.col.find({})

async def delete_user(self, user_id):
await self.col.delete_many({'id': int(user_id)})

async def get_banned(self):
users = self.col.find({'ban_status.is_banned': True})
b_users = [user['id'] async for user in users]
return b_users

async def update_configs(self, id, configs):
await self.col.update_one({'id': int(id)}, {'$set': {'configs': configs}})

async def get_configs(self, id):
default = {
'caption': None,
'duplicate': True,
'forward_tag': False,
'file_size': 0,
'size_limit': None,
'extension': None,
'keywords': None,
'protect': None,
'button': None,
'db_uri': None,
'filters': {
'poll': True,
'text': True,
'audio': True,
'voice': True,
'video': True,
'photo': True,
'document': True,
'animation': True,
'sticker': True
}
}
user = await self.col.find_one({'id':int(id)})
if user:
return user.get('configs', default)
return default

async def add_bot(self, datas):
if not await self.is_bot_exist(datas['user_id']):
await self.bot.insert_one(datas)

async def remove_bot(self, user_id):
await self.bot.delete_many({'user_id': int(user_id)})

async def get_bot(self, user_id: int):
bot = await self.bot.find_one({'user_id': user_id})
return bot if bot else None

async def is_bot_exist(self, user_id):
bot = await self.bot.find_one({'user_id': user_id})
return bool(bot)

async def in_channel(self, user_id: int, chat_id: int) -> bool:
channel = await self.chl.find_one({"user_id": int(user_id), "chat_id": int(chat_id)})
return bool(channel)

async def add_channel(self, user_id: int, chat_id: int, title, username):
channel = await self.in_channel(user_id, chat_id)
if channel:
return False
return await self.chl.insert_one({"user_id": user_id, "chat_id": chat_id, "title": title, "username": username})

async def remove_channel(self, user_id: int, chat_id: int):
channel = await self.in_channel(user_id, chat_id )
if not channel:
return False
return await self.chl.delete_many({"user_id": int(user_id), "chat_id": int(chat_id)})

async def get_channel_details(self, user_id: int, chat_id: int):
return await self.chl.find_one({"user_id": int(user_id), "chat_id": int(chat_id)})

async def get_user_channels(self, user_id: int):
channels = self.chl.find({"user_id": int(user_id)})
return [channel async for channel in channels]

async def get_filters(self, user_id):
filters = []
filter = (await self.get_configs(user_id))['filters']
for k, v in filter.items():
if v == False:
filters.append(str(k))
return filters

async def add_frwd(self, user_id):
return await self.nfy.insert_one({'user_id': int(user_id)})

async def rmve_frwd(self, user_id=0, all=False):
data = {} if all else {'user_id': int(user_id)}
return await self.nfy.delete_many(data)

async def get_all_frwd(self):
return self.nfy.find({})

db = Database(Config.DATABASE_URI, Config.DATABASE_NAME)
3 changes: 3 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
docker:
worker: Dockerfile
32 changes: 32 additions & 0 deletions logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[loggers]
keys=root

[handlers]
keys=consoleHandler,fileHandler

[formatters]
keys=consoleFormatter,fileFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler,fileHandler

[handler_consoleHandler]
class=StreamHandler
level=INFO
formatter=consoleFormatter
args=(sys.stdout,)

[handler_fileHandler]
class=FileHandler
level=ERROR
formatter=fileFormatter
args=('TelegramBot.log','w',)

[formatter_consoleFormatter]
format=%(asctime)s - %(lineno)d - %(name)s - %(module)s - %(levelname)s - %(message)s
datefmt=%I:%M:%S %p

[formatter_fileFormatter]
format=[%(asctime)s:%(name)s:%(lineno)d:%(levelname)s] %(message)s
datefmt=%m/%d/%Y %I:%M:%S %p
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from bot import Bot

app = Bot()
app.run()
1 change: 1 addition & 0 deletions plugins/Galaxy_Bots
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 52e6a05

Please sign in to comment.