Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated python, pyrogram version and improvement in code #11

Merged
merged 10 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 15 additions & 19 deletions Plugins/commands.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)


import pyrogram
from pyrogram import filters
from bot import channelforward
from config import Config
from translation import Translation


########################################################################################################################################################################################################
################################################################################################################################################################################################################################################
# start command

@channelforward.on_message(filters.command(["start"]))
async def start(c, m):
await c.send_message(chat_id=m.chat.id,
text=Translation.START,
parse_mode="html",
disable_web_page_preview=True,
reply_to_message_id=m.message_id)
@channelforward.on_message(filters.command("start") & filters.private & filters.incoming)
async def start(client, message):
await message.reply(
text=Translation.START,
disable_web_page_preview=True,
quote=True
)

################################################################################################################################################################################################################################################
# about command

@channelforward.on_message(filters.command(["about"]))
async def about(c, m):
await c.send_message(chat_id=m.chat.id,
text=Translation.ABOUT,
parse_mode="html",
disable_web_page_preview=True,
reply_to_message_id=m.message_id)
@channelforward.on_message(filters.command("about") & filters.private & filters.incoming)
async def about(client, message):
await message.reply(
text=Translation.ABOUT,
disable_web_page_preview=True,
quote=True
)

################################################################################################################################################################################################################################################
22 changes: 12 additions & 10 deletions Plugins/forward.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

import asyncio
from pyrogram import filters
from bot import channelforward
from config import Config


@channelforward.on_message(filters.channel)
async def forward(c, m):
async def forward(client, message):
# Forwarding the messages to the channel

for id in Config.CHANNEL:
from_channel, to_channel = id.split(":")
if m.chat.id == int(from_channel):
await m.forward(int(to_channel), as_copy=True)
print("Forwarded a message from", from_channel, "to", to_channel)
asyncio.sleep(1)
try:
for id in Config.CHANNEL:
from_channel, to_channel = id.split(":")
if m.chat.id == int(from_channel):
func = message.copy if AS_COPY else message.forward
await func(int(to_channel), as_copy=True)
logger.info("Forwarded a message from", from_channel, "to", to_channel)
await asyncio.sleep(1)
except Exception as e:
logger.exception(e)
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
## CHANNEL AUTO FORWARD
This repo is the clone of [CHANNEL AUTOMATIC NS BOT](https://telegram.dog/Autoforward_Nsbot)

**NOTE:** There is more difference between my bot and this repo. But the purposes is same

# CHANNEL AUTO FORWARD
A Simple telegram bot written in python to forward your files from one channel to other channel when a new post is available. What you need to do is just deploy this code.

[![Open Source? Yes!](https://badgen.net/badge/Open%20Source%20%3F/Yes%21/blue?icon=github)](https://github.com/Ns-AnoNymouS/TG-CONVERT-BOT/tree/main)
[![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg)](https://telegram.dog/Ns_AnoNymouS)

## How to Deploy? 🤔
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/Ns-AnoNymouS/auto-caption-bot/tree/main)
- 👆 Press the deploy button.
You can deploy this code any where you want but we provided heroku and railway deploy methods below

- Select one of the methods
- [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/Ns-AnoNymouS/auto-caption-bot)

- [![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/wEf927)

- Go to [my.telegram.org](https://my.telegram.org/)
- And get your API ID
Expand All @@ -24,9 +25,9 @@ This repo is the clone of [CHANNEL AUTOMATIC NS BOT](https://telegram.dog/Autofo

- Get the Bot Father Token from [@BotFather](https://telegram.dog/botfather)

- Paste the token below TG_BOT_TOKEN.

- Paste the token below BOT_TOKEN.

- Set AS_COPY value to True if you want to forward messages without forward tag.


## How to reach Me ?
Expand Down
80 changes: 34 additions & 46 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
{
"name": "Channel Auto forward bot",
"description": "Telegram auto forwarding bot. Create your Fork now.",
"keywords": [
"telegram",
"best",
"forward"
],
"logo": "https://telegra.ph/file/5b5dd216d70b29c80e25e.jpg",
"success_url": "https://telegram.dog/Autoforward_Nsbot",
"website": "https://github.com/Ns-AnoNymouS/TG-CONVERT-BOT",
"repository": "https://github.com/Ns-AnoNymouS/TG-CONVERT-BOT",
"env": {
"WEBHOOK": {
"description": "Setting this to ANYTHING will enable webhooks when in env mode",
"value": "ANYTHING"
"name": "Channel Auto forward bot",
"description": "Telegram auto forwarding bot. Create your Fork now.",
"keywords": [
"telegram",
"simple",
"auto",
"forward"
],
"logo": "https://telegra.ph/file/5b5dd216d70b29c80e25e.jpg",
"success_url": "https://telegram.dog/Autoforward_Nsbot",
"repository": "https://github.com/Ns-AnoNymouS/Auto-Forward-Bot",
"env": {
"AS_COPY": {
"description": "set this to true to forward message as copy",
"value": "False"
},
"API_HASH": {
"description": "Get this value from https://my.telegram.org",
"value": ""
},
"API_ID": {
"description": "Get this value from https://my.telegram.org",
"value": ""
},
"BOT_TOKEN": {
"description": "Your bot token, as a string. Get this from @BotFather",
"value": ""
},
"CHANNEL_ID": {
"description": "your channel id in format -10023352648:-100655379 (from channel id:to channel id) if you want to give more channels seperate them with white space",
"value": ""
}
},
"TG_BOT_TOKEN": {
"description": "Your bot token, as a string.",
"value": ""
},
"APP_ID": {
"description": "Get this value from https://my.telegram.org",
"value": ""
},
"CHANNEL_ID": {
"description": "your channel id in format -12352626:-34466(from channel id:to channel id) if you want to give more channels seperate them with white space",
"value": ""
},
"API_HASH": {
"description": "Get this value from https://my.telegram.org",
"value": ""
}
},
"addons": [
],
"buildpacks": [{
"url": "https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest"
}, {
"url": "heroku/python"
}],
"formation": {
"worker": {
"quantity": 1,
"size": "free"
}
}
}
"buildpacks": [{"url": "heroku/python"}]
}
45 changes: 26 additions & 19 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import pyrogram

import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

import os
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(lineno)d - %(module)s - %(levelname)s - %(message)s'
)
logging.getLogger().setLevel(logging.INFO)
logging.getLogger("pyrogram").setLevel(logging.WARNING)

import uvloop
uvloop.install()
from config import Config
from pyrogram import Client
logging.getLogger("pyrogram").setLevel(logging.WARNING)

class channelforward(Client):

class channelforward(Client, Config):
def __init__(self):
super().__init__(
session_name="CHANNELFORWARD",
bot_token = Config.BOT_TOKEN,
api_id = Config.API_ID,
api_hash = Config.API_HASH,
workers = 20,
plugins = dict(
root="Plugins"
)
name="CHANNELFORWARD",
bot_token=self.BOT_TOKEN,
api_id=self.API_ID,
api_hash=self.API_HASH,
workers=20,
plugins={'root': 'Plugins'}
)

async def start(self):
await super().start()
me = await self.get_me()
print(f"New session started for {me.first_name}({me.username})")

async def stop(self):
await super().stop()
print("Session stopped. Bye!!")


if __name__ == "__main__" :
channelforward().run()

11 changes: 6 additions & 5 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from os import getenv

class Config(object):
BOT_TOKEN = os.environ.get("TG_BOT_TOKEN", "")
API_ID = int(os.environ.get("APP_ID", 12345))
API_HASH = os.environ.get("API_HASH")
CHANNEL = list(x for x in os.environ.get("CHANNEL_ID", "").replace("\n", " ").split(' '))
API_HASH = getenv("API_HASH")
API_ID = int(getenv("API_ID", 0))
AS_COPY = True if getenv("AS_COPY", False) == "True" else False
BOT_TOKEN = getenv("BOT_TOKEN", "")
CHANNEL = list(x for x in getenv("CHANNEL_ID", "").replace("\n", " ").split(' '))
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
https://github.com/Mahesh0253/pyrogram/archive/beta.zip
uvloop
tgcrypto
pyrogram~=2.0.59
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.8.6
python-3.11.0