all repos — gif-escarbot @ 128ac99d74edbf9fd72470d2f2f39c35e988f98c

Earthbound Café's custom delivery bot with other cool utilities built-in.

initial commit
Marco Andronaco andronacomarco@gmail.com
Sat, 24 Jun 2023 12:02:26 +0200
commit

128ac99d74edbf9fd72470d2f2f39c35e988f98c

4 files changed, 48 insertions(+), 0 deletions(-)

jump to
A .env.example

@@ -0,0 +1,3 @@

+token= +group_id= +channel_id=
A .gitignore

@@ -0,0 +1,2 @@

+.env +venv
A main.py

@@ -0,0 +1,34 @@

+from telegram.ext import MessageHandler, ApplicationBuilder, filters +from telegram import Update +import logging, dotenv, os +dotenv.load_dotenv() +logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) +logger = logging.getLogger(__name__) + +async def forward(update: Update, _): + if update.effective_chat.id == CHANNEL_ID: + if update.channel_post is not None: + await update.channel_post.forward(GROUP_ID) + logger.info("Forwarded a message.") + +def err_missing_file(filename: str, exit_arg: int = 1): + + exit(exit_arg) + +if __name__ == "__main__": + + try: + TOKEN = str(os.getenv("token")) + GROUP_ID = int(os.getenv("group_id")) + CHANNEL_ID = int(os.getenv("channel_id")) + except TypeError: + logger.error(f"Please create and fill the following file: .env") + exit(1) + + if '' in [TOKEN, GROUP_ID, CHANNEL_ID]: + logger.error(f"Please fill the following file: .env") + exit(1) + + application = ApplicationBuilder().token(TOKEN).build() + application.add_handler(MessageHandler(filters.ChatType.CHANNEL, forward)) + application.run_polling()
A requirements.txt

@@ -0,0 +1,9 @@

+anyio==3.6.2 +certifi==2023.5.7 +h11==0.14.0 +httpcore==0.17.2 +httpx==0.24.1 +idna==3.4 +python-dotenv==1.0.0 +python-telegram-bot==20.3 +sniffio==1.3.0