import logging
import random
import requests
from telegram import Update, Bot
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, filters, CallbackContext
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO
)
logging.getLogger("httpx").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
MOVIE_API_URL = "https://xiaoapi.cn/API/jx_txsp.php"
PAN_API_URL = "https://www.hhlqilongzhu.cn/api/ziyuan_nanfeng.php"
async def get_movie_data(update: Update, context: ContextTypes.DEFAULT_TYPE):
movie_url = update.message.text
response = requests.get(MOVIE_API_URL, params=movie_url)
if response.status_code == 200:
movie_info = response.json()
if movie_info and 'title' in movie_info:
await update.message.reply_text("解析成功啦!")
await update.message.reply_text(
"点击这里访问 [" + movie_info['title'] + "]" + "(" + movie_info['url'] + ")", parse_mode='Markdown')
else:
await update.message.reply_text("抱歉,没有找到相关的影片解析信息。")
else:
await update.message.reply_text("无法连接到电影API接口。")
async def get_movieName_data(update: Update, context: ContextTypes.DEFAULT_TYPE):
movie_name = update.message.text
response = requests.get(PAN_API_URL, params={'keysearch': movie_name})
if response.status_code == 200:
movie_info = response.json()
if 'data' in movie_info:
await update.message.reply_text("获取资源成功" + "! 共找到" + str(movie_info['count']) + '条资源')
num = 0
mastext = []
for i in movie_info['data']:
num += 1
mastext.append(f"{num}:{i['title']}-({i['data_url']}) ")
await update.message.reply_text('\n'.join(mastext), parse_mode=None)
else:
await update.message.reply_text("抱歉,没有找到相关的影片信息。")
else:
await update.message.reply_text("无法连接到PAN_API_URL接口。")
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
'''响应start命令'''
text = '欢迎使用可搜机器人,您可以发送VIP视频链接给我解析'
await context.bot.send_message(chat_id=update.effective_chat.id, text=text)
async def help(update: Update, context: ContextTypes.DEFAULT_TYPE):
'''响应help命令'''
text = "=" * 5 + '开发者信息' + "=" * 5 + "\n" + "Developer:RenYuke"
await context.bot.send_message(chat_id=update.effective_chat.id, text=text)
async def ohayo(update: Update, context: ContextTypes.DEFAULT_TYPE):
'''随机消息'''
texts = ['早上好呀', '我的小鱼你醒了,还记得清晨吗', '哦哈哟~']
await context.bot.send_message(chat_id=update.effective_chat.id, text=random.choice(texts))
async def choose_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.message.text:
text = update.message.text
if text.startswith('https://'):
await get_movie_data(update, context)
else:
await get_movieName_data(update, context)
def main():
start_handler = CommandHandler('start', start)
help_handler = CommandHandler('help', help)
filter_ohayo = filters.Regex('早安|早上好|哦哈哟|ohayo|早')
ohayo_handler = MessageHandler(filter_ohayo, ohayo)
massage_handle = MessageHandler(filters.TEXT & ~filters.COMMAND, choose_handler)
TOKEN = 'YOUR TOKEN'
application = ApplicationBuilder().token(TOKEN).build()
application.add_handler(start_handler)
application.add_handler(help_handler)
application.add_handler(ohayo_handler)
application.add_handler(massage_handle)
application.run_polling()
if __name__ == '__main__':
main()
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.