Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
161ed14
Created All Files
Joelkb May 8, 2023
309e057
Create __init__.py
Joelkb May 8, 2023
3984b88
Add files via upload
Joelkb May 8, 2023
ba8dd17
Added deploy to render button
Joelkb May 8, 2023
efd135f
Added Logging
Joelkb May 8, 2023
4923a34
Added /logs
Joelkb May 8, 2023
3cc456d
Disable
Joelkb May 8, 2023
63ae3e9
Fix
Joelkb May 8, 2023
6848204
Update commands.py
Joelkb May 8, 2023
cbd82b1
Update commands.py
Joelkb May 8, 2023
3c6cc6a
Update commands.py
Joelkb May 8, 2023
8fb1c9f
Update commands.py
Joelkb May 8, 2023
705c6b2
Update commands.py
Joelkb May 8, 2023
2632cf0
Update commands.py
Joelkb May 8, 2023
fc8b5df
Fixed Bugs I guess
Joelkb May 8, 2023
e14ca05
Update commands.py
Joelkb May 8, 2023
b257212
Fix floodwait
Joelkb May 8, 2023
24972b0
Update callbacks.py
Joelkb May 8, 2023
d9e89e4
Added Skip Command for resuming stopped process
Joelkb May 8, 2023
17cc441
Some Improvements
Joelkb May 10, 2023
88efe8b
Fixes
Joelkb May 10, 2023
004d3d4
Few imporvements
Joelkb May 10, 2023
3fb020e
Merge branch 'web' of https://github.com/Joelkb/File-Forward-Bot into…
Joelkb May 10, 2023
abc0d76
Fixes
Joelkb May 10, 2023
64f07cc
Fix
Joelkb May 10, 2023
7dfc4c8
Fix error
Joelkb May 10, 2023
72f1158
Create app.json
Joelkb May 10, 2023
98e5cd4
Just a test Commit
Joelkb May 11, 2023
724a62f
Merge branch 'web' of https://github.com/Joelkb/File-Forward-Bot into…
Joelkb May 11, 2023
a364e69
Fix mistake
Joelkb May 11, 2023
cb4ad83
Debugging
Joelkb May 11, 2023
f75a950
Merge branch 'web' of https://github.com/Joelkb/File-Forward-Bot into…
Joelkb May 11, 2023
3868790
Fix error
Joelkb May 11, 2023
e5ecbef
Fix
Joelkb May 11, 2023
07ec41a
Fix
Joelkb May 11, 2023
2337d53
Debug
Joelkb May 11, 2023
503effd
Debug
Joelkb May 11, 2023
5b00b0a
Debug
Joelkb May 11, 2023
a2bfd1c
Fix
Joelkb May 11, 2023
ed1372f
Undo
Joelkb May 11, 2023
f2a5598
Some Fixes
Joelkb Jun 3, 2023
2ab3012
Fixes went wrong
Joelkb Jun 3, 2023
a858f06
Just a Try
Joelkb Jun 3, 2023
3d58927
Fix
Joelkb Jun 3, 2023
281f5ff
Fixes and improvements
Joelkb Jun 3, 2023
ea4a346
Update commands.py
Joelkb Jun 3, 2023
1f5bb5a
Changes
Joelkb Jan 6, 2024
2b2e545
Update Dockerfile
Muhammedhashirm009 Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.10.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 /ForwardBot
WORKDIR /ForwardBot
RUN python3 bot.py
678 changes: 339 additions & 339 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 @@
web: python3 bot.py
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# File-Forward-Bot
File-Forward-Bot
#Not Yet Completed !
<details><summary>Deploy To Render</summary>
<br>
<b>
Use these commands:
<br>
<br>
• Build Command: <code>pip3 install -U -r requirements.txt</code>
<br>
<br>
• Start Command: <code>python3 bot.py</code>
<br>
<br>
Go to https://uptimerobot.com/ and add a monitor to keep your bot alive.
<br>
<br>
Use these settings when adding a monitor:</b>
<br>
<br>
<img src="https://telegra.ph/file/a79a156e44f43c9833b50.jpg" alt="render template">
<br>
<br>
<b>Click on the below button to deploy directly to render ↓</b>
<br>
<br>
<a href="https://render.com/deploy?repo=https://github.com/Joelkb/File-Forward-Bot/tree/web">
<img src="https://render.com/images/deploy-to-render-button.svg" alt="Deploy to Render">
</a>
</details>
57 changes: 57 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "File-Forward-Bot",
"description": "Use this bot to forward all files from one channel to other even if its private or public.",
"stack": "container",
"keywords": [
"telegram",
"auto-forward-bot",
"forward-bot",
"forward",
"best",
"indian",
"pyrogram",
"media",
"export",
"channel",
"file-forward",
"media-forward"
],
"website": "https://github.com/Joelkb/File-Forward-Bot",
"repository": "https://github.com/Joelkb/File-Forward-Bot",
"env": {
"BOT_TOKEN": {
"description": "Your bot token.",
"required": true
},
"API_ID": {
"description": "Get this value from https://my.telegram.org",
"required": true
},
"API_HASH": {
"description": "Get this value from https://my.telegram.org",
"required": true
},
"TARGET_DB": {
"description": "ID of channel which you want the bot to send all files to.",
"required": true
},
"ADMINS": {
"description": "ID of Admin. Separate multiple Admins by space.",
"required": true
},
"LOG_CHANNEL": {
"description": "Bot Logs,Give a channel id with -100xxxxxxx",
"required": true
}
},
"addons": [],
"buildpacks": [{
"url": "heroku/python"
}],
"formation": {
"worker": {
"quantity": 1,
"size": "eco"
}
}
}
97 changes: 97 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from pyrogram import Client, __version__
from pyrogram.raw.all import layer
from datetime import date, datetime
from vars import SESSION, API_HASH, API_ID, BOT_TOKEN, LOG_CHANNEL, PORT
from typing import Union, Optional, AsyncGenerator
from script import scripts
from pyrogram import types
from utils import temp_utils
from aiohttp import web
from plugins import web_server
import logging
import pytz
import logging.config

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


class Bot(Client):

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):
await super().start()
me = await self.get_me()
temp_utils.ME = me.id
temp_utils.USER_NAME = me.username
temp_utils.BOT_NAME = me.first_name
self.username = '@' + me.username
logging.info(f"{me.first_name} with for Pyrogram v{__version__} (Layer {layer}) started on {me.username}.")
tz = pytz.timezone('Asia/Kolkata')
today = date.today()
now = datetime.now(tz)
time = now.strftime("%H:%M:%S %p")
await self.send_message(chat_id=LOG_CHANNEL, text=scripts.RESTART_TXT.format(today, time))
app = web.AppRunner(await web_server())
await app.setup()
bind_address = "0.0.0.0"
await web.TCPSite(app, bind_address, PORT).start()

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


app = Bot()
app.run()
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=('Logs.txt','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
8 changes: 8 additions & 0 deletions plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from aiohttp import web
from .route import routes


async def web_server():
web_app = web.Application(client_max_size=30000000)
web_app.add_routes(routes)
return web_app
63 changes: 63 additions & 0 deletions plugins/callbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from pyrogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup
from pyrogram import Client
from script import scripts
from utils import temp_utils
import logging
from .commands import start_forward

logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)

@Client.on_callback_query()
async def query_handler(bot: Client, query: CallbackQuery):
if query.data == "close":
await query.message.delete()
elif query.data == "about":
btn = [[
InlineKeyboardButton("Go Back", callback_data="home"),
InlineKeyboardButton("Close", callback_data="close")
]]
await query.message.edit_text(
text=scripts.ABOUT_TXT.format(temp_utils.BOT_NAME),
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(btn)
)
elif query.data == "home":
btn = [[
InlineKeyboardButton("About", callback_data="about"),
InlineKeyboardButton("Souce Code", callback_data="source")
],[
InlineKeyboardButton("Close", callback_data="close"),
InlineKeyboardButton("Help", callback_data="help")
]]
await query.message.edit_text(
text=scripts.START_TXT.format(query.from_user.mention, temp_utils.USER_NAME, temp_utils.BOT_NAME),
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(btn)
)
elif query.data == "source":
btn = [[
InlineKeyboardButton("Go Back", callback_data="home"),
InlineKeyboardButton("Close", callback_data="close")
]]
await query.message.edit_text(
text=scripts.SOURCE_TXT,
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(btn)
)
elif query.data == "cancel_forward":
temp_utils.CANCEL = True
elif query.data == "help":
btn = [[
InlineKeyboardButton("Go Back", callback_data="home"),
InlineKeyboardButton("Close", callback_data="close")
]]
await query.message.edit_text(
text=scripts.HELP_TXT.format(temp_utils.BOT_NAME),
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(btn)
)
elif query.data.startswith("forward"):
ident, source_chat_id, last_msg_id = query.data.split("#")
await query.message.delete()
await start_forward(bot, query.from_user.id, source_chat_id, last_msg_id)
Loading