base commit at 3am

This commit is contained in:
Ara0n 2022-01-07 03:24:12 +05:30
commit 5be47c0100
6 changed files with 190 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
botConfig.json
*.session
agentConfig.json
images

27
Pipfile Normal file
View File

@ -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"

6
README.md Normal file
View File

@ -0,0 +1,6 @@
# Araon-Chan
## About <a name = "about"></a>
Telegram bot to search and download anime from various websites.

66
bot/bot.py Normal file
View File

@ -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()

16
requirments.txt Normal file
View File

@ -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

71
uploader/uploader.py Normal file
View File

@ -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