Revert "refactor: extract userbot to standalone repo, add as git submodule"
This reverts commit 3c383db9a7.
This commit is contained in:
@@ -0,0 +1,230 @@
|
||||
import os
|
||||
|
||||
import aiofiles
|
||||
import requests
|
||||
from pyrogram import Client, enums, filters
|
||||
from pyrogram.errors import MediaCaptionTooLong
|
||||
from pyrogram.types import InputMediaPhoto, Message
|
||||
from utils.misc import modules_help, prefix
|
||||
from utils.scripts import format_exc
|
||||
|
||||
url = 'https://api.safone.co'
|
||||
|
||||
headers = {
|
||||
'Accept-Language': 'en-US,en;q=0.9',
|
||||
'Connection': 'keep-alive',
|
||||
'DNT': '1',
|
||||
'Referer': 'https://api.safone.co/docs',
|
||||
'Sec-Fetch-Dest': 'empty',
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
|
||||
'accept': 'application/json',
|
||||
'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'sec-ch-ua-platform': '"Linux"',
|
||||
}
|
||||
|
||||
|
||||
@Client.on_message(filters.command('anime_search', prefix) & filters.me)
|
||||
async def anime_search(client: Client, message: Message):
|
||||
try:
|
||||
chat_id = message.chat.id
|
||||
await message.edit_text('Processing...')
|
||||
if len(message.command) > 1:
|
||||
query = message.text.split(maxsplit=1)[1]
|
||||
else:
|
||||
message.edit_text("What should i search? You didn't provided me with any value to search")
|
||||
|
||||
response = requests.get(url=f'{url}/anime/search?query={query}', headers=headers, timeout=5)
|
||||
if response.status_code != 200:
|
||||
await message.edit_text('Something went wrong')
|
||||
return
|
||||
|
||||
result = response.json()
|
||||
|
||||
averageScore = result['averageScore']
|
||||
try:
|
||||
coverImage_url = result['imageUrl']
|
||||
coverImage = requests.get(url=coverImage_url, timeout=10).content
|
||||
async with aiofiles.open('coverImage.jpg', mode='wb') as f:
|
||||
await f.write(coverImage)
|
||||
|
||||
except Exception:
|
||||
coverImage = None
|
||||
|
||||
title = result['title']['english']
|
||||
trailer = result['trailer']['id']
|
||||
description = result['description']
|
||||
episodes = result['episodes']
|
||||
genres = ', '.join(result['genres'])
|
||||
isAdult = result['isAdult']
|
||||
status = result['status']
|
||||
studios = ', '.join(result['studios'])
|
||||
|
||||
await message.delete()
|
||||
await client.send_media_group(
|
||||
chat_id,
|
||||
[
|
||||
InputMediaPhoto(
|
||||
'coverImage.jpg',
|
||||
caption=f"<b>Title:</b> <code>{title}</code>\n<b>Average Score:</b> <code>{averageScore}</code>\n<b>Status:</b> <code>{status}</code>\n<b>Genres:</b> <code>{genres}</code>\n<b>Episodes:</b> <code>{episodes}</code>\n<b>Is Adult:</b> <code>{isAdult}</code>\n<b>Studios:</b> <code>{studios}</code>\n<b>Description:</b> <code>{description}</code>\n<b>Trailer:</b> <a href='https://youtu.be/{trailer}'>Click Here</a>",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
except MediaCaptionTooLong:
|
||||
description = description[:850]
|
||||
await message.delete()
|
||||
await client.send_media_group(
|
||||
chat_id,
|
||||
[
|
||||
InputMediaPhoto(
|
||||
'coverImage.jpg',
|
||||
caption=f"<b>Title:</b> <code>{title}</code>\n<b>Average Score:</b> <code>{averageScore}</code>\n<b>Status:</b> <code>{status}</code>\n<b>Genres:</b> <code>{genres}</code>\n<b>Episodes:</b> <code>{episodes}</code>\n<b>Is Adult:</b> <code>{isAdult}</code>\n<b>Studios:</b> <code>{studios}</code>\n<b>Description:</b> <code>{description}</code>\n<b>Trailer:</b> <a href='https://youtu.be/{trailer}'>Click Here</a>",
|
||||
)
|
||||
],
|
||||
)
|
||||
except Exception as e:
|
||||
await message.edit_text(format_exc(e))
|
||||
finally:
|
||||
if os.path.exists('coverImage.jpg'):
|
||||
os.remove('coverImage.jpg')
|
||||
|
||||
|
||||
@Client.on_message(filters.command('manga_search', prefix) & filters.me)
|
||||
async def manga_search(client: Client, message: Message):
|
||||
try:
|
||||
chat_id = message.chat.id
|
||||
await message.edit_text('Processing...')
|
||||
if len(message.command) > 1:
|
||||
query = message.text.split(maxsplit=1)[1]
|
||||
else:
|
||||
message.edit_text("What should i search? You didn't provided me with any value to search")
|
||||
|
||||
response = requests.get(url=f'{url}/anime/manga?query={query}', headers=headers, timeout=5)
|
||||
if response.status_code != 200:
|
||||
await message.edit_text('Something went wrong')
|
||||
return
|
||||
|
||||
result = response.json()
|
||||
|
||||
averageScore = result['averageScore']
|
||||
try:
|
||||
coverImage_url = result['imageUrl']
|
||||
coverImage = requests.get(url=coverImage_url, timeout=10).content
|
||||
async with aiofiles.open('coverImage.jpg', mode='wb') as f:
|
||||
await f.write(coverImage)
|
||||
|
||||
except Exception:
|
||||
coverImage = None
|
||||
|
||||
title = result['title']['english']
|
||||
trailer = result['trailer']['id']
|
||||
description = result['description']
|
||||
chapters = result['chapters']
|
||||
genres = ', '.join(result['genres'])
|
||||
isAdult = result['isAdult']
|
||||
status = result['status']
|
||||
studios = ', '.join(result['studios'])
|
||||
|
||||
await message.delete()
|
||||
await client.send_media_group(
|
||||
chat_id,
|
||||
[
|
||||
InputMediaPhoto(
|
||||
'coverImage.jpg',
|
||||
caption=f"<b>Title:</b> <code>{title}</code>\n<b>Average Score:</b> <code>{averageScore}</code>\n<b>Status:</b> <code>{status}</code>\n<b>Genres:</b> <code>{genres}</code>\n<b>Chapters:</b> <code>{chapters}</code>\n<b>Is Adult:</b> <code>{isAdult}</code>\n<b>Studios:</b> <code>{studios}</code>\n<b>Description:</b> <code>{description}</code>\n<b>Trailer:</b> <a href='https://youtu.be/{trailer}'>Click Here</a>",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
except MediaCaptionTooLong:
|
||||
description = description[:850]
|
||||
await message.delete()
|
||||
await client.send_media_group(
|
||||
chat_id,
|
||||
[
|
||||
InputMediaPhoto(
|
||||
'coverImage.jpg',
|
||||
caption=f"<b>Title:</b> <code>{title}</code>\n<b>Average Score:</b> <code>{averageScore}</code>\n<b>Status:</b> <code>{status}</code>\n<b>Genres:</b> <code>{genres}</code>\n<b>Chapters:</b> <code>{chapters}</code>\n<b>Is Adult:</b> <code>{isAdult}</code>\n<b>Studios:</b> <code>{studios}</code>\n<b>Description:</b> <code>{description}</code>\n<b>Trailer:</b> <a href='https://youtu.be/{trailer}'>Click Here</a>",
|
||||
)
|
||||
],
|
||||
)
|
||||
except Exception as e:
|
||||
await message.edit_text(format_exc(e))
|
||||
finally:
|
||||
if os.path.exists('coverImage.jpg'):
|
||||
os.remove('coverImage.jpg')
|
||||
|
||||
|
||||
@Client.on_message(filters.command('character', prefix) & filters.me)
|
||||
async def character(client: Client, message: Message):
|
||||
try:
|
||||
chat_id = message.chat.id
|
||||
await message.edit_text('Processing...')
|
||||
if len(message.command) > 1:
|
||||
query = message.text.split(maxsplit=1)[1]
|
||||
else:
|
||||
message.edit_text("What should i search? You didn't provided me with any value to search")
|
||||
|
||||
response = requests.get(url=f'{url}/anime/character?query={query}', headers=headers, timeout=5)
|
||||
if response.status_code != 200:
|
||||
await message.edit_text('Something went wrong')
|
||||
return
|
||||
|
||||
result = response.json()
|
||||
|
||||
try:
|
||||
coverImage_url = result['image']['large']
|
||||
coverImage = requests.get(url=coverImage_url, timeout=10).content
|
||||
async with aiofiles.open('coverImage.jpg', mode='wb') as f:
|
||||
await f.write(coverImage)
|
||||
|
||||
except Exception:
|
||||
coverImage = None
|
||||
|
||||
age = result['age']
|
||||
description = result['description']
|
||||
height = result['height']
|
||||
name = result['name']['full']
|
||||
native_name = result['name']['native']
|
||||
read_more = result['siteUrl']
|
||||
|
||||
await message.delete()
|
||||
await client.send_media_group(
|
||||
chat_id,
|
||||
[
|
||||
InputMediaPhoto(
|
||||
'coverImage.jpg',
|
||||
caption=f'**Name:** `{name}`\n**Native Name:** `{native_name}`\n**Age:** `{age}`\n**Height:** {height}\n**Description:** `{description}`[read more...]({read_more})',
|
||||
parse_mode=enums.ParseMode.MARKDOWN,
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
except MediaCaptionTooLong:
|
||||
description = description[:850]
|
||||
await message.delete()
|
||||
await client.send_media_group(
|
||||
chat_id,
|
||||
[
|
||||
InputMediaPhoto(
|
||||
'coverImage.jpg',
|
||||
caption=f'**Name:** `{name}`\n**Native Name:** `{native_name}`\n**Age:** `{age}`\n**Height:** {height}\n**Description:** `{description}`[read more...]({read_more})',
|
||||
parse_mode=enums.ParseMode.MARKDOWN,
|
||||
)
|
||||
],
|
||||
)
|
||||
except Exception as e:
|
||||
await message.edit_text(format_exc(e))
|
||||
finally:
|
||||
if os.path.exists('coverImage.jpg'):
|
||||
os.remove('coverImage.jpg')
|
||||
|
||||
|
||||
modules_help['anilist'] = {
|
||||
'anime_search': 'Search for anime on Anilist',
|
||||
'manga_search': 'Search for manga on Anilist',
|
||||
'character': 'Search for character on Anilist',
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
from io import BytesIO
|
||||
|
||||
from aiohttp import ClientSession
|
||||
from pyrogram import Client, enums, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
from utils.misc import modules_help, prefix
|
||||
from utils.scripts import format_exc
|
||||
|
||||
session = ClientSession()
|
||||
|
||||
|
||||
class Post:
|
||||
def __init__(self, source: dict, session: ClientSession):
|
||||
self._json = source
|
||||
self.session = session
|
||||
|
||||
@property
|
||||
async def image(self):
|
||||
return (
|
||||
self.file_url
|
||||
if self.file_url
|
||||
else (
|
||||
self.large_file_url
|
||||
if self.large_file_url
|
||||
else (
|
||||
self.source
|
||||
if self.source and 'pximg' not in self.source
|
||||
else await self.pximg
|
||||
if self.source
|
||||
else None
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
async def pximg(self):
|
||||
async with self.session.get(self.source) as response:
|
||||
return BytesIO(await response.read())
|
||||
|
||||
def __getattr__(self, item):
|
||||
return self._json.get(item)
|
||||
|
||||
|
||||
async def random():
|
||||
async with session.get(url='https://danbooru.donmai.us/posts/random.json') as response:
|
||||
return Post(await response.json(encoding='utf-8'), session)
|
||||
|
||||
|
||||
@Client.on_message(filters.command(['arnd', 'arandom'], prefix) & filters.me)
|
||||
async def anime_handler(client: Client, message: Message):
|
||||
try:
|
||||
await message.edit('<b>Searching art</b>', parse_mode=enums.ParseMode.HTML)
|
||||
ra = await random()
|
||||
img = await ra.image
|
||||
await message.reply_photo(
|
||||
photo=img,
|
||||
caption=f'<b>{ra.tag_string_general if ra.tag_string_general else "Untitled"}</b>',
|
||||
parse_mode=enums.ParseMode.HTML,
|
||||
)
|
||||
return await message.delete()
|
||||
except Exception as e:
|
||||
await message.edit(format_exc(e), parse_mode=enums.ParseMode.HTML)
|
||||
|
||||
|
||||
modules_help['anime'] = {
|
||||
'arnd': 'Random anime art (May get caught 18+)',
|
||||
'arandom': 'Random anime art (May get caught 18+)',
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import asyncio
|
||||
|
||||
import requests
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
from utils.misc import modules_help, prefix
|
||||
from utils.scripts import format_exc
|
||||
|
||||
|
||||
def get_neko_media(query):
|
||||
return requests.get(f'https://nekos.life/api/v2/img/{query}', timeout=10).json()['url']
|
||||
|
||||
|
||||
@Client.on_message(filters.command('neko', prefix) & filters.me)
|
||||
async def neko(_, message: Message):
|
||||
if len(message.command) == 1:
|
||||
await message.edit(
|
||||
f"<b>Neko type isn't provided\nYou can get available neko types with <code>{prefix}neko_types</code></b>"
|
||||
)
|
||||
|
||||
query = message.command[1]
|
||||
await message.edit('<b>Loading...</b>')
|
||||
try:
|
||||
await message.edit(f'{get_neko_media(query)}', disable_web_page_preview=False)
|
||||
except Exception as e:
|
||||
await message.edit(format_exc(e))
|
||||
|
||||
|
||||
@Client.on_message(filters.command(['nekotypes', 'neko_types'], prefix) & filters.me)
|
||||
async def neko_types_func(_, message: Message):
|
||||
neko_types = """hug kiss tickle lewd neko pat lizard 8ball cat chat fact smug woof gasm goose cuddle avatar slap gecg feed fox_girl meow wallpaper spank waifu ngif name owoify spoiler why"""
|
||||
await message.edit(' '.join(f'<code>{n}</code>' for n in neko_types.split()))
|
||||
|
||||
|
||||
@Client.on_message(filters.command(['nekospam', 'neko_spam'], prefix) & filters.me)
|
||||
async def neko_spam(client: Client, message: Message):
|
||||
query = message.command[1]
|
||||
amount = int(message.command[2])
|
||||
|
||||
await message.delete()
|
||||
|
||||
for _ in range(amount):
|
||||
if message.reply_to_message:
|
||||
await message.reply_to_message.reply(get_neko_media(query))
|
||||
else:
|
||||
await client.send_message(message.chat.id, get_neko_media(query))
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
|
||||
modules_help['neko'] = {
|
||||
'neko [type]*': 'Get neko media',
|
||||
'neko_types': 'Available neko types',
|
||||
'neko_spam [type]* [amount]*': 'Start spam with neko media',
|
||||
}
|
||||
Reference in New Issue
Block a user