From 5be47c010035bac4d61ee51f0cbd63490da866f6 Mon Sep 17 00:00:00 2001 From: Ara0n Date: Fri, 7 Jan 2022 03:24:12 +0530 Subject: [PATCH] base commit at 3am --- .gitignore | 4 +++ Pipfile | 27 +++++++++++++++++ README.md | 6 ++++ bot/bot.py | 66 ++++++++++++++++++++++++++++++++++++++++ requirments.txt | 16 ++++++++++ uploader/uploader.py | 71 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 190 insertions(+) create mode 100644 .gitignore create mode 100644 Pipfile create mode 100644 README.md create mode 100644 bot/bot.py create mode 100644 requirments.txt create mode 100644 uploader/uploader.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b24a9c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +botConfig.json +*.session +agentConfig.json +images \ No newline at end of file diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..b987ecb --- /dev/null +++ b/Pipfile @@ -0,0 +1,27 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +python-telegram-bot = "==13.10" +telegramclient = "*" +telethon = "==1.24.0" +backports-zoneinfo = "==0.2.1" +cachetools = "==4.2.2" +certifi = "==2021.10.8" +pyaes = "==1.6.1" +pyasn1 = "==0.4.8" +pytz = "==2021.3" +pytz-deprecation-shim = "==0.1.0.post0" +rsa = "==4.8" +six = "==1.16.0" +tornado = "==6.1" +tzdata = "==2021.5" +tzlocal = "==4.1" +APScheduler = "==3.6.3" + +[requires] +python_version = "3.8" diff --git a/README.md b/README.md new file mode 100644 index 0000000..50b34bb --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Araon-Chan + +## About +Telegram bot to search and download anime from various websites. + + diff --git a/bot/bot.py b/bot/bot.py new file mode 100644 index 0000000..2790706 --- /dev/null +++ b/bot/bot.py @@ -0,0 +1,66 @@ +import logging +import json +from telegram.ext import Updater, CommandHandler, MessageHandler, Filters +from telegram.update import Update + +#enabling Logging + +logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) +logger = logging.getLogger(__name__) + +with open('botConfig.json', 'r') as config: + configdata = json.load(config) + +API_TOKEN = configdata.get("bot_token") + +def start(update, context): + """Send a message when the command /start is issued.""" + update.message.reply_text('Hi!') + + +def help(update, context): + """Send a message when the command /help is issued.""" + update.message.reply_text('Help!') + + +def echo(update, context): + """Echo the user message.""" + update.message.reply_text((update.message.text).upper()) + +def search(update, context): + logger.info('Search function is called!') + update.message.reply_text('Searching....') + +def download(update, context): + logger.info('download function is called!') + update.message.reply_text('Downloading!') + + +def error(update, context): + """Log Errors caused by Updates.""" + logger.warning('Update "%s" caused error "%s"', update, context.error) + + +def main(): + + updater = Updater(token=API_TOKEN, use_context=True) + + # Get the dispatcher to register handlers + dp = updater.dispatcher + + # on different commands - answer in Telegram + dp.add_handler(CommandHandler("start", start)) + dp.add_handler(CommandHandler("help", help)) + dp.add_handler(CommandHandler("search", search)) + dp.add_handler(CommandHandler("download", download)) + + dp.add_handler(MessageHandler(Filters.text, echo)) + + dp.add_error_handler(error) + + updater.start_polling() + updater.idle() + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/requirments.txt b/requirments.txt new file mode 100644 index 0000000..b93f13e --- /dev/null +++ b/requirments.txt @@ -0,0 +1,16 @@ +APScheduler==3.6.3 +backports.zoneinfo==0.2.1 +cachetools==4.2.2 +certifi==2021.10.8 +pyaes==1.6.1 +pyasn1==0.4.8 +python-telegram-bot==13.10 +pytz==2021.3 +pytz-deprecation-shim==0.1.0.post0 +rsa==4.8 +six==1.16.0 +Telethon==1.24.0 +tornado==6.1 +tzdata==2021.5 +tzlocal==4.1 +telethon==1.24.0 \ No newline at end of file diff --git a/uploader/uploader.py b/uploader/uploader.py new file mode 100644 index 0000000..1eeebeb --- /dev/null +++ b/uploader/uploader.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +#https://sudonull.com/post/62683-Telegram-bots-Uploading-files-larger-than-50mb +''' +The function of this uploader is to upload a given file to @animedatabase_bot +and get the file_id from the the uploaded file. + +fun facts i just came accross + +the .send_file() function will have to send the file to the bot itself +Just uploading the file to the server via upload , getting file_id and passing it to the bot will not work, +file_id only works inside the chat in which it was created - +so that our bot can send the file to the user by file_id - +the agent must send him this file +then the bot will receive own file_id for this file and will be able to dispose of it. + +''' +from telethon import TelegramClient +from telethon.tl.types import DocumentAttributeVideo +import asyncio +import json + + +with open('config/agentConfig.json', 'r') as config: + configdata = json.load(config) + +entity = configdata.get('entity') #session name - it doesn't matter what +api_id = configdata.get('api_id') +api_hash = configdata.get('api_hash') +phone = configdata.get('phone') + +bot_name = configdata.get('bot_name') + + +# if not client.is_user_authorized(): +# #client.send_code_request(phone) #at the first start - uncomment, after authorization to avoid FloodWait I advise you to comment +# client.sign_in(phone, input('Enter code: ')) + + +def callback(current, total): + print('Uploaded: {:.2%}'.format(current / total)) + +async def uploadVideo(bot_name,file_path,file_name,chat_id,object_id): + async with TelegramClient(entity, api_id, api_hash) as client: + await client.send_file( + str(bot_name), + file_path, + caption=str(chat_id + ':' + object_id + ':' + file_name), + attributes=[DocumentAttributeVideo(0,0,0)], + progress_callback=callback, + part_size_kb=512, + supports_streaming=True, + ) + await client.disconnect() + return 0 + +async def main(argv): + file_path = argv[1] + file_name = argv[2] + chat_id = argv[3] + object_id = argv[4] + + + await uploadVideo(bot_name,file_path,file_name,chat_id,object_id) + + + +if __name__ == '__main__': + import sys + asyncio.run(main()) + +# python uploader.py rainfall.mp4 rainfall chat_id narutos1ep34 \ No newline at end of file